Make sure blank is on the right and improve koans
This commit is contained in:
@@ -10,11 +10,11 @@ defmodule Strings do
|
||||
end
|
||||
|
||||
koan "Or pulled apart when needed" do
|
||||
assert ___ == String.split("hello world")
|
||||
assert ["hello", "world"] == String.split(___, " ")
|
||||
end
|
||||
|
||||
koan "Be careful, a message may be altered" do
|
||||
assert ___ == String.replace("An awful day", "awful", "incredible")
|
||||
assert String.replace("An awful day", "awful", "incredible") == ___
|
||||
end
|
||||
|
||||
koan "But strings never lie about themselves" do
|
||||
@@ -26,7 +26,7 @@ defmodule Strings do
|
||||
end
|
||||
|
||||
koan "Other times a little cleaning is in order" do
|
||||
assert ___ == String.strip(" \n banana\n ")
|
||||
assert String.strip(" \n banana\n ") == ___
|
||||
end
|
||||
|
||||
koan "Repetition is the mother of learning" do
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
defmodule Tuples do
|
||||
use Koans
|
||||
|
||||
koan "Tuples have a size" do
|
||||
assert tuple_size({:a, :b, :c}) == ___
|
||||
end
|
||||
|
||||
koan "Tuples can contain different things" do
|
||||
assert {:a, 1, "hi"} == ___
|
||||
end
|
||||
|
||||
koan "Tuples have a size" do
|
||||
assert tuple_size({:a, :b, :c}) == ___
|
||||
end
|
||||
|
||||
koan "You can pull out individual elements" do
|
||||
assert elem({:a, "hi"}, 1) == ___
|
||||
end
|
||||
|
||||
@@ -33,10 +33,6 @@ defmodule Lists do
|
||||
assert List.flatten([1, [2, 3], 4, [5]]) == ___
|
||||
end
|
||||
|
||||
koan "Same rules apply to new members that arrive late" do
|
||||
assert List.flatten([1, [2, 3]], [4]) == ___
|
||||
end
|
||||
|
||||
koan "Order can also be specified for new members" do
|
||||
assert List.insert_at([1, 2, 3], 1, 4) == ___
|
||||
end
|
||||
@@ -45,7 +41,7 @@ defmodule Lists do
|
||||
assert List.replace_at([1, 2, 3], 0, 10) == ___
|
||||
end
|
||||
|
||||
koan "Replacing something which is not" do
|
||||
koan "When a replacement cannot be found, the list remains the same" do
|
||||
assert List.replace_at([1, 2, 3], 10, 0) == ___
|
||||
end
|
||||
|
||||
@@ -62,10 +58,6 @@ defmodule Lists do
|
||||
end
|
||||
|
||||
koan "Wrapping other values is a handy option" do
|
||||
assert List.wrap("value") == :___
|
||||
end
|
||||
|
||||
koan "Zipping can be a useful operation" do
|
||||
assert List.zip([[1, 2], [3, 4], [5, 6]]) == :___
|
||||
assert List.wrap("value") == ___
|
||||
end
|
||||
end
|
||||
|
||||
@@ -10,7 +10,7 @@ defmodule Structs do
|
||||
assert person == ___
|
||||
end
|
||||
|
||||
koan "You can access the fields of a struct" do
|
||||
koan "Unless previously defined, fields begin as nil" do
|
||||
nobody = %Person{}
|
||||
assert nobody.age == ___
|
||||
end
|
||||
@@ -26,17 +26,6 @@ defmodule Structs do
|
||||
assert older.age == ___
|
||||
end
|
||||
|
||||
koan "The original struct is not affected by updates" do
|
||||
joe = %Person{name: "Joe", age: 23}
|
||||
assert %{ joe | age: joe.age + 10}.age == ___
|
||||
assert joe.age == ___
|
||||
end
|
||||
|
||||
koan "You can pattern match into the fields of a struct" do
|
||||
%Person{age: age} = %Person{age: 22, name: "Silvia"}
|
||||
assert age == ___
|
||||
end
|
||||
|
||||
defmodule Plane do
|
||||
defstruct passengers: 0, maker: :boeing
|
||||
end
|
||||
@@ -49,7 +38,7 @@ defmodule Structs do
|
||||
assert plane?(%Person{}) == ___
|
||||
end
|
||||
|
||||
koan "Are basically maps" do
|
||||
koan "Struct can be treated like maps" do
|
||||
silvia = %Person{age: 22, name: "Silvia"}
|
||||
|
||||
assert Map.fetch!(silvia, :age) == ___
|
||||
|
||||
@@ -56,21 +56,32 @@ defmodule PatternMatching do
|
||||
def make_noise(_anything), do: "Eh?"
|
||||
|
||||
koan "Functions can declare what kind of arguments they accept" do
|
||||
dog = %{type: "dog", legs: 4, age: 9, color: "brown"}
|
||||
cat = %{type: "cat", legs: 4, age: 3, color: "grey"}
|
||||
snake = %{type: "snake", legs: 0, age: 20, color: "black"}
|
||||
dog = %{type: "dog"}
|
||||
cat = %{type: "cat"}
|
||||
snake = %{type: "snake"}
|
||||
|
||||
assert make_noise(dog) == ___
|
||||
assert make_noise(cat) == ___
|
||||
assert make_noise(dog) == ___
|
||||
assert make_noise(snake) == ___
|
||||
end
|
||||
|
||||
koan "Errors are shaped differently than sucessful results" do
|
||||
result = case Map.fetch(%{}, :obviously_not_a_key) do
|
||||
dog = %{type: "dog"}
|
||||
|
||||
result = case Map.fetch(dog, :type) do
|
||||
{:ok, value} -> value
|
||||
:error -> "not present"
|
||||
_ -> flunk("I should not happen")
|
||||
end
|
||||
|
||||
assert result == ___
|
||||
end
|
||||
|
||||
defmodule Animal do
|
||||
defstruct [:kind, :name]
|
||||
end
|
||||
|
||||
koan "You can pattern match into the fields of a struct" do
|
||||
%Animal{name: name} = %Animal{kind: "dog", name: "Max"}
|
||||
assert name == ___
|
||||
end
|
||||
end
|
||||
|
||||
@@ -11,7 +11,7 @@ defmodule Functions do
|
||||
|
||||
def multiply(a, b), do: a * b
|
||||
koan "Single line functions are cool, but mind the comma and the colon!" do
|
||||
assert multiply(2, ___) == 6
|
||||
assert 6 == multiply(2, ___)
|
||||
end
|
||||
|
||||
def first(foo, bar), do: "#{foo} and #{bar}"
|
||||
|
||||
@@ -6,7 +6,7 @@ defmodule Enums do
|
||||
end
|
||||
|
||||
koan "Depending on the type, it counts pairs" do
|
||||
assert Enum.count(%{ :a => :foo, :b => :bar}) == ___
|
||||
assert Enum.count(%{ a: :foo, b: :bar}) == ___
|
||||
end
|
||||
|
||||
def less_than_five?(n), do: n < 5
|
||||
|
||||
@@ -30,9 +30,8 @@ defmodule Processes do
|
||||
koan "Waiting for a message can get boring" do
|
||||
parent = self()
|
||||
spawn(fn -> receive do
|
||||
_anything -> flunk "I really wasn't expecting messages"
|
||||
after
|
||||
10 -> send parent, {:waited_too_long, "I am impatient"}
|
||||
5 -> send parent, {:waited_too_long, "I am impatient"}
|
||||
end
|
||||
end)
|
||||
|
||||
|
||||
@@ -25,7 +25,9 @@ defmodule Tasks do
|
||||
:timer.sleep(100)
|
||||
3 * 3
|
||||
end)
|
||||
assert Task.shutdown(handle) == ___
|
||||
%Task{pid: pid} = handle
|
||||
Task.shutdown(handle)
|
||||
assert Process.alive?(pid) == ___
|
||||
end
|
||||
|
||||
koan "Shutdown will give you an answer if it has it" do
|
||||
|
||||
@@ -27,10 +27,10 @@ defmodule Agents do
|
||||
end
|
||||
|
||||
koan "Somebody has to switch off the light at the end of the day" do
|
||||
Agent.start_link(fn() -> ["Milk"] end, name: __MODULE__)
|
||||
{:ok, pid} = Agent.start_link(fn() -> ["Milk"] end, name: __MODULE__)
|
||||
|
||||
result = Agent.stop(__MODULE__)
|
||||
Agent.stop(__MODULE__)
|
||||
|
||||
assert result == ___
|
||||
assert Process.alive?(pid) == ___
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user