diff options
| author | Jared Martin <760765+jaredor@users.noreply.github.com> | 2021-07-25 23:59:03 -0500 |
|---|---|---|
| committer | Jared Martin <760765+jaredor@users.noreply.github.com> | 2021-07-25 23:59:03 -0500 |
| commit | 9d2ccc16f87a77950c7a791849a435d15b7324ea (patch) | |
| tree | 89d19147f2ebff9261c834808b79a264eed33ab1 /challenge-122/jaredor/perl | |
| parent | a755381882f6f06b5f9fef1a55dd6d6c3bc35d66 (diff) | |
| download | perlweeklychallenge-club-9d2ccc16f87a77950c7a791849a435d15b7324ea.tar.gz perlweeklychallenge-club-9d2ccc16f87a77950c7a791849a435d15b7324ea.tar.bz2 perlweeklychallenge-club-9d2ccc16f87a77950c7a791849a435d15b7324ea.zip | |
Updated with --test coverage (minimal)
Diffstat (limited to 'challenge-122/jaredor/perl')
| -rwxr-xr-x | challenge-122/jaredor/perl/ch-2.pl | 37 |
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(); } |
