exercism-perl5

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

atbash-cipher.t (3046B) - 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 AtbashCipher qw<encode_atbash decode_atbash>;
     10 
     11 my @test_cases = do { local $/; @{ JSON->decode(<DATA>) }; };
     12 plan 15;
     13 
     14 imported_ok qw<encode_atbash decode_atbash> or bail_out;
     15 
     16 for my $case (@test_cases) {
     17   is(
     18     $case->{property} eq 'encode'
     19     ? encode_atbash( $case->{input}{phrase} )
     20     : decode_atbash( $case->{input}{phrase} ),
     21     $case->{expected}, $case->{description}
     22   );
     23 }
     24 
     25 __DATA__
     26 [
     27   {
     28     "description": "encode: encode yes",
     29     "expected": "bvh",
     30     "input": {
     31       "phrase": "yes"
     32     },
     33     "property": "encode"
     34   },
     35   {
     36     "description": "encode: encode no",
     37     "expected": "ml",
     38     "input": {
     39       "phrase": "no"
     40     },
     41     "property": "encode"
     42   },
     43   {
     44     "description": "encode: encode OMG",
     45     "expected": "lnt",
     46     "input": {
     47       "phrase": "OMG"
     48     },
     49     "property": "encode"
     50   },
     51   {
     52     "description": "encode: encode spaces",
     53     "expected": "lnt",
     54     "input": {
     55       "phrase": "O M G"
     56     },
     57     "property": "encode"
     58   },
     59   {
     60     "description": "encode: encode mindblowingly",
     61     "expected": "nrmwy oldrm tob",
     62     "input": {
     63       "phrase": "mindblowingly"
     64     },
     65     "property": "encode"
     66   },
     67   {
     68     "description": "encode: encode numbers",
     69     "expected": "gvhgr mt123 gvhgr mt",
     70     "input": {
     71       "phrase": "Testing,1 2 3, testing."
     72     },
     73     "property": "encode"
     74   },
     75   {
     76     "description": "encode: encode deep thought",
     77     "expected": "gifgs rhurx grlm",
     78     "input": {
     79       "phrase": "Truth is fiction."
     80     },
     81     "property": "encode"
     82   },
     83   {
     84     "description": "encode: encode all the letters",
     85     "expected": "gsvjf rxpyi ldmul cqfnk hlevi gsvoz abwlt",
     86     "input": {
     87       "phrase": "The quick brown fox jumps over the lazy dog."
     88     },
     89     "property": "encode"
     90   },
     91   {
     92     "description": "decode: decode exercism",
     93     "expected": "exercism",
     94     "input": {
     95       "phrase": "vcvix rhn"
     96     },
     97     "property": "decode"
     98   },
     99   {
    100     "description": "decode: decode a sentence",
    101     "expected": "anobstacleisoftenasteppingstone",
    102     "input": {
    103       "phrase": "zmlyh gzxov rhlug vmzhg vkkrm thglm v"
    104     },
    105     "property": "decode"
    106   },
    107   {
    108     "description": "decode: decode numbers",
    109     "expected": "testing123testing",
    110     "input": {
    111       "phrase": "gvhgr mt123 gvhgr mt"
    112     },
    113     "property": "decode"
    114   },
    115   {
    116     "description": "decode: decode all the letters",
    117     "expected": "thequickbrownfoxjumpsoverthelazydog",
    118     "input": {
    119       "phrase": "gsvjf rxpyi ldmul cqfnk hlevi gsvoz abwlt"
    120     },
    121     "property": "decode"
    122   },
    123   {
    124     "description": "decode: decode with too many spaces",
    125     "expected": "exercism",
    126     "input": {
    127       "phrase": "vc vix    r hn"
    128     },
    129     "property": "decode"
    130   },
    131   {
    132     "description": "decode: decode with no spaces",
    133     "expected": "anobstacleisoftenasteppingstone",
    134     "input": {
    135       "phrase": "zmlyhgzxovrhlugvmzhgvkkrmthglmv"
    136     },
    137     "property": "decode"
    138   }
    139 ]