-
Notifications
You must be signed in to change notification settings - Fork 0
/
none_test.go
54 lines (49 loc) · 1.12 KB
/
none_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
package slices_test
import (
"testing"
"github.com/dosadczuk/go-slices"
"github.com/google/go-cmp/cmp"
)
func TestNone(t *testing.T) {
tt := map[string]struct {
// input
values []int
predicate func(int) bool
// assert
want bool
}{
"empty slice": {
values: nil, // zero value
predicate: func(_ int) bool { return true },
want: true,
},
"empty slice and predicate is nil": {
values: nil, // zero value
predicate: nil,
want: true,
},
"slice with values and predicate is nil": {
values: []int{1, 2, 3, 4, 5},
predicate: nil,
want: false,
},
"slice with values matching predicate": {
values: []int{1, 2, 3, 4, 5},
predicate: func(val int) bool { return val%2 == 0 },
want: false,
},
"slice with values not matching predicate": {
values: []int{1, 2, 3, 4, 5},
predicate: func(val int) bool { return val < 0 },
want: true,
},
}
for name, tc := range tt {
t.Run(name, func(t *testing.T) {
have := slices.None(tc.values, tc.predicate)
if !cmp.Equal(tc.want, have) {
t.Error(cmp.Diff(tc.want, have))
}
})
}
}