-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplan_test.go
68 lines (61 loc) · 1020 Bytes
/
plan_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
package malak
import (
"testing"
"github.com/stretchr/testify/require"
)
func TestCounter(t *testing.T) {
tt := []struct {
name string
amount int64
takeN int64
hasError bool
}{
{
name: "cannot take from an empty counter",
amount: 0,
takeN: 10,
hasError: true,
},
{
name: "cannot take more than avaialble",
amount: 10,
takeN: 11,
hasError: true,
},
{
name: "can take exact value",
amount: 10,
takeN: 10,
hasError: false,
},
{
name: "can take less value",
amount: 10,
takeN: 9,
hasError: false,
},
{
name: "zero take 1",
amount: 0,
takeN: 1,
hasError: true,
},
{
name: "zero take 0",
amount: 0,
takeN: 0,
hasError: true,
},
}
for _, tc := range tt {
t.Run(tc.name, func(t *testing.T) {
c := Counter(tc.amount)
err := c.TakeN(tc.takeN)
if tc.hasError {
require.Error(t, err)
return
}
require.NoError(t, err)
})
}
}