-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathany_all_none_test.go
More file actions
109 lines (106 loc) · 1.99 KB
/
Copy pathany_all_none_test.go
File metadata and controls
109 lines (106 loc) · 1.99 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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
package utils
import "testing"
func TestAny(t *testing.T) {
type args[T any] struct {
list []T
fn func(T) bool
}
type testCase[T any] struct {
name string
args args[T]
want bool
}
tests := []testCase[string]{
{
name: "empty",
args: struct {
list []string
fn func(string) bool
}{list: make([]string, 0), fn: fnTrue},
want: false,
},
{
name: "not empty",
args: struct {
list []string
fn func(string) bool
}{list: []string{"xd"}, fn: fnTrue},
want: true,
},
{
name: "not length 2",
args: struct {
list []string
fn func(string) bool
}{list: []string{"xdd"}, fn: fnLength2},
want: false,
},
{
name: "length 2",
args: struct {
list []string
fn func(string) bool
}{list: []string{"xdd", "xd"}, fn: fnLength2},
want: true,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := Any(tt.args.list, tt.args.fn); got != tt.want {
t.Errorf("Any() = %v, want %v", got, tt.want)
}
})
}
}
func TestAll(t *testing.T) {
type args[T any] struct {
list []T
fn func(T) bool
}
type testCase[T any] struct {
name string
args args[T]
want bool
}
tests := []testCase[string]{
{
name: "empty",
args: struct {
list []string
fn func(string) bool
}{list: make([]string, 0), fn: fnTrue},
want: true,
},
{
name: "not empty",
args: struct {
list []string
fn func(string) bool
}{list: []string{"xd"}, fn: fnTrue},
want: true,
},
{
name: "not empty false",
args: struct {
list []string
fn func(string) bool
}{list: []string{"xd"}, fn: fnFalse},
want: false,
},
{
name: "not length 2",
args: struct {
list []string
fn func(string) bool
}{list: []string{"xdd"}, fn: fnLength2},
want: false,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := All(tt.args.list, tt.args.fn); got != tt.want {
t.Errorf("All() = %v, want %v", got, tt.want)
}
})
}
}