From 1efda3e75dee42c560a7dab018c583357f1b0eec Mon Sep 17 00:00:00 2001 From: Moxley Stratton Date: Fri, 9 Feb 2018 16:04:53 -0800 Subject: [PATCH 1/3] 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 --- exercises/pig-latin/pig_latin_test.exs | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/exercises/pig-latin/pig_latin_test.exs b/exercises/pig-latin/pig_latin_test.exs index 5bb6c45d1d..bfdaeaae2e 100644 --- a/exercises/pig-latin/pig_latin_test.exs +++ b/exercises/pig-latin/pig_latin_test.exs @@ -63,7 +63,7 @@ defmodule PigLatinTest do @tag :pending test "word beginning with q without a following u" do - assert PigLatin.translate("qat") == "atqay" + assert PigLatin.translate("qatar") == "atarqay" end @tag :pending @@ -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" @@ -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 @@ -133,4 +143,3 @@ defmodule PigLatinTest do end end end - From 62b4be4e23903126126e0f377ebca6a99aed3ddc Mon Sep 17 00:00:00 2001 From: Moxley Stratton Date: Fri, 9 Feb 2018 16:22:45 -0800 Subject: [PATCH 2/3] Revert 'qat' test change --- exercises/pig-latin/pig_latin_test.exs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/exercises/pig-latin/pig_latin_test.exs b/exercises/pig-latin/pig_latin_test.exs index bfdaeaae2e..9034c528d2 100644 --- a/exercises/pig-latin/pig_latin_test.exs +++ b/exercises/pig-latin/pig_latin_test.exs @@ -63,7 +63,7 @@ defmodule PigLatinTest do @tag :pending test "word beginning with q without a following u" do - assert PigLatin.translate("qatar") == "atarqay" + assert PigLatin.translate("qat") == "atqay" end @tag :pending From d6c2dde81037d8f5feed062949fbc5afe7715355 Mon Sep 17 00:00:00 2001 From: Moxley Stratton Date: Mon, 12 Feb 2018 06:49:21 -0800 Subject: [PATCH 3/3] Make example.exs test pass --- exercises/pig-latin/example.exs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/exercises/pig-latin/example.exs b/exercises/pig-latin/example.exs index b0a670c9f4..d47f3083d0 100644 --- a/exercises/pig-latin/example.exs +++ b/exercises/pig-latin/example.exs @@ -32,7 +32,7 @@ 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].*)$/ @@ -40,4 +40,3 @@ defmodule PigLatin do end end end -