From 8b3d33efb8de22324599e853bc0c024ee34063d6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A1s=20B=20Nagy?= <20251272+BNAndras@users.noreply.github.com> Date: Tue, 2 Jul 2024 17:32:13 -0700 Subject: [PATCH] Apply code review --- exercises/practice/pig-latin/.meta/example.jl | 12 +- exercises/practice/pig-latin/runtests.jl | 181 +++++++++--------- 2 files changed, 100 insertions(+), 93 deletions(-) diff --git a/exercises/practice/pig-latin/.meta/example.jl b/exercises/practice/pig-latin/.meta/example.jl index 8126f20c..71637c2b 100644 --- a/exercises/practice/pig-latin/.meta/example.jl +++ b/exercises/practice/pig-latin/.meta/example.jl @@ -1,17 +1,17 @@ function translate(phrase) words = split(phrase, " ") - fragments = map(translateFragment, words) + fragments = map(translatefragment, words) join(fragments, " ") end -vowelSound = r"^([aeiou]|xr|yt)" -consonantSound = r"^([^aeiou]+(?=y)|[^aeiou]?qu|[^aeiou]+)([a-z]+)" +vowelsound = r"^([aeiou]|xr|yt)" +consonantsound = r"^([^aeiou]+(?=y)|[^aeiou]?qu|[^aeiou]+)([a-z]+)" -function translateFragment(fragment) +function translatefragment(fragment) translated = fragment - if !occursin(vowelSound, fragment) - translated = replace(fragment, consonantSound => s"\g<2>\g<1>") + if !occursin(vowelsound, fragment) + translated = replace(fragment, consonantsound => s"\g<2>\g<1>") end translated * "ay" diff --git a/exercises/practice/pig-latin/runtests.jl b/exercises/practice/pig-latin/runtests.jl index a893c6d3..ce6b97ca 100644 --- a/exercises/practice/pig-latin/runtests.jl +++ b/exercises/practice/pig-latin/runtests.jl @@ -3,92 +3,99 @@ using Test include("pig-latin.jl") @testset verbose = true "tests" begin - @testset "word beginning with a" begin - @test translate("apple") == "appleay" - end - - @testset "word beginning with e" begin - @test translate("ear") == "earay" - end - - @testset "word beginning with i" begin - @test translate("igloo") == "iglooay" - end - - @testset "word beginning with o" begin - @test translate("object") == "objectay" - end - - @testset "word beginning with u" begin - @test translate("under") == "underay" - end - - @testset "word beginning with a vowel and followed by a qu" begin - @test translate("equal") == "equalay" - end - - @testset "word beginning with p" begin - @test translate("pig") == "igpay" - end - - @testset "word beginning with k" begin - @test translate("koala") == "oalakay" - end - - @testset "word beginning with x" begin - @test translate("xenon") == "enonxay" - end - - @testset "word beginning with q without a following u" begin - @test translate("qat") == "atqay" - end - - @testset "word beginning with ch" begin - @test translate("chair") == "airchay" - end - - @testset "word beginning with qu" begin - @test translate("queen") == "eenquay" - end - - @testset "word beginning with qu and a preceding consonant" begin - @test translate("square") == "aresquay" - end - - @testset "word beginning with th" begin - @test translate("therapy") == "erapythay" - end - - @testset "word beginning with thr" begin - @test translate("thrush") == "ushthray" - end - - @testset "word beginning with sch" begin - @test translate("school") == "oolschay" - end - - @testset "word beginning with yt" begin - @test translate("yttria") == "yttriaay" - end - - @testset "word beginning with xr" begin - @test translate("xray") == "xrayay" - end - - @testset "y is treated like a consonant at the beginning of a word" begin - @test translate("yellow") == "ellowyay" - end - - @testset "y is treated like a vowel at the end of a consonant cluster" begin - @test translate("rhythm") == "ythmrhay" - end - - @testset "y as second letter in two letter word" begin - @test translate("my") == "ymay" - end - - @testset "a whole phrase" begin - @test translate("quick fast run") == "ickquay astfay unray" + @testset "ay is added to words that begin with vowels" begin + @testset "word beginning with a" begin + @test translate("apple") == "appleay" + end + + @testset "word beginning with e" begin + @test translate("ear") == "earay" + end + + @testset "word beginning with i" begin + @test translate("igloo") == "iglooay" + end + + @testset "word beginning with o" begin + @test translate("object") == "objectay" + end + + @testset "word beginning with u" begin + @test translate("under") == "underay" + end + + @testset "word beginning with a vowel and followed by a qu" begin + @test translate("equal") == "equalay" + end + end + + @testset "some letter clusters are treated like a single consonant" begin + @testset "word beginning with p" begin + @test translate("pig") == "igpay" + end + + @testset "word beginning with k" begin + @test translate("koala") == "oalakay" + end + + @testset "word beginning with x" begin + @test translate("xenon") == "enonxay" + end + + @testset "word beginning with q without a following u" begin + @test translate("qat") == "atqay" + end + + @testset "word beginning with ch" begin + @test translate("chair") == "airchay" + end + + @testset "word beginning with qu" begin + @test translate("queen") == "eenquay" + end + + @testset "word beginning with qu and a preceding consonant" begin + @test translate("square") == "aresquay" + end + + @testset "word beginning with th" begin + @test translate("therapy") == "erapythay" + end + + @testset "word beginning with thr" begin + @test translate("thrush") == "ushthray" + end + + @testset "word beginning with sch" begin + @test translate("school") == "oolschay" + end + end + + @testset "some letter clusters are treated like a single vowel" begin + @testset "word beginning with yt" begin + @test translate("yttria") == "yttriaay" + end + + @testset "word beginning with xr" begin + @test translate("xray") == "xrayay" + end + + @testset "y is treated like a consonant at the beginning of a word" begin + @test translate("yellow") == "ellowyay" + end + + @testset "y is treated like a vowel at the end of a consonant cluster" begin + @test translate("rhythm") == "ythmrhay" + end + + @testset "y as second letter in two letter word" begin + @test translate("my") == "ymay" + end + end + + @testset "phrases are translated" begin + @testset "a whole phrase" begin + @test translate("quick fast run") == "ickquay astfay unray" + end end end -