aboutsummaryrefslogtreecommitdiff
path: root/challenge-088/paulo-custodio/test.pl
diff options
context:
space:
mode:
authorPaulo Custodio <pauloscustodio@gmail.com>2020-12-22 21:38:38 +0000
committerPaulo Custodio <pauloscustodio@gmail.com>2020-12-22 21:38:38 +0000
commitc43d32635c9aa65c1e0630065e423450ffacf845 (patch)
tree2bc7d94577a616fc9d1b3aa37038f03ca7db37fe /challenge-088/paulo-custodio/test.pl
parentbb41f12afa7361bb50ab8f4f2b932a975bdca48e (diff)
downloadperlweeklychallenge-club-c43d32635c9aa65c1e0630065e423450ffacf845.tar.gz
perlweeklychallenge-club-c43d32635c9aa65c1e0630065e423450ffacf845.tar.bz2
perlweeklychallenge-club-c43d32635c9aa65c1e0630065e423450ffacf845.zip
Add Perl solution to challenge 088
Diffstat (limited to 'challenge-088/paulo-custodio/test.pl')
-rw-r--r--challenge-088/paulo-custodio/test.pl68
1 files changed, 68 insertions, 0 deletions
diff --git a/challenge-088/paulo-custodio/test.pl b/challenge-088/paulo-custodio/test.pl
new file mode 100644
index 0000000000..e2512af0a2
--- /dev/null
+++ b/challenge-088/paulo-custodio/test.pl
@@ -0,0 +1,68 @@
+#!/usr/bin/perl
+
+use strict;
+use warnings;
+use Test::More;
+use 5.030;
+
+my $in = "in.txt";
+
+is capture("perl perl/ch-1.pl 5 2 1 4 3"), "(24, 60, 120, 30, 40)\n";
+is capture("perl perl/ch-1.pl 2 1 4 3 "), "(12, 24, 6, 8)\n";
+is capture("perl perl/ch-1.pl 0 1 4 3 "), "(12, 0, 0, 0)\n";
+is capture("perl perl/ch-1.pl 1 1 1 1 "), "(1, 1, 1, 1)\n";
+
+spew($in, <<END);
+[ 5 ]
+END
+is capture("perl perl/ch-2.pl <$in"), "[ 5 ]\n";
+
+spew($in, <<END);
+[ 1, 2, 3 ]
+END
+is capture("perl perl/ch-2.pl <$in"), "[ 1, 2, 3 ]\n";
+
+spew($in, <<END);
+[ 1, 2, 3 ]
+[ 7, 8, 9 ]
+END
+is capture("perl perl/ch-2.pl <$in"), "[ 1, 2, 3, 9, 8, 7 ]\n";
+
+spew($in, <<END);
+[ 1 ]
+[ 4 ]
+[ 7 ]
+END
+is capture("perl perl/ch-2.pl <$in"), "[ 1, 4, 7 ]\n";
+
+spew($in, <<END);
+[ 1, 2, 3 ]
+[ 4, 5, 6 ]
+[ 7, 8, 9 ]
+END
+is capture("perl perl/ch-2.pl <$in"), "[ 1, 2, 3, 6, 9, 8, 7, 4, 5 ]\n";
+
+spew($in, <<END);
+[ 1, 2, 3, 4 ]
+[ 5, 6, 7, 8 ]
+[ 9, 10, 11, 12 ]
+[ 13, 14, 15, 16 ]
+END
+is capture("perl perl/ch-2.pl <$in"),
+ "[ 1, 2, 3, 4, 8, 12, 16, 15, 14, 13, 9, 5, 6, 7, 11, 10 ]\n";
+
+unlink($in);
+done_testing;
+
+sub capture {
+ my($cmd) = @_;
+ my $out = `$cmd`;
+ $out =~ s/[ \t\v\f\r]*\n/\n/g;
+ return $out;
+}
+
+sub spew {
+ my($file, $text) = @_;
+ open(my $fh, ">", $file) or die "write $file: $!\n";
+ print $fh $text;
+}