Untitled
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
use JSON::Fast;
use Test;
use lib '.';
require ETL <&transform &transform-no-def &untyped-transform>;
my $data = (from-json $=finish)<cases>[0]<cases>;
for $data.values {
my %input{Int:D};
for .<input>.kv {
%input{$^a.Int} = $^b;
}
my Int %expected-typed{Str} = .<expected>;
my Int:D %expected-defined{Str:D} = .<expected>;
is-deeply local-untyped-transform(%input), .<expected>, .<description>;
is-deeply untyped-transform(%input), .<expected>, .<description>;
is-deeply local-transform-no-def(%input), %expected-typed, .<description>;
is-deeply transform-no-def(%input), %expected-typed, .<description>;
is-deeply local-transform(%input), %expected-defined, .<description>;
is-deeply transform(%input), %expected-defined, .<description>;
}
sub local-transform (%input) {
Hash[Int:D, Str:D].new: %input».lc.invert.Hash».Int;
}
sub local-transform-no-def (%input) {
Hash[Int, Str].new: %input».lc.invert.Hash».Int;
}
sub local-untyped-transform (%input) {
%input».lc.invert.Hash».Int;
}
done-testing;
=finish
{
"exercise": "etl",
"version": "1.0.0",
"cases": [
{
"comments": [
"Note: The expected input data for these tests should have",
"integer keys (not stringified numbers as shown in the JSON below",
"Unless the language prohibits that, please implement these tests",
"such that keys are integers. e.g. in JavaScript, it might look ",
"like `transform( { 1: ['A'] } );`"
],
"description": "transforms the a set of scrabble data previously indexed by the tile score to a set of data indexed by the tile letter",
"cases": [
{
"description": "a single letter",
"property": "transform",
"input": {
"1": ["A"]
},
"expected": {
"a": 1
}
},
{
"description": "single score with multiple letters",
"property": "transform",
"input": {
"1": ["A", "E", "I", "O", "U"]
},
"expected": {
"a": 1,
"e": 1,
"i": 1,
"o": 1,
"u": 1
}
},
{
"description": "multiple scores with multiple letters",
"property": "transform",
"input": {
"1": ["A", "E"],
"2": ["D", "G"]
},
"expected": {
"a": 1,
"d": 2,
"e": 1,
"g": 2
}
},
{
"description": "multiple scores with differing numbers of letters",
"property": "transform",
"input": {
"1": ["A", "E", "I", "O", "U", "L", "N", "R", "S", "T"],
"2": ["D", "G"],
"3": ["B", "C", "M", "P"],
"4": ["F", "H", "V", "W", "Y"],
"5": ["K"],
"8": ["J", "X"],
"10": ["Q", "Z"]
},
"expected": {
"a": 1, "b": 3, "c": 3, "d": 2, "e": 1,
"f": 4, "g": 2, "h": 4, "i": 1, "j": 8,
"k": 5, "l": 1, "m": 3, "n": 1, "o": 1,
"p": 3, "q": 10, "r": 1, "s": 1, "t": 1,
"u": 1, "v": 4, "w": 4, "x": 8, "y": 4,
"z": 10
}
}
]
}
]
}
Raku
INFO