-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathfilter_test.go
57 lines (39 loc) · 1.06 KB
/
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
55
56
57
package ranges
import "testing"
func TestFilter(t *testing.T) {
t.Parallel()
r := Only(1, 2, 3, 4)
sliceCopy := Slice(Filter[int](r, func(element int) bool { return element%2 == 0 }))
assertEqual(t, sliceCopy, []int{2, 4})
}
func TestFilterIsLazy(t *testing.T) {
t.Parallel()
// This will panic if it's not lazy.
Filter[int](nil, nil)
}
func TestFilterS(t *testing.T) {
t.Parallel()
r := FilterS([]int{1, 2, 3, 4}, func(element int) bool { return element%2 == 0 })
assertEqual(t, SliceF(r), []int{2, 4})
}
func TestFilterB(t *testing.T) {
t.Parallel()
r := Only(1, 2, 3, 4)
fr := FilterB(r, func(element int) bool { return element%2 == 0 })
fr2 := fr.SaveB()
fr.PopFront()
fr.PopFront()
assertEmpty(t, fr)
assertHasFront(t, fr2, 2)
assertHasBack(t, fr2, 4)
fr2.PopBack()
assertHasFront(t, fr2, 2)
assertHasBack(t, fr2, 2)
fr2.PopFront()
assertEmpty(t, fr2)
}
func TestFilterSB(t *testing.T) {
t.Parallel()
r := FilterSB([]int{1, 2, 3, 4}, func(element int) bool { return element%2 == 0 })
assertEqual(t, SliceB(Retro(r)), []int{4, 2})
}