-
Notifications
You must be signed in to change notification settings - Fork 0
/
filter_test.go
54 lines (49 loc) · 921 Bytes
/
filter_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 gotil_test
import (
"fmt"
"reflect"
"testing"
"github.com/gotilty/gotil"
)
func TestFilterBy(t *testing.T) {
input := []user{
{
name: "Micheal",
age: 27,
},
{
name: "Joe",
age: 30,
},
{
name: "Olivia",
age: 42,
},
}
expected := []user{
{
name: "Olivia",
age: 42,
},
}
result := gotil.FilterBy(input, func(v user, i int) bool {
return v.name == "Olivia"
})
if !reflect.DeepEqual(expected, result) {
t.Errorf("FindLastBy does not works expected\ncase: %v\nexpected: %v taken: %v", input, expected, result)
}
}
func BenchmarkFilterBy(b *testing.B) {
for n := 0; n < b.N; n++ {
_ = gotil.FilterBy([]int64{-100, -5, 30, 100}, func(v int64, i int) bool {
return v > 0
})
}
}
func ExampleFilterBy() {
result := gotil.FilterBy([]int64{-100, -5, 30, 100}, func(v int64, i int) bool {
return v > 0
})
fmt.Println(result)
// Output: [30 100]
}