From e50f7a5ca9bb2a6bea01bade0dd7306b13967c72 Mon Sep 17 00:00:00 2001 From: k-mx Date: Sun, 5 May 2019 11:59:01 +0500 Subject: tests and bugfix for 0,0,0 input --- challenge-006/maxim-kolodyazhny/perl5/ch-1.pl | 11 +++++----- challenge-006/maxim-kolodyazhny/perl5/ch-1.t | 31 +++++++++++++++++++++++++++ 2 files changed, 37 insertions(+), 5 deletions(-) create mode 100644 challenge-006/maxim-kolodyazhny/perl5/ch-1.t 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..6c47466405 --- /dev/null +++ b/challenge-006/maxim-kolodyazhny/perl5/ch-1.t @@ -0,0 +1,31 @@ +#!/usr/bin/env perl + +use strict; +use warnings; + +use v5.028.1; + +use Test::More tests => 10; + +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', +); + +while ( my ( $i, $o ) = each %tests ) { + + my $r = `echo $i | perl ./ch-1.pl`; + chomp $r; + + is( $r, $o ); +} + +done_testing 10; -- cgit From 856a8461e727ec9f0438049be699cdca8410a80b Mon Sep 17 00:00:00 2001 From: k-mx Date: Sun, 5 May 2019 14:03:45 +0500 Subject: extra test case --- challenge-006/maxim-kolodyazhny/perl5/ch-1.t | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/challenge-006/maxim-kolodyazhny/perl5/ch-1.t b/challenge-006/maxim-kolodyazhny/perl5/ch-1.t index 6c47466405..6f75f83286 100644 --- a/challenge-006/maxim-kolodyazhny/perl5/ch-1.t +++ b/challenge-006/maxim-kolodyazhny/perl5/ch-1.t @@ -5,7 +5,7 @@ use warnings; use v5.028.1; -use Test::More tests => 10; +use Test::More tests => 11; my %tests = ( '0,0,0' => '0,0,0', @@ -18,6 +18,7 @@ my %tests = ( '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 ) { @@ -28,4 +29,4 @@ while ( my ( $i, $o ) = each %tests ) { is( $r, $o ); } -done_testing 10; +done_testing 11; -- cgit From 3c750ebd8a6fe8ec3450ede07331e4aaf889c758 Mon Sep 17 00:00:00 2001 From: k-mx Date: Sun, 5 May 2019 14:26:48 +0500 Subject: no declarations, strict and warnings removed --- challenge-006/maxim-kolodyazhny/perl5/ch-2.pl | 4 ---- 1 file changed, 4 deletions(-) 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 ); -- cgit