From c00fb78decc28329c2d137e2339a938383c0048e Mon Sep 17 00:00:00 2001 From: Andrej Makarov Date: Fri, 10 Feb 2017 06:58:54 +0000 Subject: [PATCH] Add exercise: atbash-cipher --- config.json | 23 +++++++--- exercises/atbash-cipher/atbash-cipher.jl | 8 ++++ exercises/atbash-cipher/example.jl | 4 ++ exercises/atbash-cipher/runtests.jl | 56 ++++++++++++++++++++++++ 4 files changed, 84 insertions(+), 7 deletions(-) create mode 100644 exercises/atbash-cipher/atbash-cipher.jl create mode 100644 exercises/atbash-cipher/example.jl create mode 100644 exercises/atbash-cipher/runtests.jl diff --git a/config.json b/config.json index a2fb2689ca066..e807b4d7f151f 100644 --- a/config.json +++ b/config.json @@ -99,15 +99,24 @@ "arithmetics", "control-flow (conditionals)" ] + }, + { + "slug": "atbash-cipher", + "difficulty": 1, + "topics": [ + "strings", + "control-flow (conditionals)", + "control-flow (loops)" + ] }, { - "slug": "roman-numerals", - "difficulty": 1, - "topics": [ - "control-flow (loops)", - "strings", - "mathematics" - ] + "slug": "roman-numerals", + "difficulty": 1, + "topics": [ + "control-flow (loops)", + "strings", + "mathematics" + ] }, { "slug": "isogram", diff --git a/exercises/atbash-cipher/atbash-cipher.jl b/exercises/atbash-cipher/atbash-cipher.jl new file mode 100644 index 0000000000000..ca32629960adf --- /dev/null +++ b/exercises/atbash-cipher/atbash-cipher.jl @@ -0,0 +1,8 @@ +function encode(input::AbstractString) + +end + +function decode(input::AbstractString) + +end + diff --git a/exercises/atbash-cipher/example.jl b/exercises/atbash-cipher/example.jl new file mode 100644 index 0000000000000..ed98d7ee22288 --- /dev/null +++ b/exercises/atbash-cipher/example.jl @@ -0,0 +1,4 @@ +cipher(input::AbstractString) = map(x->isalpha(x)?Char(219-Int(x)):x, lowercase(filter(isalnum, input))) +encode(input::AbstractString) = join(matchall(r"(.{1,5})", cipher(input)), ' ') +decode(input::AbstractString) = cipher(input) + diff --git a/exercises/atbash-cipher/runtests.jl b/exercises/atbash-cipher/runtests.jl new file mode 100644 index 0000000000000..aa5da35d10dab --- /dev/null +++ b/exercises/atbash-cipher/runtests.jl @@ -0,0 +1,56 @@ +using Base.Test + +include("atbash-cipher.jl") + +@testset "encoding from English to atbash" begin + @testset "encode yes" begin + @test encode("yes") == "bvh" + end + + @testset "encode no" begin + @test encode("no") == "ml" + end + + @testset "encode OMG" begin + @test encode("OMG") == "lnt" + end + + @testset "encode spaces" begin + @test encode("O M G") == "lnt" + end + + @testset "encode mindblowingly" begin + @test encode("mindblowingly") == "nrmwy oldrm tob" + end + + @testset "encode numbers" begin + @test encode("Testing,1 2 3, testing.") == "gvhgr mt123 gvhgr mt" + end + + @testset "encode deep thought" begin + @test encode("Truth is fiction.") == "gifgs rhurx grlm" + end + + @testset "encode all the letters" begin + @test encode("The quick brown fox jumps over the lazy dog.") == "gsvjf rxpyi ldmul cqfnk hlevi gsvoz abwlt" + end +end + +@testset "decoding from atbash to English" begin + @testset "decode exercism" begin + @test decode("vcvix rhn") == "exercism" + end + + @testset "decode a sentence" begin + @test decode("zmlyh gzxov rhlug vmzhg vkkrm thglm v") == "anobstacleisoftenasteppingstone" + end + + @testset "decode numbers" begin + @test decode("gvhgr mt123 gvhgr mt") == "testing123testing" + end + + @testset "decode all the letters" begin + @test decode("gsvjf rxpyi ldmul cqfnk hlevi gsvoz abwlt") == "thequickbrownfoxjumpsoverthelazydog" + end +end +