Skip to content

Commit

Permalink
Apply code review
Browse files Browse the repository at this point in the history
  • Loading branch information
BNAndras committed Jul 3, 2024
1 parent 41bfbe5 commit 8b3d33e
Show file tree
Hide file tree
Showing 2 changed files with 100 additions and 93 deletions.
12 changes: 6 additions & 6 deletions exercises/practice/pig-latin/.meta/example.jl
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
181 changes: 94 additions & 87 deletions exercises/practice/pig-latin/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 8b3d33e

Please sign in to comment.