-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathaccumulator_test.go
75 lines (72 loc) · 1.44 KB
/
accumulator_test.go
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
package hranoprovod
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestAccumulator_Add(t *testing.T) {
tests := []struct {
name string
caller func() Accumulator
want Accumulator
}{
{
"add positive number to the right register",
func() Accumulator {
acc := NewAccumulator()
acc.Add("test", 2.22)
return acc
},
Accumulator{
"test": AccValues{0, 2.22},
},
},
{
"accumulates positive number to the right register",
func() Accumulator {
acc := NewAccumulator()
acc.Add("test", 2.00)
acc.Add("test", 3.00)
return acc
},
Accumulator{
"test": AccValues{0, 5.00},
},
},
{
"adds negative number to the right register",
func() Accumulator {
acc := NewAccumulator()
acc.Add("test", -3.00)
acc.Add("test", 2.00)
return acc
},
Accumulator{
"test": AccValues{-3.00, 2.00},
},
},
{
"accumulates correctly to both registers",
func() Accumulator {
acc := NewAccumulator()
acc.Add("test", 1.00)
acc.Add("test", -1.00)
acc.Add("test2", 2.00)
acc.Add("test2", 2.00)
acc.Add("test2", -2.00)
acc.Add("test2", -2.00)
acc.Add("test3", 0)
return acc
},
Accumulator{
"test": AccValues{-1.00, 1.00},
"test2": AccValues{-4.00, 4.00},
"test3": AccValues{0, 0},
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
assert.Equal(t, tt.want, tt.caller())
})
}
}