From d059f1a16f9ce08854b6ef2c69552802850a4710 Mon Sep 17 00:00:00 2001 From: Mohammad S Anwar Date: Sat, 18 Apr 2020 20:23:55 +0100 Subject: - Tided up Perl solutions to Path Sum. --- challenge-056/mohammad-anwar/perl/ch-2.pl | 4 ++-- challenge-056/mohammad-anwar/perl/ch-2a.pl | 5 +++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/challenge-056/mohammad-anwar/perl/ch-2.pl b/challenge-056/mohammad-anwar/perl/ch-2.pl index a37fba63aa..de8ff6982a 100644 --- a/challenge-056/mohammad-anwar/perl/ch-2.pl +++ b/challenge-056/mohammad-anwar/perl/ch-2.pl @@ -24,7 +24,7 @@ my $TREE = { }, }; -print find_matched_paths($TREE, $SUM), "\n"; +print join("\n", @{find_matched_paths($TREE, $SUM)}), "\n"; sub find_matched_paths { my ($TREE, $SUM) = @_; @@ -55,5 +55,5 @@ sub find_matched_paths { push @$matched_paths, join(" -> ", @$path) if ($total == $SUM); } - return join("\n", @$matched_paths); + return $matched_paths; } diff --git a/challenge-056/mohammad-anwar/perl/ch-2a.pl b/challenge-056/mohammad-anwar/perl/ch-2a.pl index 091e71361e..7c697a3d08 100644 --- a/challenge-056/mohammad-anwar/perl/ch-2a.pl +++ b/challenge-056/mohammad-anwar/perl/ch-2a.pl @@ -4,6 +4,7 @@ use strict; use warnings; use Test::More; +use Test::Deep; =head1 TREE @@ -28,7 +29,7 @@ my $unit_tests = { }; foreach my $sum (keys %$unit_tests) { - is (find_matched_paths($unit_tests->{$sum}, $sum), "5 -> 4 -> 11 -> 2"); + is_deeply (find_matched_paths($unit_tests->{$sum}, $sum), ["5 -> 4 -> 11 -> 2"]); } done_testing; @@ -62,5 +63,5 @@ sub find_matched_paths { push @$matched_paths, join(" -> ", @$path) if ($total == $SUM); } - return join("\n", @$matched_paths); + return $matched_paths; } -- cgit