Skip to content

Commit 74e2383

Browse files
moxleydevonestes
authored andcommitted
Pig Latin: Added tests and improved test descriptions (exercism#390)
* Improved test descriptions Some test descriptions weren't doing a good job of communicating the rules of Pig Latin, leading to implementations that gamed the tests. For example, implementations were looking specifically for a leading 'yt' word as a vowel word, but not any other combination of 'y' and a consonant, like 'yd'. A couple tests are added to break the overly-specific implementations. The following implmentation passes the new version of the tests: http://exercism.io/submissions/2ec927894ece47baa8fe482f9f210a63 * Revert 'qat' test change * Make example.exs test pass
1 parent 244b82d commit 74e2383

File tree

2 files changed

+14
-6
lines changed

2 files changed

+14
-6
lines changed

exercises/pig-latin/example.exs

+1-2
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,11 @@ defmodule PigLatin do
3232
end
3333

3434
defp consonant_prefix_and_rest(word) do
35-
if Regex.match?(~r/^yt|xr/, word) do
35+
if Regex.match?(~r/^[yx][bcdfghjklmnpqrstvwxy]+/, word) do
3636
["", word]
3737
else
3838
~r/^(s?qu|(?:[^aeiou]*))?([aeiou].*)$/
3939
|> Regex.run(word, capture: :all_but_first)
4040
end
4141
end
4242
end
43-

exercises/pig-latin/pig_latin_test.exs

+13-4
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ defmodule PigLatinTest do
8282
end
8383
end
8484

85-
describe "some letter clusters are treated like a single consonant" do
85+
describe "consecutive consonants are treated like a single consonant" do
8686
@tag :pending
8787
test "word beginning with ch" do
8888
assert PigLatin.translate("chair") == "airchay"
@@ -114,16 +114,26 @@ defmodule PigLatinTest do
114114
end
115115
end
116116

117-
describe "some letter clusters are treated like a single vowel" do
117+
describe "'x' and 'y', when followed by a consonant, are treated like a vowel" do
118118
@tag :pending
119-
test "word beginning with yt" do
119+
test "word beginning with y, followed by a consonant" do
120120
assert PigLatin.translate("yttria") == "yttriaay"
121121
end
122122

123+
@tag :pending
124+
test "word beginning with y, followed by another consonant" do
125+
assert PigLatin.translate("yddria") == "yddriaay"
126+
end
127+
123128
@tag :pending
124129
test "word beginning with xr" do
125130
assert PigLatin.translate("xray") == "xrayay"
126131
end
132+
133+
@tag :pending
134+
test "word beginning with xb" do
135+
assert PigLatin.translate("xbot") == "xbotay"
136+
end
127137
end
128138

129139
describe "phrases are translated" do
@@ -133,4 +143,3 @@ defmodule PigLatinTest do
133143
end
134144
end
135145
end
136-

0 commit comments

Comments
 (0)