aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--challenge-184/happy-barney/perl/ch-1-test-scenario.pl40
-rw-r--r--challenge-184/happy-barney/perl/ch-1.pl15
-rw-r--r--challenge-184/happy-barney/perl/ch-1.t6
-rw-r--r--challenge-184/happy-barney/perl/ch-2-test-scenario.pl70
-rw-r--r--challenge-184/happy-barney/perl/ch-2.pl21
-rw-r--r--challenge-184/happy-barney/perl/ch-2.t7
6 files changed, 159 insertions, 0 deletions
diff --git a/challenge-184/happy-barney/perl/ch-1-test-scenario.pl b/challenge-184/happy-barney/perl/ch-1-test-scenario.pl
new file mode 100644
index 0000000000..5ae4207c95
--- /dev/null
+++ b/challenge-184/happy-barney/perl/ch-1-test-scenario.pl
@@ -0,0 +1,40 @@
+
+use strict;
+use warnings;
+
+use Test::YAFT;
+
+act { [ challenge_184_1 (@{ $_[0] }) ] } 'list_of_strings';
+
+it 'should replace leading 2 chars in every string'
+ => with_list_of_strings => [
+ 'aa0011', 'bb0022', 'cc0033', 'dd0044',
+ 'ee0055', 'ff0066', 'gg0077', 'hh0088',
+ 'ii0099', 'jj1100', 'kk1111', 'll1122',
+ ]
+ => expect => [
+ '000011', '010022', '020033', '030044',
+ '040055', '050066', '060077', '070088',
+ '080099', '091100', '101111', '111122',
+ ]
+ ;
+
+it 'should use different index for same prefix'
+ => with_list_of_strings => [
+ 'aa0011', 'aa0022', 'aa0033', 'aa0044',
+ ]
+ => expect => [
+ '000011', '010022', '020033', '030044',
+ ]
+ ;
+
+it 'should accept empty list'
+ => with_list_of_strings => [
+ ]
+ => expect => [
+ ]
+ ;
+
+had_no_warnings;
+done_testing;
+
diff --git a/challenge-184/happy-barney/perl/ch-1.pl b/challenge-184/happy-barney/perl/ch-1.pl
new file mode 100644
index 0000000000..3f2a047f94
--- /dev/null
+++ b/challenge-184/happy-barney/perl/ch-1.pl
@@ -0,0 +1,15 @@
+#!/usr/bin/env perl
+
+use strict;
+use warnings;
+
+sub challenge_184_1 {
+ my (@strings) = @_;
+
+ my $sequence = "00";
+ substr ($_, 0, 2) = $sequence ++
+ for @strings;
+
+ return @strings;
+}
+
diff --git a/challenge-184/happy-barney/perl/ch-1.t b/challenge-184/happy-barney/perl/ch-1.t
new file mode 100644
index 0000000000..9f61072bba
--- /dev/null
+++ b/challenge-184/happy-barney/perl/ch-1.t
@@ -0,0 +1,6 @@
+
+use strict;
+use warnings;
+
+do "./ch-1.pl";
+do "./ch-1-test-scenario.pl";
diff --git a/challenge-184/happy-barney/perl/ch-2-test-scenario.pl b/challenge-184/happy-barney/perl/ch-2-test-scenario.pl
new file mode 100644
index 0000000000..1a454dc8f1
--- /dev/null
+++ b/challenge-184/happy-barney/perl/ch-2-test-scenario.pl
@@ -0,0 +1,70 @@
+
+use strict;
+use warnings;
+
+use Test::YAFT;
+
+act { [ challenge_184_2 (@{ $_[0] }) ] } 'list_of_strings';
+
+it q[should pick numbers and letters from strings]
+ => with_list_of_strings => [
+ 'a 1 b', '2 c 3',
+ ]
+ => expect => [
+ [
+ qw[ 1 ],
+ qw[ 2 3 ],
+ ],
+ [
+ qw[ a b ],
+ qw[ c ],
+ ],
+ ]
+ ;
+
+it q[should omit result when string contains only letters or numbers]
+ => with_list_of_strings => [
+ 'a 1 b', '1 2 3', '2 c 3', 'a b c', '4 d',
+ ]
+ => expect => [
+ [
+ qw[ 1 ],
+ qw[ 1 2 3 ],
+ qw[ 2 3 ],
+ qw[ 4 ],
+ ],
+ [
+ qw[ a b ],
+ qw[ c ],
+ qw[ a b c ],
+ qw[ d ],
+ ],
+ ]
+ ;
+
+it q[should recognize single char strings]
+ => with_list_of_strings => [
+ 'a', '1',
+ ]
+ => expect => [
+ [
+ qw[ 1 ],
+ ],
+ [
+ qw[ a ],
+ ],
+ ]
+ ;
+
+it 'should accept empty list'
+ => with_list_of_strings => [
+ ]
+ => expect => [
+ [],
+ [],
+ ]
+ ;
+
+had_no_warnings;
+done_testing;
+
diff --git a/challenge-184/happy-barney/perl/ch-2.pl b/challenge-184/happy-barney/perl/ch-2.pl
new file mode 100644
index 0000000000..d94d5dd8ad
--- /dev/null
+++ b/challenge-184/happy-barney/perl/ch-2.pl
@@ -0,0 +1,21 @@
+#!/usr/bin/env perl
+
+use strict;
+use warnings;
+
+sub challenge_184_2 {
+ my (@strings) = @_;
+
+ my (@numbers, @letters);
+
+ my $re_numbers = qr/[0-9]/;
+ my $re_letters = qr/[a-z]/;
+
+ for my $string (@strings) {
+ push @numbers, split qr/ +/, $string =~ s/$re_letters ?//gr;
+ push @letters, split qr/ +/, $string =~ s/$re_numbers ?//gr;
+ }
+
+ return (\@numbers, \@letters);
+}
+
diff --git a/challenge-184/happy-barney/perl/ch-2.t b/challenge-184/happy-barney/perl/ch-2.t
new file mode 100644
index 0000000000..aac2cc2a14
--- /dev/null
+++ b/challenge-184/happy-barney/perl/ch-2.t
@@ -0,0 +1,7 @@
+
+use strict;
+use warnings;
+
+do "./ch-2.pl";
+do "./ch-2-test-scenario.pl";
+