exercism-perl5

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

scrabble-score.t (1955B) - 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 ScrabbleScore qw<scrabble_score>;
     10 
     11 my @test_cases = do { local $/; @{ JSON->decode(<DATA>) }; };
     12 
     13 imported_ok qw<scrabble_score> or bail_out;
     14 
     15 for my $case (@test_cases) {
     16   is( scrabble_score( $case->{input}{word} ),
     17     $case->{expected}, $case->{description}, );
     18 }
     19 
     20 done_testing;
     21 
     22 __DATA__
     23 [
     24   {
     25     "description": "lowercase letter",
     26     "expected": 1,
     27     "input": {
     28       "word": "a"
     29     },
     30     "property": "score"
     31   },
     32   {
     33     "description": "uppercase letter",
     34     "expected": 1,
     35     "input": {
     36       "word": "A"
     37     },
     38     "property": "score"
     39   },
     40   {
     41     "description": "valuable letter",
     42     "expected": 4,
     43     "input": {
     44       "word": "f"
     45     },
     46     "property": "score"
     47   },
     48   {
     49     "description": "short word",
     50     "expected": 2,
     51     "input": {
     52       "word": "at"
     53     },
     54     "property": "score"
     55   },
     56   {
     57     "description": "short, valuable word",
     58     "expected": 12,
     59     "input": {
     60       "word": "zoo"
     61     },
     62     "property": "score"
     63   },
     64   {
     65     "description": "medium word",
     66     "expected": 6,
     67     "input": {
     68       "word": "street"
     69     },
     70     "property": "score"
     71   },
     72   {
     73     "description": "medium, valuable word",
     74     "expected": 22,
     75     "input": {
     76       "word": "quirky"
     77     },
     78     "property": "score"
     79   },
     80   {
     81     "description": "long, mixed-case word",
     82     "expected": 41,
     83     "input": {
     84       "word": "OxyphenButazone"
     85     },
     86     "property": "score"
     87   },
     88   {
     89     "description": "english-like word",
     90     "expected": 8,
     91     "input": {
     92       "word": "pinata"
     93     },
     94     "property": "score"
     95   },
     96   {
     97     "description": "empty input",
     98     "expected": 0,
     99     "input": {
    100       "word": ""
    101     },
    102     "property": "score"
    103   },
    104   {
    105     "description": "entire alphabet available",
    106     "expected": 87,
    107     "input": {
    108       "word": "abcdefghijklmnopqrstuvwxyz"
    109     },
    110     "property": "score"
    111   }
    112 ]