Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
adding advent 2013 day 06
- Loading branch information
Showing
1 changed file
with
44 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| use v6; | ||
| use Test; | ||
|
|
||
| plan 2; | ||
|
|
||
| BEGIN { @*INC.push: 't/spec/packages' } | ||
|
|
||
| use Test::Util; | ||
|
|
||
| my $main = q:to"END-MAIN"; | ||
| use v6; | ||
| use lib 'lib'; | ||
| # the main functionality of the script | ||
| sub deduplicate(Str $s) { | ||
| my %seen; | ||
| $s.comb.grep({!%seen{ .lc }++}).join; | ||
| } | ||
| # normal call | ||
| multi MAIN($phrase) { | ||
| say deduplicate($phrase) | ||
| } | ||
| # if you call the script with --test, it runs its unit tests | ||
| multi MAIN(Bool :$test!) { | ||
| # imports &plan, &is etc. only into the lexical scope | ||
| use Test; | ||
| plan 2; | ||
| is deduplicate('just some words'), | ||
| 'just omewrd', 'basic deduplication'; | ||
| is deduplicate('Abcabd'), | ||
| 'Abcd', 'case insensitivity'; | ||
| } | ||
| END-MAIN | ||
|
|
||
| is_run $main, { | ||
| out => "Duplicate hrmov\n", err => ''}, :args['Duplicate character removal'], 'normal main call'; | ||
|
|
||
| is_run $main, {out => q:to"END-TEST-OUT", er => ''}, :args['--test'], 'test main call'; | ||
| 1..2 | ||
| ok 1 - basic deduplication | ||
| ok 2 - case insensitivity | ||
| END-TEST-OUT |