Skip to content

Commit ad5b486

Browse files
committed
Merge pull request #74 from ukutaht/split-test-harness
Create a test file for each of the koan modules
2 parents 4c5009c + b147948 commit ad5b486

14 files changed

+250
-215
lines changed

lib/koans/07_pattern_matching.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,8 @@ defmodule PatternMatching do
5656
def make_noise(_anything), do: "Eh?"
5757

5858
koan "Functions can declare what kind of arguments they accept" do
59-
dog = %{type: "dog"}
6059
cat = %{type: "cat"}
60+
dog = %{type: "dog"}
6161
snake = %{type: "snake"}
6262

6363
assert make_noise(cat) == ___

test/koans/enum_koans_test.exs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
defmodule EnumTests do
2+
use ExUnit.Case
3+
use TestHarness
4+
5+
test "Enums" do
6+
answers = [
7+
3,
8+
2,
9+
{:multiple, [true, false]},
10+
{:multiple, [true, false]},
11+
{:multiple, [true, false]},
12+
[10,20,30],
13+
[1,3],
14+
[2],
15+
[1,2,3],
16+
[1,2,3,4,5],
17+
[1,2,3],
18+
[{1, :a}, {2, :b}, {3, :c}],
19+
2,
20+
nil,
21+
:no_such_element,
22+
6
23+
]
24+
25+
test_all(Enums, answers)
26+
end
27+
end

test/koans/equalities_koan_test.exs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
defmodule EqualitiesTests do
2+
use ExUnit.Case
3+
use TestHarness
4+
5+
test "Equalities" do
6+
answers = [
7+
true,
8+
false,
9+
1,
10+
2,
11+
1,
12+
4,
13+
2
14+
]
15+
16+
test_all(Equalities, answers)
17+
end
18+
end

test/koans/functions_koans_test.exs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
defmodule FunctionsTests do
2+
use ExUnit.Case
3+
use TestHarness
4+
5+
test "Functions" do
6+
answers = [
7+
"Hello, World!",
8+
3,
9+
{:multiple, ["One and Two", "Only One"]},
10+
{:multiple, ["Hello Hello Hello Hello Hello ","Hello Hello "]},
11+
{:multiple, [:entire_list, :single_thing]},
12+
{:multiple, ["10 is bigger than 5", "4 is not bigger than 27"]},
13+
{:multiple, ["It was zero", "The length was 5"]},
14+
6,
15+
6,
16+
100,
17+
"Full Name"
18+
]
19+
20+
test_all(Functions, answers)
21+
end
22+
end

test/koans/lists_koans_test.exs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
defmodule ListsTests do
2+
use ExUnit.Case
3+
use TestHarness
4+
5+
test "Lists" do
6+
answers = [1,
7+
3,
8+
[1, 2, :a, "b"],
9+
[1,2],
10+
[1,2,3],
11+
[1,3],
12+
["life", "life", "life"],
13+
[1, 2, 3, 4, 5],
14+
[1, 4, 2, 3],
15+
[10, 2, 3],
16+
[1, 2, 3],
17+
[1, 2, 3, 4],
18+
[1, 2, 3, 4],
19+
{1, 2, 3},
20+
["value"],
21+
]
22+
23+
test_all(Lists, answers)
24+
end
25+
end

test/koans/maps_koans_test.exs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
defmodule MapsTests do
2+
use ExUnit.Case
3+
use TestHarness
4+
5+
test "Maps" do
6+
answers = [
7+
"Jon",
8+
{:multiple, [[:age, :last_name, :name], [27, "Jon", "Snow"]]},
9+
{:ok, 27},
10+
:error,
11+
{:ok, "Kayaking"},
12+
{:ok, 37},
13+
{:ok, 16},
14+
[:last_name, :name],
15+
%{:name => "Jon", :last_name => "Snow"},
16+
{:ok, "Baratheon"},
17+
%{ :name => "Jon", :last_name => "Snow"}
18+
]
19+
20+
test_all(Maps, answers)
21+
end
22+
end

test/koans/patterns_koans_test.exs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
defmodule PatternsTests do
2+
use ExUnit.Case
3+
use TestHarness
4+
5+
test "Pattern Matching" do
6+
answers = [
7+
1,
8+
2,
9+
1,
10+
{:multiple, [1, [2,3,4]]},
11+
[1,2,3,4],
12+
3,
13+
"eggs, milk",
14+
"Honda",
15+
[1,2,3],
16+
{:multiple, ["Meow", "Woof", "Eh?",]},
17+
"dog",
18+
"Max"
19+
]
20+
21+
test_all(PatternMatching, answers)
22+
end
23+
end

test/koans/processes_koans_test.exs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
defmodule ProcessesTests do
2+
use ExUnit.Case
3+
use TestHarness
4+
5+
test "Processes" do
6+
answers = [
7+
true,
8+
:running,
9+
"hola!",
10+
:how_are_you?,
11+
{:waited_too_long, "I am inpatient"},
12+
false,
13+
{:multiple, [true, false]},
14+
{:exited, :random_reason},
15+
true,
16+
false,
17+
{:exited, :normal},
18+
{:exited, :normal}
19+
]
20+
21+
test_all(Processes, answers)
22+
end
23+
end

test/koans/strings_koan_test.exs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
defmodule StringTests do
2+
use ExUnit.Case
3+
use TestHarness
4+
5+
test "Strings" do
6+
answers = [
7+
"hello",
8+
"hello ",
9+
"hello world",
10+
"An incredible day",
11+
"incredible",
12+
"banana",
13+
"banana",
14+
"String",
15+
"listen"
16+
]
17+
18+
test_all(Strings, answers)
19+
end
20+
end

test/koans/structs_koans_test.exs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
defmodule StructsTests do
2+
use ExUnit.Case
3+
use TestHarness
4+
5+
test "Structs" do
6+
answers = [
7+
%Structs.Person{},
8+
nil,
9+
"Joe",
10+
33,
11+
{:multiple, [true, false]},
12+
22,
13+
]
14+
15+
test_all(Structs, answers)
16+
end
17+
end

test/koans/tasks_koans_test.exs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
defmodule TasksTests do
2+
use ExUnit.Case
3+
use TestHarness
4+
5+
test "Tasks" do
6+
answers = [
7+
10,
8+
:ok,
9+
nil,
10+
false,
11+
9,
12+
[1,4,9,16]
13+
]
14+
15+
test_all(Tasks, answers)
16+
end
17+
end

test/koans/tuples_koans_test.exs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
defmodule TupleTests do
2+
use ExUnit.Case
3+
use TestHarness
4+
5+
test "Tuples" do
6+
answers = [
7+
{:a, 1, "hi"},
8+
3,
9+
"hi",
10+
{:a, "bye"},
11+
{:a, :new_thing, "hi"},
12+
{"Huey", "Dewey", "Louie"},
13+
{:this, :is, :awesome},
14+
[:this, :can, :be, :a, :list]
15+
]
16+
17+
test_all(Tuples, answers)
18+
end
19+
end

0 commit comments

Comments
 (0)