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