Extract answers from arithmetic module
This commit is contained in:
@@ -2,53 +2,51 @@ defmodule Arithmetic do
|
|||||||
use Koans
|
use Koans
|
||||||
|
|
||||||
koan "it can add numbers" do
|
koan "it can add numbers" do
|
||||||
assert 3 + 4 == 7
|
assert 3 + :__ == 7
|
||||||
end
|
end
|
||||||
|
|
||||||
koan "it can substract numbers" do
|
koan "it can substract numbers" do
|
||||||
assert 7 - 4 == 3
|
assert 7 - 4 == :__
|
||||||
end
|
end
|
||||||
|
|
||||||
koan "it can multiply" do
|
koan "it can multiply" do
|
||||||
assert 3 * 4 == 12
|
assert 3 * 4 == :__
|
||||||
end
|
end
|
||||||
|
|
||||||
koan "floats and integers can be equal..." do
|
koan "floats and integers can be equal..." do
|
||||||
assert 3.0 == 3
|
assert 3.0 == :__
|
||||||
end
|
end
|
||||||
|
|
||||||
koan "..unless they are not precisely the same" do
|
koan "..unless they are not precisely the same" do
|
||||||
assert 3.2 != 3
|
assert 3.2 != :__
|
||||||
end
|
end
|
||||||
|
|
||||||
koan "it does floating point division" do
|
koan "it does floating point division" do
|
||||||
assert 5 / 2 == 2.5
|
assert 5 / 2 == :__
|
||||||
end
|
end
|
||||||
|
|
||||||
koan "it does integer division" do
|
koan "it does integer division" do
|
||||||
numerator = 5
|
numerator = 5
|
||||||
denominator = 2
|
denominator = 2
|
||||||
assert div(numerator, denominator) == 2
|
assert div(numerator, denominator) == :__
|
||||||
end
|
end
|
||||||
|
|
||||||
koan "it calculates the remainder of a division" do
|
koan "it calculates the remainder of a division" do
|
||||||
numerator = 5
|
numerator = 5
|
||||||
denominator = 2
|
denominator = 2
|
||||||
assert rem(numerator, denominator) == 1
|
assert rem(numerator, denominator) == :__
|
||||||
end
|
end
|
||||||
|
|
||||||
koan "it finds the maximum in a list" do
|
koan "it finds the maximum in a list" do
|
||||||
assert Enum.max([1,2,3,4]) == 4
|
assert Enum.max([1,2,3,4]) == :__
|
||||||
end
|
|
||||||
|
|
||||||
koan "it can compare numbers" do
|
|
||||||
assert 5 > 2
|
|
||||||
assert 5 >= 5
|
|
||||||
assert 3 < 7
|
|
||||||
assert 5 <= 5
|
|
||||||
end
|
end
|
||||||
|
|
||||||
koan "it finds the minimum in a list" do
|
koan "it finds the minimum in a list" do
|
||||||
assert Enum.min([1,2,3,4]) == 1
|
assert Enum.min([1,2,3,4]) == :__
|
||||||
end
|
end
|
||||||
|
|
||||||
|
koan "it can compare numbers" do
|
||||||
|
assert 5 > :__
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -97,6 +97,24 @@ defmodule KoansHarnessTest do
|
|||||||
test_all(Functions, answers)
|
test_all(Functions, answers)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
test "Arithmetic" do
|
||||||
|
answers = [
|
||||||
|
4,
|
||||||
|
3,
|
||||||
|
12,
|
||||||
|
3,
|
||||||
|
3,
|
||||||
|
2.5,
|
||||||
|
2,
|
||||||
|
1,
|
||||||
|
4,
|
||||||
|
1,
|
||||||
|
2
|
||||||
|
]
|
||||||
|
|
||||||
|
test_all(Arithmetic, answers)
|
||||||
|
end
|
||||||
|
|
||||||
def test_all(module, answers) do
|
def test_all(module, answers) do
|
||||||
module.all_koans
|
module.all_koans
|
||||||
|> Enum.zip(answers)
|
|> Enum.zip(answers)
|
||||||
|
|||||||
Reference in New Issue
Block a user