Sha256: 9d76bf8936487b2277ee3bb8b85c53d899ba975508fe8772a4a8eaf4e65f7156
Contents?: true
Size: 1.9 KB
Versions: 37
Compression:
Stored size: 1.9 KB
Contents
#!/usr/bin/env perl6 use v6; use Test; use lib my $dir = $?FILE.IO.dirname; use JSON::Tiny; my $exercise = 'Leap'; my $version = v1; my $module = %*ENV<EXERCISM> ?? 'Example' !! $exercise; plan 7; use-ok $module or bail-out; require ::($module); if ::($exercise).^ver !~~ $version { warn "\nExercise version mismatch. Further tests may fail!" ~ "\n$exercise is $(::($exercise).^ver.gist). " ~ "Test is $($version.gist).\n"; bail-out 'Example version must match test version.' if %*ENV<EXERCISM>; } my @subs; BEGIN { @subs = <&is-leap-year> }; subtest 'Subroutine(s)', { plan 1; eval-lives-ok "use $module; ::('$_').defined or die '$_ is not defined.'", $_ for @subs; } or bail-out 'All subroutines must be defined and exported.'; require ::($module) @subs.eager; is .<input>.&is-leap-year, |.<expected description> for @(my $c-data.<cases>); if %*ENV<EXERCISM> && (my $c-data-file = "$dir/../../x-common/exercises/{$dir.IO.basename}/canonical-data.json".IO.resolve) ~~ :f { is-deeply $c-data, from-json($c-data-file.slurp), 'canonical-data' } else { skip } done-testing; INIT { $c-data := from-json 「 { "exercise": "leap", "version": "1.0.0", "cases": [ { "description": "year not divisible by 4: common year", "property": "leapYear", "input": 2015, "expected": false }, { "description": "year divisible by 4, not divisible by 100: leap year", "property": "leapYear", "input": 2016, "expected": true }, { "description": "year divisible by 100, not divisible by 400: common year", "property": "leapYear", "input": 2100, "expected": false }, { "description": "year divisible by 400: leap year", "property": "leapYear", "input": 2000, "expected": true } ] } 」 }
Version data entries
37 entries across 37 versions & 1 rubygems