Untitled

Run Settings
LanguageRaku
Language Version
Run Command
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 } } ] } ] }
unit module ETL; sub transform (%input) is export { Hash[Int:D, Str:D].new: %input».lc.invert.Hash».Int; } sub transform-no-def (%input) is export { Hash[Int, Str].new: %input».lc.invert.Hash».Int; } sub untyped-transform (%input) is export { %input».lc.invert.Hash».Int; }
Editor Settings
Theme
Key bindings
Full width
Lines