From 117653ee12b38e1328eccbf2a252911f118db01b Mon Sep 17 00:00:00 2001 From: Daniel Mita <966706+m-dango@users.noreply.github.com> Date: Wed, 16 Jun 2021 12:18:07 +0100 Subject: [PATCH] Add strain to generator (#417) --- exercises/practice/binary/Binary.pm | 18 ++++ exercises/practice/etl/.meta/config.json | 4 +- exercises/practice/hexadecimal/Hexadecimal.pm | 18 ++++ .../practice/linked-list/.meta/config.json | 6 +- exercises/practice/linked-list/Deque.pm | 46 +++++++++ exercises/practice/list-ops/ListOps.pm | 24 +++++ .../practice/ocr-numbers/.meta/config.json | 4 +- .../palindrome-products/.meta/config.json | 6 +- .../palindrome-products/Palindrome.pm | 24 +++++ .../point-mutations/.meta/config.json | 6 +- exercises/practice/point-mutations/DNA.pm | 18 ++++ .../practice/prime-factors/.meta/config.json | 6 +- exercises/practice/prime-factors/Prime.pm | 12 +++ exercises/practice/proverb/Proverb.pm | 12 +++ .../pythagorean-triplet/.meta/config.json | 6 +- .../practice/pythagorean-triplet/Triplet.pm | 36 +++++++ .../practice/queen-attack/.meta/config.json | 6 +- exercises/practice/queen-attack/Queens.pm | 36 +++++++ .../rna-transcription/.meta/config.json | 4 +- .../robot-simulator/.meta/config.json | 6 +- exercises/practice/robot-simulator/Robot.pm | 82 ++++++++++++++++ .../practice/saddle-points/.meta/config.json | 6 +- exercises/practice/saddle-points/Matrix.pm | 30 ++++++ .../practice/simple-cipher/.meta/config.json | 6 +- exercises/practice/simple-cipher/Cipher.pm | 24 +++++ .../simple-linked-list/.meta/config.json | 6 +- .../practice/simple-linked-list/LinkedList.pm | 31 +++++++ .../practice/strain/.meta/exercise-data.yaml | 93 +++++++++++++++++++ .../practice/strain/.meta/solutions/Strain.pm | 3 +- exercises/practice/strain/Strain.pm | 17 ++++ exercises/practice/strain/strain.t | 48 ++++------ exercises/practice/trinary/Trinary.pm | 17 ++++ 32 files changed, 592 insertions(+), 69 deletions(-) create mode 100644 exercises/practice/binary/Binary.pm create mode 100644 exercises/practice/hexadecimal/Hexadecimal.pm create mode 100644 exercises/practice/linked-list/Deque.pm create mode 100644 exercises/practice/list-ops/ListOps.pm create mode 100644 exercises/practice/palindrome-products/Palindrome.pm create mode 100644 exercises/practice/point-mutations/DNA.pm create mode 100644 exercises/practice/prime-factors/Prime.pm create mode 100644 exercises/practice/proverb/Proverb.pm create mode 100644 exercises/practice/pythagorean-triplet/Triplet.pm create mode 100644 exercises/practice/queen-attack/Queens.pm create mode 100644 exercises/practice/robot-simulator/Robot.pm create mode 100644 exercises/practice/saddle-points/Matrix.pm create mode 100644 exercises/practice/simple-cipher/Cipher.pm create mode 100644 exercises/practice/simple-linked-list/LinkedList.pm create mode 100644 exercises/practice/strain/.meta/exercise-data.yaml create mode 100644 exercises/practice/strain/Strain.pm mode change 100644 => 100755 exercises/practice/strain/strain.t create mode 100644 exercises/practice/trinary/Trinary.pm diff --git a/exercises/practice/binary/Binary.pm b/exercises/practice/binary/Binary.pm new file mode 100644 index 00000000..f3e8dfc2 --- /dev/null +++ b/exercises/practice/binary/Binary.pm @@ -0,0 +1,18 @@ +package Binary; + +use strict; +use warnings; + +sub new { + my ( $class, $binary ) = @_; + + return undef; +} + +sub to_decimal { + my $self = shift; + + return undef; +} + +__PACKAGE__; diff --git a/exercises/practice/etl/.meta/config.json b/exercises/practice/etl/.meta/config.json index 764bf88c..843a4c3b 100644 --- a/exercises/practice/etl/.meta/config.json +++ b/exercises/practice/etl/.meta/config.json @@ -3,13 +3,13 @@ "authors": [], "files": { "solution": [ - "Etl.pm" + "ETL.pm" ], "test": [ "etl.t" ], "example": [ - ".meta/solutions/Etl.pm" + ".meta/solutions/ETL.pm" ] }, "source": "The Jumpstart Lab team", diff --git a/exercises/practice/hexadecimal/Hexadecimal.pm b/exercises/practice/hexadecimal/Hexadecimal.pm new file mode 100644 index 00000000..30db01de --- /dev/null +++ b/exercises/practice/hexadecimal/Hexadecimal.pm @@ -0,0 +1,18 @@ +package Hexadecimal; + +use strict; +use warnings; + +sub new { + my ( $class, $hexadecimal ) = @_; + + return undef; +} + +sub to_decimal { + my $self = shift; + + return undef; +} + +__PACKAGE__; diff --git a/exercises/practice/linked-list/.meta/config.json b/exercises/practice/linked-list/.meta/config.json index da3e9c39..4a42e82c 100644 --- a/exercises/practice/linked-list/.meta/config.json +++ b/exercises/practice/linked-list/.meta/config.json @@ -3,13 +3,13 @@ "authors": [], "files": { "solution": [ - "LinkedList.pm" + "Deque.pm" ], "test": [ - "linked-list.t" + "deque.t" ], "example": [ - ".meta/solutions/LinkedList.pm" + ".meta/solutions/Deque.pm" ] }, "source": "Classic computer science topic" diff --git a/exercises/practice/linked-list/Deque.pm b/exercises/practice/linked-list/Deque.pm new file mode 100644 index 00000000..df5eecf7 --- /dev/null +++ b/exercises/practice/linked-list/Deque.pm @@ -0,0 +1,46 @@ +package Deque; +use strict; +use warnings; + +sub new { + my ($class) = @_; + + return undef; +} + +sub push { + my ( $self, $value ) = @_; + + return undef; +} + +sub pop { + my ($self) = @_; + + return undef; +} + +sub shift { + my ($self) = @_; + + return undef; +} + +sub unshift { + my ( $self, $value ) = @_; + + return undef; +} + +package Element; +use strict; +use warnings; + +sub new { + my ( $class, %data ) = @_; + + return undef; +} + +1; + diff --git a/exercises/practice/list-ops/ListOps.pm b/exercises/practice/list-ops/ListOps.pm new file mode 100644 index 00000000..27c35d5c --- /dev/null +++ b/exercises/practice/list-ops/ListOps.pm @@ -0,0 +1,24 @@ +package ListOps; + +use strict; +use warnings; + +sub map { + my ( $func, $list ) = @_; + + return undef; +} + +sub reduce { + my ( $func, $list ) = @_; + + return undef; +} + +sub length { + my $list = shift; + + return undef; +} + +1; diff --git a/exercises/practice/ocr-numbers/.meta/config.json b/exercises/practice/ocr-numbers/.meta/config.json index 3a7e468b..4466a598 100644 --- a/exercises/practice/ocr-numbers/.meta/config.json +++ b/exercises/practice/ocr-numbers/.meta/config.json @@ -3,13 +3,13 @@ "authors": [], "files": { "solution": [ - "OcrNumbers.pm" + "OCRNumbers.pm" ], "test": [ "ocr-numbers.t" ], "example": [ - ".meta/solutions/OcrNumbers.pm" + ".meta/solutions/OCRNumbers.pm" ] }, "source": "Inspired by the Bank OCR kata", diff --git a/exercises/practice/palindrome-products/.meta/config.json b/exercises/practice/palindrome-products/.meta/config.json index ed04f685..291aa63e 100644 --- a/exercises/practice/palindrome-products/.meta/config.json +++ b/exercises/practice/palindrome-products/.meta/config.json @@ -3,13 +3,13 @@ "authors": [], "files": { "solution": [ - "PalindromeProducts.pm" + "Palindrome.pm" ], "test": [ - "palindrome-products.t" + "palindrome.t" ], "example": [ - ".meta/solutions/PalindromeProducts.pm" + ".meta/solutions/Palindrome.pm" ] }, "source": "Problem 4 at Project Euler", diff --git a/exercises/practice/palindrome-products/Palindrome.pm b/exercises/practice/palindrome-products/Palindrome.pm new file mode 100644 index 00000000..dd158e22 --- /dev/null +++ b/exercises/practice/palindrome-products/Palindrome.pm @@ -0,0 +1,24 @@ +package Palindrome; + +use strict; +use warnings; + +sub new { + my ( $class, $min_max ) = @_; + + return undef; +} + +sub largest { + my $self = shift; + + return undef; +} + +sub smallest { + my $self = shift; + + return undef; +} + +1; diff --git a/exercises/practice/point-mutations/.meta/config.json b/exercises/practice/point-mutations/.meta/config.json index 09549481..ea852a63 100644 --- a/exercises/practice/point-mutations/.meta/config.json +++ b/exercises/practice/point-mutations/.meta/config.json @@ -3,13 +3,13 @@ "authors": [], "files": { "solution": [ - "PointMutations.pm" + "DNA.pm" ], "test": [ - "point-mutations.t" + "dna.t" ], "example": [ - ".meta/solutions/PointMutations.pm" + ".meta/solutions/DNA.pm" ] }, "source": "The Calculating Point Mutations problem at Rosalind", diff --git a/exercises/practice/point-mutations/DNA.pm b/exercises/practice/point-mutations/DNA.pm new file mode 100644 index 00000000..1d03e1a8 --- /dev/null +++ b/exercises/practice/point-mutations/DNA.pm @@ -0,0 +1,18 @@ +package DNA; + +use strict; +use warnings; + +sub new { + my ( $class, $strand ) = @_; + + return undef; +} + +sub hamming_distance { + my ( $self, $strand ) = @_; + + return undef; +} + +__PACKAGE__; diff --git a/exercises/practice/prime-factors/.meta/config.json b/exercises/practice/prime-factors/.meta/config.json index e460c5e4..6d7185ba 100644 --- a/exercises/practice/prime-factors/.meta/config.json +++ b/exercises/practice/prime-factors/.meta/config.json @@ -3,13 +3,13 @@ "authors": [], "files": { "solution": [ - "PrimeFactors.pm" + "Prime.pm" ], "test": [ - "prime-factors.t" + "prime.t" ], "example": [ - ".meta/solutions/PrimeFactors.pm" + ".meta/solutions/Prime.pm" ] }, "source": "The Prime Factors Kata by Uncle Bob", diff --git a/exercises/practice/prime-factors/Prime.pm b/exercises/practice/prime-factors/Prime.pm new file mode 100644 index 00000000..b280817e --- /dev/null +++ b/exercises/practice/prime-factors/Prime.pm @@ -0,0 +1,12 @@ +package Prime; +use strict; +use warnings; + +sub factors { + my ($num) = @_; + + return undef; +} + +1; + diff --git a/exercises/practice/proverb/Proverb.pm b/exercises/practice/proverb/Proverb.pm new file mode 100644 index 00000000..3ccb7731 --- /dev/null +++ b/exercises/practice/proverb/Proverb.pm @@ -0,0 +1,12 @@ +package Proverb; + +use strict; +use warnings; + +sub proverb { + my ( $items, $qualifier ) = @_; + + return undef; +} + +__PACKAGE__; diff --git a/exercises/practice/pythagorean-triplet/.meta/config.json b/exercises/practice/pythagorean-triplet/.meta/config.json index e65b84c3..5015e832 100644 --- a/exercises/practice/pythagorean-triplet/.meta/config.json +++ b/exercises/practice/pythagorean-triplet/.meta/config.json @@ -3,13 +3,13 @@ "authors": [], "files": { "solution": [ - "PythagoreanTriplet.pm" + "Triplet.pm" ], "test": [ - "pythagorean-triplet.t" + "triplet.t" ], "example": [ - ".meta/solutions/PythagoreanTriplet.pm" + ".meta/solutions/Triplet.pm" ] }, "source": "Problem 9 at Project Euler", diff --git a/exercises/practice/pythagorean-triplet/Triplet.pm b/exercises/practice/pythagorean-triplet/Triplet.pm new file mode 100644 index 00000000..4e90a421 --- /dev/null +++ b/exercises/practice/pythagorean-triplet/Triplet.pm @@ -0,0 +1,36 @@ +package Triplet; + +use strict; +use warnings; + +sub new { + my ( $class, @args ) = @_; + + return undef; +} + +sub is_pythagorean { + my $self = shift; + + return undef; +} + +sub sum { + my $self = shift; + + return undef; +} + +sub product { + my $self = shift; + + return undef; +} + +sub products { + my $self = shift; + + return undef; +} + +1; diff --git a/exercises/practice/queen-attack/.meta/config.json b/exercises/practice/queen-attack/.meta/config.json index ff27c64a..ef8fe50e 100644 --- a/exercises/practice/queen-attack/.meta/config.json +++ b/exercises/practice/queen-attack/.meta/config.json @@ -3,13 +3,13 @@ "authors": [], "files": { "solution": [ - "QueenAttack.pm" + "Queens.pm" ], "test": [ - "queen-attack.t" + "queen.t" ], "example": [ - ".meta/solutions/QueenAttack.pm" + ".meta/solutions/Queens.pm" ] }, "source": "J Dalbey's Programming Practice problems", diff --git a/exercises/practice/queen-attack/Queens.pm b/exercises/practice/queen-attack/Queens.pm new file mode 100644 index 00000000..0324901e --- /dev/null +++ b/exercises/practice/queen-attack/Queens.pm @@ -0,0 +1,36 @@ +package Queens; +use strict; +use warnings; + +sub new { + my ( $class, %data ) = @_; + + return undef; +} + +sub white { + my ($self) = @_; + + return undef; +} + +sub black { + my ($self) = @_; + + return undef; +} + +sub to_string { + my ($self) = @_; + + return undef; +} + +sub can_attack { + my ($self) = @_; + + return undef; +} + +1; + diff --git a/exercises/practice/rna-transcription/.meta/config.json b/exercises/practice/rna-transcription/.meta/config.json index 3994f036..67ef35be 100644 --- a/exercises/practice/rna-transcription/.meta/config.json +++ b/exercises/practice/rna-transcription/.meta/config.json @@ -3,13 +3,13 @@ "authors": [], "files": { "solution": [ - "RnaTranscription.pm" + "RNA.pm" ], "test": [ "rna-transcription.t" ], "example": [ - ".meta/solutions/RnaTranscription.pm" + ".meta/solutions/RNA.pm" ] }, "source": "Hyperphysics", diff --git a/exercises/practice/robot-simulator/.meta/config.json b/exercises/practice/robot-simulator/.meta/config.json index e1836a8d..8a4b3ce1 100644 --- a/exercises/practice/robot-simulator/.meta/config.json +++ b/exercises/practice/robot-simulator/.meta/config.json @@ -3,13 +3,13 @@ "authors": [], "files": { "solution": [ - "RobotSimulator.pm" + "Robot.pm" ], "test": [ - "robot-simulator.t" + "robot_simulator.t" ], "example": [ - ".meta/solutions/RobotSimulator.pm" + ".meta/solutions/Robot.pm" ] }, "source": "Inspired by an interview question at a famous company.", diff --git a/exercises/practice/robot-simulator/Robot.pm b/exercises/practice/robot-simulator/Robot.pm new file mode 100644 index 00000000..68c79c1f --- /dev/null +++ b/exercises/practice/robot-simulator/Robot.pm @@ -0,0 +1,82 @@ +# there are 2 packages in this file; separate them once multiple files are supported + +use strict; +use warnings; + +{ + + package Robot; + + + sub new { + return undef; + } + + sub bearing { + return undef; + } + + sub coordinates { + return undef; + } + + sub orient { + my ( $self, $direction ) = @_; + + return undef; + } + + sub turn_right { + my $self = shift; + + return undef; + } + + sub turn_left { + my $self = shift; + + return undef; + } + + sub at { + my ( $self, $x, $y ) = @_; + + return undef; + } + + sub advance { + my $self = shift; + + return undef; + } + +} # end of Package Example; + +{ + + package Simulator; + + sub new { + return undef; + } + + sub place { + my ( $self, $robot, $options ) = @_; + + return undef; + } + + sub evaluate { + my ( $self, $robot, $abbreviation ) = @_; + + return undef; + } + + sub instructions { + my ( $self, $abbreviation ) = @_; + + return undef; + } +} + +1; diff --git a/exercises/practice/saddle-points/.meta/config.json b/exercises/practice/saddle-points/.meta/config.json index a412255a..8ac75040 100644 --- a/exercises/practice/saddle-points/.meta/config.json +++ b/exercises/practice/saddle-points/.meta/config.json @@ -3,13 +3,13 @@ "authors": [], "files": { "solution": [ - "SaddlePoints.pm" + "Matrix.pm" ], "test": [ - "saddle-points.t" + "saddle_points.t" ], "example": [ - ".meta/solutions/SaddlePoints.pm" + ".meta/solutions/Matrix.pm" ] }, "source": "J Dalbey's Programming Practice problems", diff --git a/exercises/practice/saddle-points/Matrix.pm b/exercises/practice/saddle-points/Matrix.pm new file mode 100644 index 00000000..79751328 --- /dev/null +++ b/exercises/practice/saddle-points/Matrix.pm @@ -0,0 +1,30 @@ +package Matrix; + +use strict; +use warnings; + +sub new { + my ( $class, $matrix_str ) = @_; + + return undef; +} + +sub rows { + my ( $self, $index ) = @_; + + return undef; +} + +sub columns { + my ( $self, $index ) = @_; + + return undef; +} + +sub saddle_points { + my $self = shift; + + return undef; +} + +1; diff --git a/exercises/practice/simple-cipher/.meta/config.json b/exercises/practice/simple-cipher/.meta/config.json index 6573da13..2571b062 100644 --- a/exercises/practice/simple-cipher/.meta/config.json +++ b/exercises/practice/simple-cipher/.meta/config.json @@ -3,13 +3,13 @@ "authors": [], "files": { "solution": [ - "SimpleCipher.pm" + "Cipher.pm" ], "test": [ - "simple-cipher.t" + "cipher.t" ], "example": [ - ".meta/solutions/SimpleCipher.pm" + ".meta/solutions/Cipher.pm" ] }, "source": "Substitution Cipher at Wikipedia", diff --git a/exercises/practice/simple-cipher/Cipher.pm b/exercises/practice/simple-cipher/Cipher.pm new file mode 100644 index 00000000..bfd45844 --- /dev/null +++ b/exercises/practice/simple-cipher/Cipher.pm @@ -0,0 +1,24 @@ +package Cipher; + +use strict; +use warnings; + +sub new { + my ( $class, $key ) = @_; + + return undef; +} + +sub encode { + my ( $self, $plaintext ) = @_; + + return undef; +} + +sub decode { + my ( $self, $cipher ) = @_; + + return undef; +} + +1; diff --git a/exercises/practice/simple-linked-list/.meta/config.json b/exercises/practice/simple-linked-list/.meta/config.json index c7d3578a..0b41b102 100644 --- a/exercises/practice/simple-linked-list/.meta/config.json +++ b/exercises/practice/simple-linked-list/.meta/config.json @@ -3,13 +3,13 @@ "authors": [], "files": { "solution": [ - "SimpleLinkedList.pm" + "LinkedList.pm" ], "test": [ - "simple-linked-list.t" + "simple_linked_list.t" ], "example": [ - ".meta/solutions/SimpleLinkedList.pm" + ".meta/solutions/LinkedList.pm" ] }, "source": "Inspired by 'Data Structures and Algorithms with Object-Oriented Design Patterns in Ruby', singly linked-lists.", diff --git a/exercises/practice/simple-linked-list/LinkedList.pm b/exercises/practice/simple-linked-list/LinkedList.pm new file mode 100644 index 00000000..88ddc96e --- /dev/null +++ b/exercises/practice/simple-linked-list/LinkedList.pm @@ -0,0 +1,31 @@ +package LinkedList; + +use strict; +use warnings; + +sub new { + my $class = shift; + + return undef; +} + +sub from_array { + my ( $pkg, $array ) = @_; + + return undef; +} + +sub to_array { + my $self = shift; + + return undef; +} + +sub reverse : method { + my $self = shift; + + return undef; +} + +1; + diff --git a/exercises/practice/strain/.meta/exercise-data.yaml b/exercises/practice/strain/.meta/exercise-data.yaml new file mode 100644 index 00000000..ef980394 --- /dev/null +++ b/exercises/practice/strain/.meta/exercise-data.yaml @@ -0,0 +1,93 @@ +subs: keep discard +tests: |- + my ( $input, $expected, $function ); + + $input = []; + $expected = []; + $function = sub { my $x = shift; $x % 2 == 0 }; + is( keep( $input, $function ), $expected, "empty list" ); + + $input = [ 2, 4, 6, 8, 10 ]; + $expected = []; + $function = sub { my $x = shift; $x % 2 == 1 }; + is( keep( $input, $function ), + $expected, "keep odd numbers. empty result " ); + + $input = [ 2, 4, 6, 8, 10 ]; + $expected = []; + $function = sub { my $x = shift; $x % 2 == 0 }; + is( discard( $input, $function ), + $expected, "discard even numbers. empty result" ); + + $input = [ 2, 4, 6, 8, 10 ]; + $expected = [ 2, 4, 6, 8, 10 ]; + $function = sub { my $x = shift; $x % 2 == 0 }; + is( keep( $input, $function ), + $expected, "keep even numbers. result == input" ); + + $input = [qw(dough cash plough though through enough)]; + $expected = ['cash']; + $function = sub { my $x = shift; $x =~ m/ough$/ }; + is( discard( $input, $function ), + $expected, "discard input endswith 'ough'" ); + + $input = [qw(zebra arizona apple google mozilla)]; + $expected = [qw(zebra arizona mozilla)]; + $function = sub { my $x = shift; $x =~ /z/ }; + is( keep( $input, $function ), + $expected, "keep input with 'z'" ); + + $input = [ '1,2,3', 'one', 'almost!', 'love' ]; + $expected = []; + $function = sub { my $x = shift; $x =~ /\p{IsAlpha}/ }; + is( discard( keep( $input, $function ) // [], $function ), + $expected, "keep then discard" ); + + $input = [ '1,2,3', 'one', 'almost!', 'love' ]; + $expected = [ '1,2,3', 'one', 'almost!', 'love' ]; + $function = sub { my $x = shift; $x =~ /\p{Alpha}/ }; + my $combined = [ + @{ keep( $input, $function ) // [] }, + @{ discard( $input, $function ) // [] } + ]; + is( + [ sort @$combined ], + [ sort @$expected ], + "combine keep and discard results. keep + discard" + ); + +example: |- + sub keep { [ _filter( @_, 1 ) ] } + sub discard { [ _filter( @_, 0 ) ] } + + sub _filter { + my ( $list, $function, $is_keeping ) = @_; + + die "ArgumentError: 2nd parameter must be a function reference" + unless ref $function eq 'CODE'; + + my @result; + + foreach my $element (@$list) { + if ($is_keeping) { + push @result, $element if $function->($element); + next; + } + + # discard + push @result, $element unless $function->($element); + } + + return @result; + } + +stub: |- + sub keep { + my ($input, $function) = @_; + return undef; + } + + sub discard { + my ($input, $function) = @_; + return undef; + } diff --git a/exercises/practice/strain/.meta/solutions/Strain.pm b/exercises/practice/strain/.meta/solutions/Strain.pm index 8dbca995..3072bce5 100644 --- a/exercises/practice/strain/.meta/solutions/Strain.pm +++ b/exercises/practice/strain/.meta/solutions/Strain.pm @@ -1,7 +1,8 @@ package Strain; - use strict; use warnings; +use Exporter qw; +our @EXPORT_OK = qw; sub keep { [ _filter( @_, 1 ) ] } sub discard { [ _filter( @_, 0 ) ] } diff --git a/exercises/practice/strain/Strain.pm b/exercises/practice/strain/Strain.pm new file mode 100644 index 00000000..df954a4c --- /dev/null +++ b/exercises/practice/strain/Strain.pm @@ -0,0 +1,17 @@ +package Strain; +use strict; +use warnings; +use Exporter qw; +our @EXPORT_OK = qw; + +sub keep { + my ( $input, $function ) = @_; + return undef; +} + +sub discard { + my ( $input, $function ) = @_; + return undef; +} + +1; diff --git a/exercises/practice/strain/strain.t b/exercises/practice/strain/strain.t old mode 100644 new mode 100755 index af349f45..40aeed11 --- a/exercises/practice/strain/strain.t +++ b/exercises/practice/strain/strain.t @@ -1,82 +1,66 @@ #!/usr/bin/env perl -use strict; -use warnings; +use Test2::V0; -use Test2::Bundle::More; -use FindBin qw($Bin); +use FindBin qw<$Bin>; use lib $Bin, "$Bin/local/lib/perl5"; -my $module = 'Strain'; +use Strain qw; -plan 12; +imported_ok qw or bail_out; -ok -e "$Bin/$module.pm", "Missing $module.pm" - or BAIL_OUT "You need to create file $module.pm"; - -eval "use $module"; -ok !$@, "Cannot load $module" - or BAIL_OUT - "Cannot load $module. Does it compile? Does it end with 1;?"; - -can_ok $module, "keep" - or BAIL_OUT "Missing package $module or missing sub keep()"; -can_ok $module, "discard" - or BAIL_OUT "Missing package $module or missing sub discard()"; - -my $keep = \&{"${module}::keep"}; -my $discard = \&{"${module}::discard"}; my ( $input, $expected, $function ); $input = []; $expected = []; $function = sub { my $x = shift; $x % 2 == 0 }; -is_deeply( $keep->( $input, $function ), $expected, "empty list" ); +is( keep( $input, $function ), $expected, "empty list" ); $input = [ 2, 4, 6, 8, 10 ]; $expected = []; $function = sub { my $x = shift; $x % 2 == 1 }; -is_deeply( $keep->( $input, $function ), +is( keep( $input, $function ), $expected, "keep odd numbers. empty result " ); $input = [ 2, 4, 6, 8, 10 ]; $expected = []; $function = sub { my $x = shift; $x % 2 == 0 }; -is_deeply( $discard->( $input, $function ), +is( discard( $input, $function ), $expected, "discard even numbers. empty result" ); $input = [ 2, 4, 6, 8, 10 ]; $expected = [ 2, 4, 6, 8, 10 ]; $function = sub { my $x = shift; $x % 2 == 0 }; -is_deeply( $keep->( $input, $function ), +is( keep( $input, $function ), $expected, "keep even numbers. result == input" ); $input = [qw(dough cash plough though through enough)]; $expected = ['cash']; $function = sub { my $x = shift; $x =~ m/ough$/ }; -is_deeply( $discard->( $input, $function ), +is( discard( $input, $function ), $expected, "discard input endswith 'ough'" ); $input = [qw(zebra arizona apple google mozilla)]; $expected = [qw(zebra arizona mozilla)]; $function = sub { my $x = shift; $x =~ /z/ }; -is_deeply( $keep->( $input, $function ), - $expected, "keep input with 'z'" ); +is( keep( $input, $function ), $expected, "keep input with 'z'" ); $input = [ '1,2,3', 'one', 'almost!', 'love' ]; $expected = []; $function = sub { my $x = shift; $x =~ /\p{IsAlpha}/ }; -is_deeply( $discard->( $keep->( $input, $function ), $function ), +is( discard( keep( $input, $function ) // [], $function ), $expected, "keep then discard" ); $input = [ '1,2,3', 'one', 'almost!', 'love' ]; $expected = [ '1,2,3', 'one', 'almost!', 'love' ]; $function = sub { my $x = shift; $x =~ /\p{Alpha}/ }; my $combined = [ - @{ $keep->( $input, $function ) }, - @{ $discard->( $input, $function ) } + @{ keep( $input, $function ) // [] }, + @{ discard( $input, $function ) // [] } ]; -is_deeply( +is( [ sort @$combined ], [ sort @$expected ], "combine keep and discard results. keep + discard" ); + +done_testing; diff --git a/exercises/practice/trinary/Trinary.pm b/exercises/practice/trinary/Trinary.pm new file mode 100644 index 00000000..f0674927 --- /dev/null +++ b/exercises/practice/trinary/Trinary.pm @@ -0,0 +1,17 @@ +package Trinary; + +use strict; +use warnings; + +sub new { + my ( $class, $trinary ) = @_; + + return undef; +} + +sub to_decimal { + my $self = shift; + + return undef; +} +__PACKAGE__;