I was going though the exercises in http://elixirkoans.io and stumbled upon something odd. even if my code does solve the problem i don’t get a pass.
Exercise:
koan "Be careful, a message may be altered" do
assert String.replace("An awful day", "awful", "incredible") == String.replace("awful","awful","incredible", global: true)
end
Console response
Be careful, a message may be altered
Assertion failed in lib/koans/02_strings.ex:23
assert(String.replace("An awful day", "awful", "incredible") == String.replace("awful", "awful", "incredible", global: true))
left: "An incredible day"
right: "incredible"
Sorry, I don’t get it… Also I do not see any relationship between the code you show here and the code you linked…
I have to say though that I never did the koans beyond a certain point… Its not a way for me to learn…
But what I can tell is, that you create 2 strings "An incredible day" and "incredible" and assert for equality. As you clearly can see, those are not equal…
This is the full file and I get the pass after each exercise except this one
defmodule Strings do
use Koans
@intro "Strings"
koan "Strings are there to represent text" do
assert "hello" == "hello"
end
koan "Values may be inserted into strings by interpolation" do
assert "1 + 1 = #{1 + 1}" == "1 + 1 = #{1 + 1}"
end
koan "They can be put together" do
assert "hello world" == "hello" <> " " <> "world"
end
koan "Or pulled apart into a list when needed" do
assert ["hello", "world"] == String.split("hello world", " ")
end
koan "Be careful, a message may be altered" do
assert String.replace("An awful day", "awful", "incredible") == String.replace("awful","awful","incredible", global: true)
end
koan "But strings never lie about themselves" do
assert true == String.contains?("An incredible day", "day")
end
koan "Sometimes you want just the opposite of what is given" do
assert "banana" == String.reverse("ananab")
end
koan "Other times a little cleaning is in order" do
assert String.trim(" \n banana\n ") == "banana"
end
koan "Repetition is the mother of learning" do
assert String.duplicate("String", 3) == "StringStringString"
end
koan "Strings can be louder when necessary" do
assert String.upcase("listen") == "LISTEN"
end
end