-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain_test.go
More file actions
84 lines (77 loc) · 1.46 KB
/
main_test.go
File metadata and controls
84 lines (77 loc) · 1.46 KB
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
77
78
79
80
81
82
83
84
package main_test
import (
"testing"
counter "github.com/dreamsofcode-io/counter"
)
func TestAddCounts(t *testing.T) {
testCases := []struct {
name string
inputA counter.Counts
inputB counter.Counts
wants counter.Counts
}{
{
name: "Adding two counts toghether",
inputA: counter.Counts{
Bytes: 1,
Words: 10,
Lines: 14,
},
inputB: counter.Counts{
Bytes: 3,
Words: 16,
Lines: 22,
},
wants: counter.Counts{
Bytes: 4,
Words: 26,
Lines: 36,
},
},
{
name: "Empty A value",
inputA: counter.Counts{},
inputB: counter.Counts{
Bytes: 10,
Words: 3,
Lines: 1,
},
wants: counter.Counts{
Bytes: 10,
Words: 3,
Lines: 1,
},
},
{
name: "Empty B value",
inputA: counter.Counts{},
inputB: counter.Counts{
Bytes: 17,
Words: 5,
Lines: 2,
},
wants: counter.Counts{
Bytes: 17,
Words: 5,
Lines: 2,
},
},
}
for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
res := counter.AddCounts(tc.inputA, tc.inputB)
if res.Bytes != tc.wants.Bytes {
t.Log("Bytes value incorrect: wanted:", tc.wants.Bytes, "got:", res.Bytes)
t.Fail()
}
if res.Words != tc.wants.Words {
t.Log("Words value incorrect: wanted:", tc.wants.Words, "got:", res.Words)
t.Fail()
}
if res.Lines != tc.wants.Lines {
t.Log("Lines value incorrect: wanted:", tc.wants.Lines, "got:", res.Lines)
t.Fail()
}
})
}
}