Merge pull request #84 from RabeaGleissner/new-pattern-matching-koan

Additions to pattern matching koans
This commit is contained in:
Uku Taht
2016-04-26 12:51:17 +01:00
2 changed files with 18 additions and 4 deletions

View File

@@ -7,7 +7,8 @@ defmodule PatternMatching do
koan "A pattern can change" do
a = 1
assert a = ___
a = 2
assert (a == 2) == ___
end
koan "A pattern can also be strict" do
@@ -65,7 +66,19 @@ defmodule PatternMatching do
assert make_noise(snake) == ___
end
koan "Errors are shaped differently than sucessful results" do
koan "And they will only run the code that matches the argument" do
name = fn
("duck") -> "Donald"
("mouse") -> "Mickey"
(_other) -> "I need a name!"
end
assert name.("mouse") == ___
assert name.("duck") == ___
assert name.("donkey") == ___
end
koan "Errors are shaped differently than successful results" do
dog = %{type: "dog"}
result = case Map.fetch(dog, :type) do

View File

@@ -5,7 +5,7 @@ defmodule PatternsTests do
test "Pattern Matching" do
answers = [
1,
2,
true,
1,
{:multiple, [1, [2,3,4]]},
[1,2,3,4],
@@ -13,7 +13,8 @@ defmodule PatternsTests do
"eggs, milk",
"Honda",
[1,2,3],
{:multiple, ["Meow", "Woof", "Eh?",]},
{:multiple, ["Meow", "Woof", "Eh?"]},
{:multiple, ["Mickey", "Donald", "I need a name!"]},
"dog",
"Max",
]