diff options
| author | Jörg Sommrey <28217714+jo-37@users.noreply.github.com> | 2023-07-03 21:52:48 +0200 |
|---|---|---|
| committer | Jörg Sommrey <28217714+jo-37@users.noreply.github.com> | 2023-07-07 12:02:25 +0200 |
| commit | 7684bf94276fe93d56c78ae27f6e6916222b230f (patch) | |
| tree | dc80dc1a47af10754d4dd2c52b7cb52d676a6d9a | |
| parent | f99b967f32786b8aaeb2fe68a4c3042bd1a94b70 (diff) | |
| download | perlweeklychallenge-club-7684bf94276fe93d56c78ae27f6e6916222b230f.tar.gz perlweeklychallenge-club-7684bf94276fe93d56c78ae27f6e6916222b230f.tar.bz2 perlweeklychallenge-club-7684bf94276fe93d56c78ae27f6e6916222b230f.zip | |
Solution to task 1
| -rwxr-xr-x | challenge-224/jo-37/perl/ch-1.pl | 68 |
1 files changed, 68 insertions, 0 deletions
diff --git a/challenge-224/jo-37/perl/ch-1.pl b/challenge-224/jo-37/perl/ch-1.pl new file mode 100755 index 0000000000..d402e1bc5e --- /dev/null +++ b/challenge-224/jo-37/perl/ch-1.pl @@ -0,0 +1,68 @@ +#!/usr/bin/perl -s + +use v5.24; +use Test2::V0; + +our ($tests, $examples); + +{ + # Import the solution from week #221. + package CH_221; + + # Without arguments, the called program will die with a usage + # message. Capture this message as success indicator. + local @ARGV; + do '../../../challenge-221/jo-37/perl/ch-1.pl'; + die $@ unless $@ =~ /^usage: $0/; +} + +run_tests() if $tests || $examples; # does not return + +die <<EOS unless @ARGV == 2; +usage: $0 [-examples] [-tests] [SOURCE TARGET] + +-examples + run the examples from the challenge + +-tests + run some tests + +SOURCE + source string + +TARGET + check if the target can be created from the characters of SOURCE + +EOS + + +### Input and Output + +say CH_221::good_string_length(@ARGV) ? 'true' : 'false'; + + +### Implementation + +# This task is a special case of task 1 from week 221. There's a single +# word to check and here we just need to see if the result is nonzero. + + +### Examples and tests + +sub run_tests { + SKIP: { + skip "examples" unless $examples; + + ok !CH_221::good_string_length('abc', 'xyz'), 'example 1'; + ok CH_221::good_string_length('scriptinglanguage', 'perl'), + 'example 2'; + ok CH_221::good_string_length('aabbcc', 'abc'), 'example 3'; + } + + SKIP: { + skip "tests" unless $tests; + } + + done_testing; + exit; +} |
