-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfilter_test.go
More file actions
40 lines (38 loc) · 820 Bytes
/
filter_test.go
File metadata and controls
40 lines (38 loc) · 820 Bytes
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
package arrayutil
import (
"reflect"
"testing"
)
func TestFilter(t *testing.T) {
type args struct {
arr interface{}
filterf FilterFunc
}
tests := []struct {
name string
args args
wantErr bool
want []interface{}
}{
{"Success", args{
arr: []int{1, 2, 3, 4},
filterf: func(entry interface{}) bool {
return entry == 1
}}, false, []interface{}{1}},
{"Failed", args{
arr: "[]int{1, 2, 3, 4}",
filterf: nil}, true, nil},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got, err := Filter(tt.args.arr, tt.args.filterf)
if (err != nil) != tt.wantErr {
t.Errorf("Filter() error = %v, wantErr %v", err, tt.wantErr)
return
}
if !reflect.DeepEqual(got, tt.want) {
t.Errorf("Filter() = %v, want %v", got, tt.want)
}
})
}
}