Test multiple koans together

This commit is contained in:
Felipe Sere
2016-03-10 00:14:29 +00:00
parent fdb87b529f
commit 95c620129d
3 changed files with 30 additions and 3 deletions

25
lib/ast_mangler.ex Normal file
View File

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

View File

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