Improve readability of test harness

This commit is contained in:
Felipe Sere
2016-03-11 12:59:46 +00:00
parent e48cc261a9
commit 3d5da67c8d
2 changed files with 19 additions and 6 deletions

View File

@@ -15,11 +15,9 @@ defmodule ASTMangler do
|> 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

View File

@@ -2,14 +2,29 @@ defmodule KoansHarnessTest do
use ExUnit.Case
test "Equalities" do
answers = [true, 1, 2, 1, :something]
answers = [true,
1,
2,
1,
:something]
assert all_pass?(Equalities, answers) == [:passed, :passed, :passed, :passed, :passed]
assert test_all(Equalities, answers) == :all_passed
end
def all_pass?(module, answers) do
def test_all(module, answers) do
module.all_koans
|> Enum.zip(answers)
|> Enum.map(fn({koan, answer}) -> Runner.run_koan(module, koan, [answer]) end)
|> run_all(module)
|> passed?
|> results
end
def run_all(pairs, module) do
Enum.map(pairs, fn ({koan, answer}) -> Runner.run_koan(module, koan, [answer]) end)
end
def passed?(answers), do: {Enum.all?(answers, fn(element) -> element == :passed end), answers}
def results({true, _}), do: :all_passed
def results({false, answers}), do: answers
end