exercism-perl5

Repository for my Perl 5 Exercism exercises
git clone git://git.samirparikh.com/exercism-perl5
Log | Files | Refs | README

etl.t (2397B) - raw


      1 #!/usr/bin/env perl
      2 use Test2::V0;
      3 use JSON::PP;
      4 use constant JSON => JSON::PP->new;
      5 
      6 use FindBin qw<$Bin>;
      7 use lib $Bin, "$Bin/local/lib/perl5";
      8 
      9 use ETL qw<transform>;
     10 
     11 my @test_cases = do { local $/; @{ JSON->decode(<DATA>) }; };
     12 plan 5;
     13 
     14 imported_ok qw<transform> or bail_out;
     15 
     16 for my $case (@test_cases) {
     17   &is(
     18     transform( $case->{input}{legacy} ),
     19     @{$case}{qw<expected description>}
     20   );
     21 }
     22 
     23 __DATA__
     24 [
     25   {
     26     "description": "single letter",
     27     "expected": {
     28       "a": 1
     29     },
     30     "input": {
     31       "legacy": {
     32         "1": [
     33           "A"
     34         ]
     35       }
     36     },
     37     "property": "transform"
     38   },
     39   {
     40     "description": "single score with multiple letters",
     41     "expected": {
     42       "a": 1,
     43       "e": 1,
     44       "i": 1,
     45       "o": 1,
     46       "u": 1
     47     },
     48     "input": {
     49       "legacy": {
     50         "1": [
     51           "A",
     52           "E",
     53           "I",
     54           "O",
     55           "U"
     56         ]
     57       }
     58     },
     59     "property": "transform"
     60   },
     61   {
     62     "description": "multiple scores with multiple letters",
     63     "expected": {
     64       "a": 1,
     65       "d": 2,
     66       "e": 1,
     67       "g": 2
     68     },
     69     "input": {
     70       "legacy": {
     71         "1": [
     72           "A",
     73           "E"
     74         ],
     75         "2": [
     76           "D",
     77           "G"
     78         ]
     79       }
     80     },
     81     "property": "transform"
     82   },
     83   {
     84     "description": "multiple scores with differing numbers of letters",
     85     "expected": {
     86       "a": 1,
     87       "b": 3,
     88       "c": 3,
     89       "d": 2,
     90       "e": 1,
     91       "f": 4,
     92       "g": 2,
     93       "h": 4,
     94       "i": 1,
     95       "j": 8,
     96       "k": 5,
     97       "l": 1,
     98       "m": 3,
     99       "n": 1,
    100       "o": 1,
    101       "p": 3,
    102       "q": 10,
    103       "r": 1,
    104       "s": 1,
    105       "t": 1,
    106       "u": 1,
    107       "v": 4,
    108       "w": 4,
    109       "x": 8,
    110       "y": 4,
    111       "z": 10
    112     },
    113     "input": {
    114       "legacy": {
    115         "1": [
    116           "A",
    117           "E",
    118           "I",
    119           "O",
    120           "U",
    121           "L",
    122           "N",
    123           "R",
    124           "S",
    125           "T"
    126         ],
    127         "10": [
    128           "Q",
    129           "Z"
    130         ],
    131         "2": [
    132           "D",
    133           "G"
    134         ],
    135         "3": [
    136           "B",
    137           "C",
    138           "M",
    139           "P"
    140         ],
    141         "4": [
    142           "F",
    143           "H",
    144           "V",
    145           "W",
    146           "Y"
    147         ],
    148         "5": [
    149           "K"
    150         ],
    151         "8": [
    152           "J",
    153           "X"
    154         ]
    155       }
    156     },
    157     "property": "transform"
    158   }
    159 ]