Extract answers for the String module
This commit is contained in:
@@ -2,38 +2,38 @@ defmodule Strings do
|
|||||||
use Koans
|
use Koans
|
||||||
|
|
||||||
koan "Strings are there to represent text" do
|
koan "Strings are there to represent text" do
|
||||||
assert "hello" == "hello"
|
assert "hello" == :__
|
||||||
end
|
end
|
||||||
|
|
||||||
koan "They can be put together" do
|
koan "They can be put together" do
|
||||||
assert "hello world" == "hello " <> "world"
|
assert "hello world" == :__ <> "world"
|
||||||
end
|
end
|
||||||
|
|
||||||
koan "Or pulled apart when needed" do
|
koan "Or pulled apart when needed" do
|
||||||
assert ["hello", "world"] == String.split("hello world")
|
assert :__ == String.split("hello world")
|
||||||
end
|
end
|
||||||
|
|
||||||
koan "Be careful, a message may be altered" do
|
koan "Be careful, a message may be altered" do
|
||||||
assert "An awful day" == String.replace("An incredible day", "incredible", "awful")
|
assert :__ == String.replace("An incredible day", "incredible", "awful")
|
||||||
end
|
end
|
||||||
|
|
||||||
koan "But strings never lie about themselves" do
|
koan "But strings never lie about themselves" do
|
||||||
assert true == String.contains?("An incredible day", "incredible")
|
assert true == String.contains?("An incredible day", :__)
|
||||||
end
|
end
|
||||||
|
|
||||||
koan "Sometimes you want just the opposite of what is given" do
|
koan "Sometimes you want just the opposite of what is given" do
|
||||||
assert "banana" == String.reverse("ananab")
|
assert :__ == String.reverse("ananab")
|
||||||
end
|
end
|
||||||
|
|
||||||
koan "Other times a little cleaning is in order" do
|
koan "Other times a little cleaning is in order" do
|
||||||
assert "banana" == String.strip(" \n banana\n ")
|
assert :__ == String.strip(" \n banana\n ")
|
||||||
end
|
end
|
||||||
|
|
||||||
koan "Repetition is the mother of learning" do
|
koan "Repetition is the mother of learning" do
|
||||||
assert "StringStringString" == String.duplicate("String", 3)
|
assert "StringStringString" == String.duplicate(:__, 3)
|
||||||
end
|
end
|
||||||
|
|
||||||
koan "Strings can be louder when necessary" do
|
koan "Strings can be louder when necessary" do
|
||||||
assert "LISTEN" == String.upcase("listen")
|
assert "LISTEN" == String.upcase(:__)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -55,6 +55,22 @@ defmodule KoansHarnessTest do
|
|||||||
test_all(Maps, answers)
|
test_all(Maps, answers)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
test "String" do
|
||||||
|
answers = [
|
||||||
|
"hello",
|
||||||
|
"hello ",
|
||||||
|
["hello", "world"],
|
||||||
|
"An awful day",
|
||||||
|
"incredible",
|
||||||
|
"banana",
|
||||||
|
"banana",
|
||||||
|
"String",
|
||||||
|
"listen"
|
||||||
|
]
|
||||||
|
|
||||||
|
test_all(Strings, answers)
|
||||||
|
end
|
||||||
|
|
||||||
def test_all(module, answers) do
|
def test_all(module, answers) do
|
||||||
module.all_koans
|
module.all_koans
|
||||||
|> Enum.zip(answers)
|
|> Enum.zip(answers)
|
||||||
|
|||||||
Reference in New Issue
Block a user