Skip to content

Commit

Permalink
Pig Latin: Added tests and improved test descriptions (exercism#390)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
moxley authored and devonestes committed Feb 12, 2018
1 parent 244b82d commit 74e2383
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
3 changes: 1 addition & 2 deletions exercises/pig-latin/example.exs
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,11 @@ defmodule PigLatin do
end

defp consonant_prefix_and_rest(word) do
if Regex.match?(~r/^yt|xr/, word) do
if Regex.match?(~r/^[yx][bcdfghjklmnpqrstvwxy]+/, word) do
["", word]
else
~r/^(s?qu|(?:[^aeiou]*))?([aeiou].*)$/
|> Regex.run(word, capture: :all_but_first)
end
end
end

17 changes: 13 additions & 4 deletions exercises/pig-latin/pig_latin_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ defmodule PigLatinTest do
end
end

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

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

@tag :pending
test "word beginning with y, followed by another consonant" do
assert PigLatin.translate("yddria") == "yddriaay"
end

@tag :pending
test "word beginning with xr" do
assert PigLatin.translate("xray") == "xrayay"
end

@tag :pending
test "word beginning with xb" do
assert PigLatin.translate("xbot") == "xbotay"
end
end

describe "phrases are translated" do
Expand All @@ -133,4 +143,3 @@ defmodule PigLatinTest do
end
end
end

0 comments on commit 74e2383

Please sign in to comment.