diff options
| author | Mohammad S Anwar <Mohammad.Anwar@yahoo.com> | 2019-05-05 17:19:20 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2019-05-05 17:19:20 +0100 |
| commit | 31f9b3ff4a585ca32cc9704eda66129cdca6e556 (patch) | |
| tree | c79bbbe67fda78c364511828115f816eba2c6607 /challenge-006 | |
| parent | d58ce57ec357e95d204565074014cab93eefe70b (diff) | |
| parent | 3c750ebd8a6fe8ec3450ede07331e4aaf889c758 (diff) | |
| download | perlweeklychallenge-club-31f9b3ff4a585ca32cc9704eda66129cdca6e556.tar.gz perlweeklychallenge-club-31f9b3ff4a585ca32cc9704eda66129cdca6e556.tar.bz2 perlweeklychallenge-club-31f9b3ff4a585ca32cc9704eda66129cdca6e556.zip | |
Merge pull request #119 from k-mx/master
tests and bugfix for 0,0,0 input
Diffstat (limited to 'challenge-006')
| -rwxr-xr-x | challenge-006/maxim-kolodyazhny/perl5/ch-1.pl | 11 | ||||
| -rw-r--r-- | challenge-006/maxim-kolodyazhny/perl5/ch-1.t | 32 | ||||
| -rwxr-xr-x | challenge-006/maxim-kolodyazhny/perl5/ch-2.pl | 4 |
3 files changed, 38 insertions, 9 deletions
diff --git a/challenge-006/maxim-kolodyazhny/perl5/ch-1.pl b/challenge-006/maxim-kolodyazhny/perl5/ch-1.pl index 0a87aa1371..c34849037f 100755 --- a/challenge-006/maxim-kolodyazhny/perl5/ch-1.pl +++ b/challenge-006/maxim-kolodyazhny/perl5/ch-1.pl @@ -6,13 +6,14 @@ use 5.028.1; use List::Util qw(sum); s{ - ( \b \d+ ) - ( ,? \d+ , )+ - ( \d+ \b ) + ( \b \d+ ) + ( ,? \d+ , )+ + ( \d++ ) (??{ # this block is treated as a pattern - # != will return '' (always match) or 1 (fail because of previous \b) - ( $3 - $1 + 1 ) * ( $1 + $3 ) / 2 != sum split ',', $&; + # != will return '' (match) or 1 (fail, because \d++ will swallow all) + # sum( eval $& ) will work too (; + ( $3 - $1 + 1 ) * ( $1 + $3 ) / 2 != ( sum( split ',', $& ) || -1 ); }) } {$1-$3}xg; diff --git a/challenge-006/maxim-kolodyazhny/perl5/ch-1.t b/challenge-006/maxim-kolodyazhny/perl5/ch-1.t new file mode 100644 index 0000000000..6f75f83286 --- /dev/null +++ b/challenge-006/maxim-kolodyazhny/perl5/ch-1.t @@ -0,0 +1,32 @@ +#!/usr/bin/env perl + +use strict; +use warnings; + +use v5.028.1; + +use Test::More tests => 11; + +my %tests = ( + '0,0,0' => '0,0,0', + '0,9999999999' => '0,9999999999', + '1' => 1, + '1,1,1,2,3,4' => '1,1,1-4', + '1,2' => '1,2', + '1,2,3,4' => '1-4', + '10,2,3,4' => '10,2-4', + '100,101,102' => '100-102', + '3,2,1,0' => '3,2,1,0', + '4,3,2' => '4,3,2', + '100,1,2,3' => '100,1-3', +); + +while ( my ( $i, $o ) = each %tests ) { + + my $r = `echo $i | perl ./ch-1.pl`; + chomp $r; + + is( $r, $o ); +} + +done_testing 11; diff --git a/challenge-006/maxim-kolodyazhny/perl5/ch-2.pl b/challenge-006/maxim-kolodyazhny/perl5/ch-2.pl index ff3bc8aa53..668d797feb 100755 --- a/challenge-006/maxim-kolodyazhny/perl5/ch-2.pl +++ b/challenge-006/maxim-kolodyazhny/perl5/ch-2.pl @@ -1,10 +1,6 @@ #!/usr/bin/env perl -use strict; -use warnings; - use v5.028.1; - use bigrat qw(bexp PI); say bexp( PI * sqrt(163), 80 ); |
