-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdescribe.exs
76 lines (61 loc) · 1.65 KB
/
describe.exs
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#---
# Excerpted from "Programming Elixir 1.3",
# published by The Pragmatic Bookshelf.
# Copyrights apply to this code. It may not be used to create training material,
# courses, books, articles, and the like. Contact us if you are in doubt.
# We make no guarantees that this code is fit for any purpose.
# Visit http://www.pragmaticprogrammer.com/titles/elixir13 for more book information.
#---
ExUnit.start()
defmodule TestStats do
use ExUnit.Case
test "calculates sum" do
list = [1, 3, 5, 7, 9]
assert Stats.sum(list) == 25
end
test "calculates count" do
list = [1, 3, 5, 7, 9]
assert Stats.count(list) == 5
end
test "calculates average" do
list = [1, 3, 5, 7, 9]
assert Stats.average(list) == 5
end
end
defmodule TestStats0 do
use ExUnit.Case
describe "Stats on lists of ints" do
test "calculates sum" do
list = [1, 3, 5, 7, 9]
assert Stats.sum(list) == 25
end
test "calculates count" do
list = [1, 3, 5, 7, 9]
assert Stats.count(list) == 5
end
test "calculates average" do
list = [1, 3, 5, 7, 9]
assert Stats.average(list) == 5
end
end
end
defmodule TestStats1 do
use ExUnit.Case
describe "Stats on lists of ints" do
setup do
[ list: [1, 3, 5, 7, 9, 11],
sum: 36,
count: 6
]
end
test "calculates sum", fixture do
assert Stats.sum(fixture.list) == fixture.sum
end
test "calculates count", fixture do
assert Stats.count(fixture.list) == fixture.count
end
test "calculates average", fixture do
assert Stats.average(fixture.list) == fixture.sum / fixture.count
end
end
end