-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathexercise_2.54.exs
More file actions
30 lines (24 loc) · 905 Bytes
/
exercise_2.54.exs
File metadata and controls
30 lines (24 loc) · 905 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
defmodule Equality do
def equal?([], []), do: true
def equal?([head1 | tail1], [head2 | tail2]), do: equal?(head1, head2) && equal?(tail1, tail2)
def equal?(a, b) when is_atom(a) and is_atom(b), do: a == b
def equal?(_, _), do: false
end
ExUnit.start
defmodule EqualityTests do
use ExUnit.Case, async: true
test "empty lists are equal" do
assert Equality.equal?([], [])
end
test "single element lists are equal if the elements are equal" do
assert Equality.equal?([:a], [:a])
refute Equality.equal?([:a], [:b])
end
test "lists of unequal length are not equal" do
refute Equality.equal?(~w(foo bar baz bat)a, ~w(foo bar baz)a)
refute Equality.equal?(~w(foo bar baz bat)a, ~w(foo bar baz bat qux)a)
end
test "lists of equal length with matching elements are equal" do
assert Equality.equal?(~w(foo bar baz bat qux)a, ~w(foo bar baz bat qux)a)
end
end