tracks/perl6/exercises/allergies/allergies.t in trackler-2.2.1.48 vs tracks/perl6/exercises/allergies/allergies.t in trackler-2.2.1.49

- old
+ new

@@ -3,15 +3,13 @@ use Test; use lib my $dir = $?FILE.IO.dirname; use JSON::Fast; my Str:D $exercise := 'Allergies'; -my Version:D $version = v1; +my Version:D $version = v2; my Str $module //= $exercise; -INIT { - plan 4; -} +plan 4; use-ok $module or bail-out; require ::($module); if ::($exercise).^ver !~~ $version { @@ -22,29 +20,41 @@ } require ::($module) <&allergic-to &list-allergies>; my $c-data; -for @($c-data<cases>) -> %cases { +for $c-data<cases>.values -> %case-set { + subtest 'allergic-to' => { plan 7; - my @cases = |%cases<cases>; - for @cases -> %case { - is allergic-to(%case<score>, .<substance>), .<result>, %case<description> for @(%case<expected>); + for %case-set<cases>.values -> %case { + is allergic-to(%case<score>, .<substance>), .<result>, %case<description> ~ ': ' ~ .<substance> for %case<expected>.values; } - } if %cases<description> ~~ 'allergicTo'; + } when %case-set<description> ~~ 'allergicTo'; + subtest 'list-allergies' => { plan 9; - my @cases = |%cases<cases>; - for @cases { - is list-allergies(.<score>), |.<expected description>; + for %case-set<cases>.values { + cmp-ok list-allergies(.<score>), '~~', .<expected>.Set, .<description>; } - } if %cases<description> ~~ 'list'; + } when %case-set<description> ~~ 'list'; + } -done-testing; +unless %*ENV<EXERCISM> { + skip-rest 'exercism tests'; + exit; +} +subtest 'canonical-data' => { + (my $c-data-file = "$dir/../../problem-specifications/exercises/{ + $dir.IO.resolve.basename + }/canonical-data.json".IO.resolve) ~~ :f ?? + is-deeply $c-data, EVAL('from-json $c-data-file.slurp'), 'match problem-specifications' !! + flunk 'problem-specifications file not found'; +} + INIT { $c-data := from-json q:to/END/; { "exercise": "allergies", @@ -196,21 +206,7 @@ ] } END - if %*ENV<EXERCISM> { - $module = 'Example'; - if (my $c-data-file = - "$dir/../../problem-specifications/exercises/{$dir.IO.resolve.basename}/canonical-data.json" - .IO.resolve) ~~ :f - { - is-deeply $c-data, EVAL('from-json $c-data-file.slurp'), 'canonical-data'; - } - else { - flunk 'canonical-data'; - } - } - else { - skip; - } + $module = 'Example' if %*ENV<EXERCISM>; }