exercism-perl5

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

raindrops.t (3458B) - 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 Raindrops qw<raindrop>;
     10 
     11 my @test_cases = do { local $/; @{ JSON->decode(<DATA>) }; };
     12 plan 19;
     13 
     14 imported_ok qw<raindrop> or bail_out;
     15 
     16 for my $case (@test_cases) {
     17   is raindrop( $case->{input}{number} ), $case->{expected},
     18     $case->{description};
     19 }
     20 
     21 __DATA__
     22 [
     23   {
     24     "description": "the sound for 1 is 1",
     25     "expected": "1",
     26     "input": {
     27       "number": 1
     28     },
     29     "property": "convert"
     30   },
     31   {
     32     "description": "the sound for 3 is Pling",
     33     "expected": "Pling",
     34     "input": {
     35       "number": 3
     36     },
     37     "property": "convert"
     38   },
     39   {
     40     "description": "the sound for 5 is Plang",
     41     "expected": "Plang",
     42     "input": {
     43       "number": 5
     44     },
     45     "property": "convert"
     46   },
     47   {
     48     "description": "the sound for 7 is Plong",
     49     "expected": "Plong",
     50     "input": {
     51       "number": 7
     52     },
     53     "property": "convert"
     54   },
     55   {
     56     "description": "the sound for 6 is Pling as it has a factor 3",
     57     "expected": "Pling",
     58     "input": {
     59       "number": 6
     60     },
     61     "property": "convert"
     62   },
     63   {
     64     "description": "2 to the power 3 does not make a raindrop sound as 3 is the exponent not the base",
     65     "expected": "8",
     66     "input": {
     67       "number": 8
     68     },
     69     "property": "convert"
     70   },
     71   {
     72     "description": "the sound for 9 is Pling as it has a factor 3",
     73     "expected": "Pling",
     74     "input": {
     75       "number": 9
     76     },
     77     "property": "convert"
     78   },
     79   {
     80     "description": "the sound for 10 is Plang as it has a factor 5",
     81     "expected": "Plang",
     82     "input": {
     83       "number": 10
     84     },
     85     "property": "convert"
     86   },
     87   {
     88     "description": "the sound for 14 is Plong as it has a factor of 7",
     89     "expected": "Plong",
     90     "input": {
     91       "number": 14
     92     },
     93     "property": "convert"
     94   },
     95   {
     96     "description": "the sound for 15 is PlingPlang as it has factors 3 and 5",
     97     "expected": "PlingPlang",
     98     "input": {
     99       "number": 15
    100     },
    101     "property": "convert"
    102   },
    103   {
    104     "description": "the sound for 21 is PlingPlong as it has factors 3 and 7",
    105     "expected": "PlingPlong",
    106     "input": {
    107       "number": 21
    108     },
    109     "property": "convert"
    110   },
    111   {
    112     "description": "the sound for 25 is Plang as it has a factor 5",
    113     "expected": "Plang",
    114     "input": {
    115       "number": 25
    116     },
    117     "property": "convert"
    118   },
    119   {
    120     "description": "the sound for 27 is Pling as it has a factor 3",
    121     "expected": "Pling",
    122     "input": {
    123       "number": 27
    124     },
    125     "property": "convert"
    126   },
    127   {
    128     "description": "the sound for 35 is PlangPlong as it has factors 5 and 7",
    129     "expected": "PlangPlong",
    130     "input": {
    131       "number": 35
    132     },
    133     "property": "convert"
    134   },
    135   {
    136     "description": "the sound for 49 is Plong as it has a factor 7",
    137     "expected": "Plong",
    138     "input": {
    139       "number": 49
    140     },
    141     "property": "convert"
    142   },
    143   {
    144     "description": "the sound for 52 is 52",
    145     "expected": "52",
    146     "input": {
    147       "number": 52
    148     },
    149     "property": "convert"
    150   },
    151   {
    152     "description": "the sound for 105 is PlingPlangPlong as it has factors 3, 5 and 7",
    153     "expected": "PlingPlangPlong",
    154     "input": {
    155       "number": 105
    156     },
    157     "property": "convert"
    158   },
    159   {
    160     "description": "the sound for 3125 is Plang as it has a factor 5",
    161     "expected": "Plang",
    162     "input": {
    163       "number": 3125
    164     },
    165     "property": "convert"
    166   }
    167 ]