diff options
| author | Lubos Kolouch <lubos@kolouch.net> | 2019-10-20 11:52:39 +0200 |
|---|---|---|
| committer | Lubos Kolouch <lubos@kolouch.net> | 2019-10-20 11:52:39 +0200 |
| commit | 2a95c0c13dc52fe5230b464f3cc48a0b8d38d2bd (patch) | |
| tree | b229ae6ddf58ab46d6ee9ac3dc0039539ab8242f | |
| parent | a22e76e3c536995f1b35ba1c870df8664efe47b2 (diff) | |
| download | perlweeklychallenge-club-2a95c0c13dc52fe5230b464f3cc48a0b8d38d2bd.tar.gz perlweeklychallenge-club-2a95c0c13dc52fe5230b464f3cc48a0b8d38d2bd.tar.bz2 perlweeklychallenge-club-2a95c0c13dc52fe5230b464f3cc48a0b8d38d2bd.zip | |
Add tests for 2
| -rw-r--r-- | challenge-030/lubos-kolouch/perl5/ch-2.pl | 38 |
1 files changed, 26 insertions, 12 deletions
diff --git a/challenge-030/lubos-kolouch/perl5/ch-2.pl b/challenge-030/lubos-kolouch/perl5/ch-2.pl index 45e3db63c7..30124e32b5 100644 --- a/challenge-030/lubos-kolouch/perl5/ch-2.pl +++ b/challenge-030/lubos-kolouch/perl5/ch-2.pl @@ -25,27 +25,41 @@ use warnings; use feature qw/say/; sub is_ok_triple { - my ($x,$y,$z) = @_; + my ( $x, $y, $z ) = @_; - return 0 unless $x+$y+$z == 12; - return 0 unless ($x % 2 ==0) or ($y % 2 == 0) or ($z % 2 == 0); + return 0 unless $x + $y + $z == 12; + return 0 unless ( $x % 2 == 0 ) or ( $y % 2 == 0 ) or ( $z % 2 == 0 ); return 1; } -my $max = 12; +sub main { + my $max = 12; + for my $x ( 1 .. 10 ) { # max 10+1+1 + for my $y ( 1 .. 10 ) { + last if ( $x + $y ) >= $max; -for my $x (1..10) { # max 10+1+1 - for my $y (1..10) { - last if ( $x + $y ) >= $max; + for my $z ( 1 .. 10 ) { + my $sum = $x + $y + $z; + last if $sum > $max; - for my $z (1..10) { - my $sum = $x + $y + $z; - last if $sum > $max; + say "$x $y $z" if is_ok_triple( $x, $y, $z ); - say "$x $y $z" if is_ok_triple($x,$y,$z); - + } } } } +main; + +# TESTS + +use Test::More; + +is(is_ok_triple(3,4,5),1,'Test 3 4 5'); +is(is_ok_triple(3,4,6),0,'Test 3 4 6'); + +# it seems there is no triple without even number so can't test +# but leave the code in in case the $max changes + +done_testing; |
