|
| 1 | +#!/usr/bin/env perl |
| 2 | +use Test2::V0; |
| 3 | +use JSON::PP; |
| 4 | + |
| 5 | +use FindBin qw($Bin); |
| 6 | +use lib $Bin, "$Bin/local/lib/perl5"; |
| 7 | + |
| 8 | +use PigLatin qw(translate); |
| 9 | + |
| 10 | +my $C_DATA = do { local $/; decode_json(<DATA>); }; |
| 11 | +plan 23; |
| 12 | + |
| 13 | +imported_ok qw(translate) or bail_out; |
| 14 | + |
| 15 | +for my $case ( map { @{ $_->{cases} } } @{ $C_DATA->{cases} } ) { |
| 16 | + is translate( $case->{input}{phrase} ), $case->{expected}, |
| 17 | + $case->{description}; |
| 18 | +} |
| 19 | + |
| 20 | +__DATA__ |
| 21 | +{ |
| 22 | + "exercise": "pig-latin", |
| 23 | + "version": "1.2.0", |
| 24 | + "cases": [ |
| 25 | + { |
| 26 | + "description": "ay is added to words that start with vowels", |
| 27 | + "cases": [ |
| 28 | + { |
| 29 | + "description": "word beginning with a", |
| 30 | + "property": "translate", |
| 31 | + "input": { |
| 32 | + "phrase": "apple" |
| 33 | + }, |
| 34 | + "expected": "appleay" |
| 35 | + }, |
| 36 | + { |
| 37 | + "description": "word beginning with e", |
| 38 | + "property": "translate", |
| 39 | + "input": { |
| 40 | + "phrase": "ear" |
| 41 | + }, |
| 42 | + "expected": "earay" |
| 43 | + }, |
| 44 | + { |
| 45 | + "description": "word beginning with i", |
| 46 | + "property": "translate", |
| 47 | + "input": { |
| 48 | + "phrase": "igloo" |
| 49 | + }, |
| 50 | + "expected": "iglooay" |
| 51 | + }, |
| 52 | + { |
| 53 | + "description": "word beginning with o", |
| 54 | + "property": "translate", |
| 55 | + "input": { |
| 56 | + "phrase": "object" |
| 57 | + }, |
| 58 | + "expected": "objectay" |
| 59 | + }, |
| 60 | + { |
| 61 | + "description": "word beginning with u", |
| 62 | + "property": "translate", |
| 63 | + "input": { |
| 64 | + "phrase": "under" |
| 65 | + }, |
| 66 | + "expected": "underay" |
| 67 | + }, |
| 68 | + { |
| 69 | + "description": "word beginning with a vowel and followed by a qu", |
| 70 | + "property": "translate", |
| 71 | + "input": { |
| 72 | + "phrase": "equal" |
| 73 | + }, |
| 74 | + "expected": "equalay" |
| 75 | + } |
| 76 | + ] |
| 77 | + }, |
| 78 | + { |
| 79 | + "description": "first letter and ay are moved to the end of words that start with consonants", |
| 80 | + "cases": [ |
| 81 | + { |
| 82 | + "description": "word beginning with p", |
| 83 | + "property": "translate", |
| 84 | + "input": { |
| 85 | + "phrase": "pig" |
| 86 | + }, |
| 87 | + "expected": "igpay" |
| 88 | + }, |
| 89 | + { |
| 90 | + "description": "word beginning with k", |
| 91 | + "property": "translate", |
| 92 | + "input": { |
| 93 | + "phrase": "koala" |
| 94 | + }, |
| 95 | + "expected": "oalakay" |
| 96 | + }, |
| 97 | + { |
| 98 | + "description": "word beginning with x", |
| 99 | + "property": "translate", |
| 100 | + "input": { |
| 101 | + "phrase": "xenon" |
| 102 | + }, |
| 103 | + "expected": "enonxay" |
| 104 | + }, |
| 105 | + { |
| 106 | + "description": "word beginning with q without a following u", |
| 107 | + "property": "translate", |
| 108 | + "input": { |
| 109 | + "phrase": "qat" |
| 110 | + }, |
| 111 | + "expected": "atqay" |
| 112 | + } |
| 113 | + ] |
| 114 | + }, |
| 115 | + { |
| 116 | + "description": "some letter clusters are treated like a single consonant", |
| 117 | + "cases": [ |
| 118 | + { |
| 119 | + "description": "word beginning with ch", |
| 120 | + "property": "translate", |
| 121 | + "input": { |
| 122 | + "phrase": "chair" |
| 123 | + }, |
| 124 | + "expected": "airchay" |
| 125 | + }, |
| 126 | + { |
| 127 | + "description": "word beginning with qu", |
| 128 | + "property": "translate", |
| 129 | + "input": { |
| 130 | + "phrase": "queen" |
| 131 | + }, |
| 132 | + "expected": "eenquay" |
| 133 | + }, |
| 134 | + { |
| 135 | + "description": "word beginning with qu and a preceding consonant", |
| 136 | + "property": "translate", |
| 137 | + "input": { |
| 138 | + "phrase": "square" |
| 139 | + }, |
| 140 | + "expected": "aresquay" |
| 141 | + }, |
| 142 | + { |
| 143 | + "description": "word beginning with th", |
| 144 | + "property": "translate", |
| 145 | + "input": { |
| 146 | + "phrase": "therapy" |
| 147 | + }, |
| 148 | + "expected": "erapythay" |
| 149 | + }, |
| 150 | + { |
| 151 | + "description": "word beginning with thr", |
| 152 | + "property": "translate", |
| 153 | + "input": { |
| 154 | + "phrase": "thrush" |
| 155 | + }, |
| 156 | + "expected": "ushthray" |
| 157 | + }, |
| 158 | + { |
| 159 | + "description": "word beginning with sch", |
| 160 | + "property": "translate", |
| 161 | + "input": { |
| 162 | + "phrase": "school" |
| 163 | + }, |
| 164 | + "expected": "oolschay" |
| 165 | + } |
| 166 | + ] |
| 167 | + }, |
| 168 | + { |
| 169 | + "description": "some letter clusters are treated like a single vowel", |
| 170 | + "cases": [ |
| 171 | + { |
| 172 | + "description": "word beginning with yt", |
| 173 | + "property": "translate", |
| 174 | + "input": { |
| 175 | + "phrase": "yttria" |
| 176 | + }, |
| 177 | + "expected": "yttriaay" |
| 178 | + }, |
| 179 | + { |
| 180 | + "description": "word beginning with xr", |
| 181 | + "property": "translate", |
| 182 | + "input": { |
| 183 | + "phrase": "xray" |
| 184 | + }, |
| 185 | + "expected": "xrayay" |
| 186 | + } |
| 187 | + ] |
| 188 | + }, |
| 189 | + { |
| 190 | + "description": "position of y in a word determines if it is a consonant or a vowel", |
| 191 | + "cases": [ |
| 192 | + { |
| 193 | + "description": "y is treated like a consonant at the beginning of a word", |
| 194 | + "property": "translate", |
| 195 | + "input": { |
| 196 | + "phrase": "yellow" |
| 197 | + }, |
| 198 | + "expected": "ellowyay" |
| 199 | + }, |
| 200 | + { |
| 201 | + "description": "y is treated like a vowel at the end of a consonant cluster", |
| 202 | + "property": "translate", |
| 203 | + "input": { |
| 204 | + "phrase": "rhythm" |
| 205 | + }, |
| 206 | + "expected": "ythmrhay" |
| 207 | + }, |
| 208 | + { |
| 209 | + "description": "y as second letter in two letter word", |
| 210 | + "property": "translate", |
| 211 | + "input": { |
| 212 | + "phrase": "my" |
| 213 | + }, |
| 214 | + "expected": "ymay" |
| 215 | + } |
| 216 | + ] |
| 217 | + }, |
| 218 | + { |
| 219 | + "description": "phrases are translated", |
| 220 | + "cases": [ |
| 221 | + { |
| 222 | + "description": "a whole phrase", |
| 223 | + "property": "translate", |
| 224 | + "input": { |
| 225 | + "phrase": "quick fast run" |
| 226 | + }, |
| 227 | + "expected": "ickquay astfay unray" |
| 228 | + } |
| 229 | + ] |
| 230 | + } |
| 231 | + ] |
| 232 | +} |
0 commit comments