-
Notifications
You must be signed in to change notification settings - Fork 0
/
find_test.go
49 lines (47 loc) · 954 Bytes
/
find_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
package slice
import (
"reflect"
"testing"
)
func TestFind(t *testing.T) {
type args struct {
values []int
fn func(v int) bool
}
tests := []struct {
name string
args args
wantV int
wantFound bool
}{
{
name: "find_int_should_succeed",
args: args{
values: []int{1, 2, 3, 4, 5},
fn: func(v int) bool { return v == 5 },
},
wantV: 5,
wantFound: true,
},
{
name: "find_int_should_failed",
args: args{
values: []int{1, 2, 3, 4, 5},
fn: func(v int) bool { return v == 6 },
},
wantV: 0,
wantFound: false,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
gotV, gotFound := Find(tt.args.values, tt.args.fn)
if !reflect.DeepEqual(gotV, tt.wantV) {
t.Errorf("Find() gotV = %v, want %v", gotV, tt.wantV)
}
if gotFound != tt.wantFound {
t.Errorf("Find() gotFound = %v, want %v", gotFound, tt.wantFound)
}
})
}
}