collapse two koans into one
This commit is contained in:
@@ -1,45 +1,30 @@
|
|||||||
defmodule Protocols do
|
defmodule Protocols do
|
||||||
use Koans
|
use Koans
|
||||||
|
|
||||||
defprotocol School do
|
@intro "Protocols"
|
||||||
def enrol(person)
|
|
||||||
end
|
|
||||||
|
|
||||||
defmodule Student do
|
defprotocol School, do: def enrol(person)
|
||||||
defstruct name: ""
|
|
||||||
end
|
|
||||||
|
|
||||||
|
defmodule Student, do: defstruct name: ""
|
||||||
|
defmodule Baker, do: defstruct name: ""
|
||||||
defmodule Dancer do
|
defmodule Dancer do
|
||||||
defstruct name: "", dance_style: ""
|
defstruct name: "", dance_style: ""
|
||||||
end
|
end
|
||||||
|
|
||||||
defmodule Baker do
|
|
||||||
defstruct name: ""
|
|
||||||
end
|
|
||||||
|
|
||||||
defimpl School, for: Student do
|
defimpl School, for: Student do
|
||||||
def enrol(student) do
|
def enrol(student), do: "#{student.name} enrolled at secondary school"
|
||||||
"#{student.name} enrolled at secondary school"
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
defimpl School, for: Dancer do
|
defimpl School, for: Dancer do
|
||||||
def enrol(dancer) do
|
def enrol(dancer), do: "#{dancer.name} enrolled for #{dancer.dance_style}"
|
||||||
"#{dancer.name} enrolled for #{dancer.dance_style}"
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
defmodule EveningSchool do end
|
|
||||||
|
|
||||||
koan "Sharing an interface is the secret at school" do
|
koan "Sharing an interface is the secret at school" do
|
||||||
student = %Student{name: "Emily"}
|
student = %Student{name: "Emily"}
|
||||||
assert School.enrol(student) == ___
|
|
||||||
end
|
|
||||||
|
|
||||||
koan "Dancers share but belong to a different school" do
|
|
||||||
dancer = %Dancer{name: "Darcy", dance_style: "ballet"}
|
dancer = %Dancer{name: "Darcy", dance_style: "ballet"}
|
||||||
assert School.enrol(dancer) == ___
|
|
||||||
|
|
||||||
|
assert School.enrol(student) == ___
|
||||||
|
assert School.enrol(dancer) == ___
|
||||||
end
|
end
|
||||||
|
|
||||||
koan "If you don't comply you can't get in" do
|
koan "If you don't comply you can't get in" do
|
||||||
|
|||||||
@@ -4,8 +4,7 @@ defmodule ProtocolsTests do
|
|||||||
|
|
||||||
test "Protocols" do
|
test "Protocols" do
|
||||||
answers = [
|
answers = [
|
||||||
"Emily enrolled at secondary school",
|
{:multiple, ["Emily enrolled at secondary school", "Darcy enrolled for ballet"]},
|
||||||
"Darcy enrolled for ballet",
|
|
||||||
Protocol.UndefinedError
|
Protocol.UndefinedError
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user