aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xchallenge-122/jaredor/perl/ch-2.pl37
1 files changed, 30 insertions, 7 deletions
diff --git a/challenge-122/jaredor/perl/ch-2.pl b/challenge-122/jaredor/perl/ch-2.pl
index 41c55ad5e5..f2f6c8023a 100755
--- a/challenge-122/jaredor/perl/ch-2.pl
+++ b/challenge-122/jaredor/perl/ch-2.pl
@@ -67,6 +67,8 @@ sub main_algo {
} elsif ($bb_pnt == $target) {
push @scores, [ $bb_pnt, ];
}
+ # Could use an "else last" here if @bb_points is assumed to
+ # always be ascending sort and you want to save a cycle or two.
}
}
return \@scores;
@@ -89,13 +91,34 @@ sub output_results {
sub test {
use Test::More;
- my $input;
-
- # Ran out of time, no built-in testing. You'll have to try it and see :-)
- #$input = [ 4, ];
- #pp main_algo($input);
- #is_deeply( main_algo( $input ), [ ], "Test description" );
-
+ my ($input, $output);
+
+ $input = 4;
+ $output = [ [1, 1, 1, 1],
+ [1, 1, 2],
+ [1, 2, 1],
+ [1, 3],
+ [2, 1, 1],
+ [2, 2],
+ [3, 1], ];
+ is_deeply( main_algo( $input ), $output, "Ways to score 4 in basketball." );
+
+ $input = 5;
+ $output = [ [1, 1, 1, 1, 1],
+ [1, 1, 1, 2],
+ [1, 1, 2, 1],
+ [1, 1, 3],
+ [1, 2, 1, 1],
+ [1, 2, 2],
+ [1, 3, 1],
+ [2, 1, 1, 1],
+ [2, 1, 2],
+ [2, 2, 1],
+ [2, 3],
+ [3, 1, 1],
+ [3, 2],
+ ];
+ is_deeply( main_algo( $input ), $output, "Ways to score 5 in basketball." );
done_testing();
}