From f2be4c1133cf288b9d3980c9f1a32ca69e52dd90 Mon Sep 17 00:00:00 2001 From: Jörg Sommrey <28217714+jo-37@users.noreply.github.com> Date: Tue, 29 Nov 2022 18:58:03 +0100 Subject: Solution to task 2 --- challenge-193/jo-37/perl/ch-2.pl | 83 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 83 insertions(+) create mode 100755 challenge-193/jo-37/perl/ch-2.pl diff --git a/challenge-193/jo-37/perl/ch-2.pl b/challenge-193/jo-37/perl/ch-2.pl new file mode 100755 index 0000000000..f5dec6045d --- /dev/null +++ b/challenge-193/jo-37/perl/ch-2.pl @@ -0,0 +1,83 @@ +#!/usr/bin/perl -s + +use v5.16; +use Test2::V0; +use List::MoreUtils 'slide'; +use experimental 'signatures'; + +our ($tests, $examples); + +run_tests() if $tests || $examples; # does not return + +die <{"@key"} = exists $href->{"@key"} ? undef : $val; +} + + +### Examples and tests + +sub run_tests { + SKIP: { + skip "examples" unless $examples; + is [pick_odd(qw(adc wzy abc))], ['abc'], 'Example 1'; + is [pick_odd(qw(aaa bob ccc ddd))], ['bob'], 'Example 2'; + } + + SKIP: { + skip "tests" unless $tests; + is [pick_odd(qw(abc abd abe))], + bag {item 'abc'; item 'abd'; item 'abe'; end}, 'all odd'; + is [pick_odd(qw(abcd bcde cdef defg))], [], 'no odd one'; + is [pick_odd(qw(abm alm))], + bag {item 'abm'; item 'alm'; end}, '[1, 11] != [11, 1]'; + is [pick_odd(qw(aa bb cc ddd))], ['ddd'], 'odd length'; + } + + done_testing; + exit; +} -- cgit