diff --git a/exercises/allergies/Example.p6 b/exercises/allergies/Example.pm similarity index 100% rename from exercises/allergies/Example.p6 rename to exercises/allergies/Example.pm diff --git a/exercises/allergies/allergies.t b/exercises/allergies/allergies.t index a64c8a07..4755dfff 100755 --- a/exercises/allergies/allergies.t +++ b/exercises/allergies/allergies.t @@ -3,20 +3,15 @@ use Test; use JSON::Tiny; -use lib ( my $dir = IO::Path.new($?FILE).parent ).path; +use lib IO::Path.new($?FILE).parent.path; -my $module_name = %*ENV.so ?? 'Example' !! 'Allergies'; -my @potential_module = .map: $module_name ~ '.' ~ *; +my $module = %*ENV.so ?? 'Example' !! 'Allergies'; -my $module = first { $dir.child($_).e }, |@potential_module - or die "No file '$module_name.p6' found\n"; - -require $module <&allergic-to &list-allergies>; +require ::($module) <&allergic-to &list-allergies>; plan 2; -my %cases = from-json $dir.child('cases.json').slurp; - +my %cases; subtest 'allergic-to' => { my @cases = |%cases{'allergic_to'}{'cases'}; @@ -43,3 +38,119 @@ subtest 'list' => { or diag $_; } }; + +done-testing; + +INIT { + %cases = from-json 「 + { + "allergic_to": { + "description": [ + "Given a number and a substance, indicate whether Tom is allergic ", + "to that substance.", + "Test cases for this method involve more than one assertion.", + "Each case in 'expected' specifies what the method should return for", + "the given substance." + ], + "cases": [ + { + "description": "no allergies means not allergic", + "score": 0, + "expected": [ + { + "substance": "peanuts", + "result": false + }, + { + "substance": "cats", + "result": false + }, + { + "substance": "strawberries", + "result": false + } + ] + }, + { + "description": "is allergic to eggs", + "score": 1, + "expected": [ + { + "substance": "eggs", + "result": true + } + ] + }, + { + "description": "allergic to eggs in addition to other stuff", + "score": 5, + "expected": [ + { + "substance": "eggs", + "result": true + }, + { + "substance": "shellfish", + "result": true + }, + { + "substance": "strawberries", + "result": false + } + ] + } + ] + }, + "list": { + "description": ["Given a number, list all things Tom is allergic to"], + "cases": [ + { + "description": "no allergies at all", + "score": 0, + "expected": [] + }, + { + "description": "allergic to just eggs", + "score": 1, + "expected": ["eggs"] + }, + { + "description": "allergic to just peanuts", + "score": 2, + "expected": ["peanuts"] + }, + { + "description": "allergic to just strawberries", + "score": 8, + "expected": ["strawberries"] + }, + { + "description": "allergic to eggs and peanuts", + "score": 3, + "expected": ["eggs", "peanuts"] + }, + { + "description": "allergic to more than eggs but not peanuts", + "score": 5, + "expected": ["eggs", "shellfish"] + }, + { + "description": "allergic to lots of stuff", + "score": 248, + "expected": ["strawberries", "tomatoes", "chocolate", "pollen", "cats"] + }, + { + "description": "allergic to everything", + "score": 255, + "expected": ["eggs", "peanuts", "shellfish", "strawberries", "tomatoes", "chocolate", "pollen", "cats"] + }, + { + "description": "ignore non allergen score parts", + "score": 509, + "expected": ["eggs", "shellfish", "strawberries", "tomatoes", "chocolate", "pollen", "cats"] + } + ] + } + } + 」 +} diff --git a/exercises/allergies/cases.json b/exercises/allergies/cases.json deleted file mode 100644 index a5175773..00000000 --- a/exercises/allergies/cases.json +++ /dev/null @@ -1,109 +0,0 @@ -{ - "allergic_to": { - "description": [ - "Given a number and a substance, indicate whether Tom is allergic ", - "to that substance.", - "Test cases for this method involve more than one assertion.", - "Each case in 'expected' specifies what the method should return for", - "the given substance." - ], - "cases": [ - { - "description": "no allergies means not allergic", - "score": 0, - "expected": [ - { - "substance": "peanuts", - "result": false - }, - { - "substance": "cats", - "result": false - }, - { - "substance": "strawberries", - "result": false - } - ] - }, - { - "description": "is allergic to eggs", - "score": 1, - "expected": [ - { - "substance": "eggs", - "result": true - } - ] - }, - { - "description": "allergic to eggs in addition to other stuff", - "score": 5, - "expected": [ - { - "substance": "eggs", - "result": true - }, - { - "substance": "shellfish", - "result": true - }, - { - "substance": "strawberries", - "result": false - } - ] - } - ] - }, - "list": { - "description": ["Given a number, list all things Tom is allergic to"], - "cases": [ - { - "description": "no allergies at all", - "score": 0, - "expected": [] - }, - { - "description": "allergic to just eggs", - "score": 1, - "expected": ["eggs"] - }, - { - "description": "allergic to just peanuts", - "score": 2, - "expected": ["peanuts"] - }, - { - "description": "allergic to just strawberries", - "score": 8, - "expected": ["strawberries"] - }, - { - "description": "allergic to eggs and peanuts", - "score": 3, - "expected": ["eggs", "peanuts"] - }, - { - "description": "allergic to more than eggs but not peanuts", - "score": 5, - "expected": ["eggs", "shellfish"] - }, - { - "description": "allergic to lots of stuff", - "score": 248, - "expected": ["strawberries", "tomatoes", "chocolate", "pollen", "cats"] - }, - { - "description": "allergic to everything", - "score": 255, - "expected": ["eggs", "peanuts", "shellfish", "strawberries", "tomatoes", "chocolate", "pollen", "cats"] - }, - { - "description": "ignore non allergen score parts", - "score": 509, - "expected": ["eggs", "shellfish", "strawberries", "tomatoes", "chocolate", "pollen", "cats"] - } - ] - } -} diff --git a/exercises/atbash-cipher/Example.p6 b/exercises/atbash-cipher/Example.pm similarity index 100% rename from exercises/atbash-cipher/Example.p6 rename to exercises/atbash-cipher/Example.pm diff --git a/exercises/atbash-cipher/cases.json b/exercises/atbash-cipher/cases.json deleted file mode 100644 index 43241c96..00000000 --- a/exercises/atbash-cipher/cases.json +++ /dev/null @@ -1,82 +0,0 @@ -{ - "#": [ - "The tests are divided into two groups: ", - "* Encoding from English to atbash cipher", - "* Decoding from atbash cipher to all-lowercase-mashed-together English" - ], - "encode": { - "description": ["Test encoding from English to atbash"], - "cases": [ - { - "description": "encode yes", - "phrase": "yes", - "expected": "bvh" - }, - { - "description": "encode no", - "phrase": "no", - "expected": "ml" - }, - { - "description": "encode OMG", - "phrase": "OMG", - "expected": "lnt" - }, - { - "description": "encode spaces", - "phrase": "O M G", - "expected": "lnt" - }, - { - "description": "encode mindblowingly", - "phrase": "mindblowingly", - "expected": "nrmwy oldrm tob" - }, - { - "description": "encode numbers", - "phrase": "Testing,1 2 3, testing.", - "expected": "gvhgr mt123 gvhgr mt" - }, - { - "description": "encode deep thought", - "phrase": "Truth is fiction.", - "expected": "gifgs rhurx grlm" - }, - { - "description": "encode all the letters", - "phrase": "The quick brown fox jumps over the lazy dog.", - "expected": "gsvjf rxpyi ldmul cqfnk hlevi gsvoz abwlt" - }, - { - "description": "encode ignores non ascii", - "phrase": "non ascii éignored", - "expected": "mlmzh xrrrt mlivw" - } - ] - }, - "decode": { - "description": ["Test decoding from atbash to English"], - "cases": [ - { - "description": "decode exercism", - "phrase": "vcvix rhn", - "expected": "exercism" - }, - { - "description": "decode a sentence", - "phrase": "zmlyh gzxov rhlug vmzhg vkkrm thglm v", - "expected": "anobstacleisoftenasteppingstone" - }, - { - "description": "decode numbers", - "phrase": "gvhgr mt123 gvhgr mt", - "expected": "testing123testing" - }, - { - "description": "decode all the letters", - "phrase": "gsvjf rxpyi ldmul cqfnk hlevi gsvoz abwlt", - "expected": "thequickbrownfoxjumpsoverthelazydog" - } - ] - } -} diff --git a/exercises/atbash-cipher/cipher.t b/exercises/atbash-cipher/cipher.t index b68d4668..fae534fd 100755 --- a/exercises/atbash-cipher/cipher.t +++ b/exercises/atbash-cipher/cipher.t @@ -3,20 +3,15 @@ use Test; use JSON::Tiny; -use lib ( my $dir = IO::Path.new($?FILE).parent ).path; +use lib IO::Path.new($?FILE).parent.path; -my $module_name = %*ENV.so ?? 'Example' !! 'Cipher'; -my @potential_module = .map: $module_name ~ '.' ~ *; +my $module = %*ENV.so ?? 'Example' !! 'Cipher'; -my $module = first { $dir.child($_).e }, |@potential_module - or die "No file '$module_name.p6' found\n"; - -require $module <&encode &decode>; +require ::($module) <&encode &decode>; plan 2; -my %cases = from-json $dir.child('cases.json').slurp; - +my %cases; subtest 'encode' => { my @cases = |%cases..; @@ -34,3 +29,92 @@ subtest 'decode' => { is decode( . ), ., . for @cases; }; + +done-testing; + +INIT { + %cases = from-json 「 + { + "#": [ + "The tests are divided into two groups: ", + "* Encoding from English to atbash cipher", + "* Decoding from atbash cipher to all-lowercase-mashed-together English" + ], + "encode": { + "description": ["Test encoding from English to atbash"], + "cases": [ + { + "description": "encode yes", + "phrase": "yes", + "expected": "bvh" + }, + { + "description": "encode no", + "phrase": "no", + "expected": "ml" + }, + { + "description": "encode OMG", + "phrase": "OMG", + "expected": "lnt" + }, + { + "description": "encode spaces", + "phrase": "O M G", + "expected": "lnt" + }, + { + "description": "encode mindblowingly", + "phrase": "mindblowingly", + "expected": "nrmwy oldrm tob" + }, + { + "description": "encode numbers", + "phrase": "Testing,1 2 3, testing.", + "expected": "gvhgr mt123 gvhgr mt" + }, + { + "description": "encode deep thought", + "phrase": "Truth is fiction.", + "expected": "gifgs rhurx grlm" + }, + { + "description": "encode all the letters", + "phrase": "The quick brown fox jumps over the lazy dog.", + "expected": "gsvjf rxpyi ldmul cqfnk hlevi gsvoz abwlt" + }, + { + "description": "encode ignores non ascii", + "phrase": "non ascii éignored", + "expected": "mlmzh xrrrt mlivw" + } + ] + }, + "decode": { + "description": ["Test decoding from atbash to English"], + "cases": [ + { + "description": "decode exercism", + "phrase": "vcvix rhn", + "expected": "exercism" + }, + { + "description": "decode a sentence", + "phrase": "zmlyh gzxov rhlug vmzhg vkkrm thglm v", + "expected": "anobstacleisoftenasteppingstone" + }, + { + "description": "decode numbers", + "phrase": "gvhgr mt123 gvhgr mt", + "expected": "testing123testing" + }, + { + "description": "decode all the letters", + "phrase": "gsvjf rxpyi ldmul cqfnk hlevi gsvoz abwlt", + "expected": "thequickbrownfoxjumpsoverthelazydog" + } + ] + } + } + 」 +} diff --git a/exercises/phone-number/cases.json b/exercises/phone-number/cases.json deleted file mode 100644 index 9022ac4d..00000000 --- a/exercises/phone-number/cases.json +++ /dev/null @@ -1,47 +0,0 @@ -{ - "valid": [ - { - "input": 1234567890, - "number": "1234567890", - "area-code": "123", - "pretty": "(123) 456-7890", - "test": "10 digit integer" - }, - { - "input": "+1 (234) 555-6789", - "number": "2345556789", - "area-code": "234", - "pretty": "(234) 555-6789", - "test": "11 digit formatted number" - }, - { - "input": "1.379.555.2468", - "number": "3795552468", - "area-code": "379", - "pretty": "(379) 555-2468", - "test": "11 digit number containing separators" - } - ], - "invalid": [ - { - "input": "", - "test": "empty input" - }, - { - "input": "13579", - "test": "5 digit number" - }, - { - "input": "123456789011", - "test": "12 digit number" - }, - { - "input": "+2 (468) 555-1379", - "test": "11 digit number not beginning with 1" - }, - { - "input": "phone number", - "test": "not a number" - } - ] -} diff --git a/exercises/phone-number/phone.t b/exercises/phone-number/phone.t index 794ae2b1..1fa31c49 100755 --- a/exercises/phone-number/phone.t +++ b/exercises/phone-number/phone.t @@ -2,15 +2,14 @@ use v6; use Test; use JSON::Tiny; -use lib my $path = IO::Path.new($?FILE).parent.path; +use lib IO::Path.new($?FILE).parent.path; plan 12; my $module = %*ENV ?? 'Example' !! 'Phone'; use-ok $module; require ::($module) ; -my %tests = from-json open("$path/cases.json").slurp-rest; - +my %cases; subtest 'number, area-code and pretty methods', { plan 3; ok Phone.can('number'), 'can Phone.number'; @@ -18,7 +17,7 @@ subtest 'number, area-code and pretty methods', { ok Phone.can('pretty'), 'can Phone.pretty'; } or fail 'Missing method(s).'; -for @(%tests) { +for @(%cases) { my $phone = Phone.new(number => .); my $msg = 'for ' ~ .; is $phone.number, ., "number $msg"; @@ -29,5 +28,59 @@ for @(%tests) { todo 'Optional Exception Tests' unless %*ENV; # Remove this line for invalid input tests subtest 'Throw exceptions for invalid input', { plan 5; - throws-like {Phone.new(number => .)}, Exception, . for @(%tests); + throws-like {Phone.new(number => .)}, Exception, . for @(%cases); +} + +done-testing; + +INIT { + %cases = from-json 「 + { + "valid": [ + { + "input": 1234567890, + "number": "1234567890", + "area-code": "123", + "pretty": "(123) 456-7890", + "test": "10 digit integer" + }, + { + "input": "+1 (234) 555-6789", + "number": "2345556789", + "area-code": "234", + "pretty": "(234) 555-6789", + "test": "11 digit formatted number" + }, + { + "input": "1.379.555.2468", + "number": "3795552468", + "area-code": "379", + "pretty": "(379) 555-2468", + "test": "11 digit number containing separators" + } + ], + "invalid": [ + { + "input": "", + "test": "empty input" + }, + { + "input": "13579", + "test": "5 digit number" + }, + { + "input": "123456789011", + "test": "12 digit number" + }, + { + "input": "+2 (468) 555-1379", + "test": "11 digit number not beginning with 1" + }, + { + "input": "phone number", + "test": "not a number" + } + ] + } + 」 } diff --git a/exercises/space-age/Example.p6 b/exercises/space-age/Example.pm similarity index 100% rename from exercises/space-age/Example.p6 rename to exercises/space-age/Example.pm diff --git a/exercises/space-age/cases.json b/exercises/space-age/cases.json deleted file mode 100644 index d653de7b..00000000 --- a/exercises/space-age/cases.json +++ /dev/null @@ -1,46 +0,0 @@ -{ "#": [], - "age on": { - "cases": [ - { - "planet": "Earth", - "seconds": 1000000000, - "expected": 31.69 - }, - { - "planet": "Mercury", - "seconds": 2134835688, - "expected": 280.88 - }, - { - "planet": "Venus", - "seconds": 189839836, - "expected": 9.78 - }, - { - "planet": "Mars", - "seconds": 2329871239, - "expected": 39.25 - }, - { - "planet": "Jupiter", - "seconds": 901876382, - "expected": 2.41 - }, - { - "planet": "Saturn", - "seconds": 3000000000, - "expected": 3.23 - }, - { - "planet": "Uranus", - "seconds": 3210123456, - "expected": 1.21 - }, - { - "planet": "Neptune", - "seconds": 8210123456, - "expected": 1.58 - } - ] - } -} diff --git a/exercises/space-age/space-age.t b/exercises/space-age/space-age.t index 1c65afd3..b32c1721 100755 --- a/exercises/space-age/space-age.t +++ b/exercises/space-age/space-age.t @@ -3,21 +3,65 @@ use Test; use JSON::Tiny; -use lib ( my $dir = IO::Path.new($?FILE).parent ).path; +use lib IO::Path.new($?FILE).parent.path; -my $module_name = %*ENV.so ?? 'Example' !! 'SpaceAge'; -my @potential_module = .map: $module_name ~ '.' ~ *; +my $module = %*ENV.so ?? 'Example' !! 'SpaceAge'; -my $module = first { $dir.child($_).e }, |@potential_module - or die "No file '$module_name.p6' found\n"; - -require $module <&age-on>; +require ::($module) <&age-on>; plan 8; -my %testcase = from-json $dir.child('cases.json').slurp; - -for |%testcase{'age on'}{'cases'} -> %case { +my @cases; +for @cases -> %case { is age-on( |%case), %case{'expected'}, %case.gist; } + +done-testing; + +INIT { + @cases = from-json 「 + [ + { + "planet": "Earth", + "seconds": 1000000000, + "expected": 31.69 + }, + { + "planet": "Mercury", + "seconds": 2134835688, + "expected": 280.88 + }, + { + "planet": "Venus", + "seconds": 189839836, + "expected": 9.78 + }, + { + "planet": "Mars", + "seconds": 2329871239, + "expected": 39.25 + }, + { + "planet": "Jupiter", + "seconds": 901876382, + "expected": 2.41 + }, + { + "planet": "Saturn", + "seconds": 3000000000, + "expected": 3.23 + }, + { + "planet": "Uranus", + "seconds": 3210123456, + "expected": 1.21 + }, + { + "planet": "Neptune", + "seconds": 8210123456, + "expected": 1.58 + } + ] + 」 +} diff --git a/exercises/wordy/Example.p6 b/exercises/wordy/Example.pm similarity index 100% rename from exercises/wordy/Example.p6 rename to exercises/wordy/Example.pm diff --git a/exercises/wordy/cases.json b/exercises/wordy/cases.json deleted file mode 100644 index b736432b..00000000 --- a/exercises/wordy/cases.json +++ /dev/null @@ -1,89 +0,0 @@ -{ - "#": [ - "The tests that expect 'false' should be implemented to raise", - "an error, or indicate a failure. Implement this in a way that", - "makes sense for your language." - ], - "cases": [ - { - "description": "addition", - "input": "What is 1 plus 1?", - "expected": 2 - }, - { - "description": "more addition", - "input": "What is 53 plus 2?", - "expected": 55 - }, - { - "description": "addition with negative numbers", - "input": "What is -1 plus -10?", - "expected": -11 - }, - { - "description": "large addition", - "input": "What is 123 plus 45678?", - "expected": 45801 - }, - { - "description": "subtraction", - "input": "What is 4 minus -12?", - "expected": 16 - }, - { - "description": "multiplication", - "input": "What is -3 multiplied by 25?", - "expected": -75 - }, - { - "description": "division", - "input": "What is 33 divided by -3?", - "expected": -11 - }, - { - "description": "multiple additions", - "input": "What is 1 plus 1 plus 1?", - "expected": 3 - }, - { - "description": "addition and subtraction", - "input": "What is 1 plus 5 minus -2?", - "expected": 8 - }, - { - "description": "multiple subtraction", - "input": "What is 20 minus 4 minus 13?", - "expected": 3 - }, - { - "description": "subtraction then addition", - "input": "What is 17 minus 6 plus 3?", - "expected": 14 - }, - { - "description": "multiple multiplication", - "input": "What is 2 multiplied by -2 multiplied by 3?", - "expected": -12 - }, - { - "description": "addition and multiplication", - "input": "What is -3 plus 7 multiplied by -2?", - "expected": -8 - }, - { - "description": "multiple division", - "input": "What is -12 divided by 2 divided by -3?", - "expected": 2 - }, - { - "description": "unknown operation", - "input": "What is 52 cubed?", - "expected": null - }, - { - "description": "Non math question", - "input": "Who is the President of the United States?", - "expected": null - } - ] -} diff --git a/exercises/wordy/wordy.t b/exercises/wordy/wordy.t index 0b727802..58b324af 100755 --- a/exercises/wordy/wordy.t +++ b/exercises/wordy/wordy.t @@ -3,21 +3,16 @@ use Test; use JSON::Tiny; -use lib ( my $dir = IO::Path.new($?FILE).parent ).path; +use lib IO::Path.new($?FILE).parent.path; -my $module_name = %*ENV.so ?? 'Example' !! 'Wordy'; -my @potential_module = .map: $module_name ~ '.' ~ *; +my $module = %*ENV.so ?? 'Example' !! 'Wordy'; -my $module = first { $dir.child($_).e }, |@potential_module - or die "No file '$module_name.p6' found\n"; - -require $module <&answer>; +require ::($module) <&answer>; plan 16; -my %cases = from-json $dir.child('cases.json').slurp; - -for |%cases -> %case { +my @cases; +for @cases -> %case { with %case { is answer(%case), |%case or diag 'input: ' ~ %case; @@ -27,3 +22,92 @@ for |%cases -> %case { or diag 'input: ' ~ %case; } } + +done-testing; + +INIT { + @cases = from-json 「 + [ + { + "description": "addition", + "input": "What is 1 plus 1?", + "expected": 2 + }, + { + "description": "more addition", + "input": "What is 53 plus 2?", + "expected": 55 + }, + { + "description": "addition with negative numbers", + "input": "What is -1 plus -10?", + "expected": -11 + }, + { + "description": "large addition", + "input": "What is 123 plus 45678?", + "expected": 45801 + }, + { + "description": "subtraction", + "input": "What is 4 minus -12?", + "expected": 16 + }, + { + "description": "multiplication", + "input": "What is -3 multiplied by 25?", + "expected": -75 + }, + { + "description": "division", + "input": "What is 33 divided by -3?", + "expected": -11 + }, + { + "description": "multiple additions", + "input": "What is 1 plus 1 plus 1?", + "expected": 3 + }, + { + "description": "addition and subtraction", + "input": "What is 1 plus 5 minus -2?", + "expected": 8 + }, + { + "description": "multiple subtraction", + "input": "What is 20 minus 4 minus 13?", + "expected": 3 + }, + { + "description": "subtraction then addition", + "input": "What is 17 minus 6 plus 3?", + "expected": 14 + }, + { + "description": "multiple multiplication", + "input": "What is 2 multiplied by -2 multiplied by 3?", + "expected": -12 + }, + { + "description": "addition and multiplication", + "input": "What is -3 plus 7 multiplied by -2?", + "expected": -8 + }, + { + "description": "multiple division", + "input": "What is -12 divided by 2 divided by -3?", + "expected": 2 + }, + { + "description": "unknown operation", + "input": "What is 52 cubed?", + "expected": null + }, + { + "description": "Non math question", + "input": "Who is the President of the United States?", + "expected": null + } + ] + 」 +}