Show how to test koans for Equalities

This commit is contained in:
Felipe Sere
2016-03-10 16:44:29 +00:00
parent 95c620129d
commit eb1da4b1fc
7 changed files with 24 additions and 48 deletions

View File

@@ -1,24 +0,0 @@
defmodule ASTMangler do
def expand([do: thing], replacement) do
[do: expand(thing, replacement)]
end
def expand({fun, context, args}, replacement) do
new_args = replace(args, replacement)
{fun, context, new_args}
end
def replace(args, b) do
args
|> Enum.find_index(fn(x) -> x == :__ end)
|> replace(args, b)
end
def replace(nil, [], _b), do: []
def replace(nil, [ast], b) do
[expand(ast,b)]
end
def replace(index, list, b) do
List.update_at(list, index, fn(_)-> b end)
end
end

View File

@@ -9,6 +9,7 @@ defmodule ASTMangler do
end
def expand(n, _), do: n
def replace(nil, _), do: nil
def replace(args, b) do
args
|> Enum.find_index(fn(x) -> x == :__ end)

View File

@@ -1,8 +1,7 @@
defmodule Koans do
defmacro koan(name, body) do
compiled_name = String.to_atom(name)
x = quote do: answer
mangled_body = ASTMangler.expand(body, x)
mangled_body = ASTMangler.expand(body, quote do: answer)
quote do
@koans unquote(compiled_name)
def unquote(compiled_name)(answer \\ :nothing) do

View File

@@ -40,13 +40,6 @@ defmodule Runner do
end
end
def test_single_koan(module, name, answer) do
case apply(module, name, [answer]) do
:ok -> :passed
error -> IO.inspect error
end
end
def run_koan(module, name) do
case apply(module, name, []) do
:ok -> :passed