Skip to content

Commit

Permalink
Move JSON into test suites
Browse files Browse the repository at this point in the history
  • Loading branch information
m-dango committed Feb 8, 2017
1 parent c12a513 commit 5e4fed7
Show file tree
Hide file tree
Showing 10 changed files with 411 additions and 392 deletions.
121 changes: 118 additions & 3 deletions exercises/allergies/allergies.t
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,14 @@
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 = %*ENV<EXERCISM> ?? 'Example' !! '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'};

Expand All @@ -38,3 +37,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"]
}
]
}
}
}
109 changes: 0 additions & 109 deletions exercises/allergies/cases.json

This file was deleted.

94 changes: 91 additions & 3 deletions exercises/atbash-cipher/atbash-cipher.t
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,14 @@
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 = %*ENV<EXERCISM> ?? 'Example' !! 'Cipher';
require ::($module) <&encode &decode>;

plan 2;

my %cases = from-json $dir.child('cases.json').slurp;

my %cases;
subtest 'encode' => {
my @cases = |%cases.<encode>.<cases>;

Expand All @@ -29,3 +28,92 @@ subtest 'decode' => {
is decode( .<phrase> ), .<expected>, .<description>
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"
}
]
}
}
}
Loading

0 comments on commit 5e4fed7

Please sign in to comment.