-
Notifications
You must be signed in to change notification settings - Fork 0
/
filtermap_test.go
73 lines (64 loc) · 2.13 KB
/
filtermap_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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
package iterator
import (
"testing"
)
func TestTakeWhile(t *testing.T) {
cases := []struct {
iter Iterator[int]
pred func(int, int) (bool, error)
expected []int
}{
{Range(0, 5, 1), func(_, item int) (bool, error) { return item < 3, nil }, []int{0, 1, 2}},
{FromSlice([]int{0, 1, 2, 3, 0, 1, 2, 3}), func(_, item int) (bool, error) { return item < 3, nil }, []int{0, 1, 2}},
}
for i := range cases {
checkIteratorEqual(t, TakeWhile(cases[i].pred)(cases[i].iter), cases[i].expected)
}
}
func TestDropWhile(t *testing.T) {
cases := []struct {
iter Iterator[int]
pred func(int, int) (bool, error)
expected []int
}{
{Range(0, 5, 1), func(_, item int) (bool, error) { return item < 3, nil }, []int{3, 4, 5}},
{FromSlice([]int{0, 1, 2, 3, 0, 1, 2, 3, 4}), func(_, item int) (bool, error) { return item < 3, nil }, []int{3, 0, 1, 2, 3, 4}},
}
for i := range cases {
checkIteratorEqual(t, DropWhile(cases[i].pred)(cases[i].iter), cases[i].expected)
}
}
func TestSlice(t *testing.T) {
cases := []struct {
iter Iterator[int]
from, to, step int
expected []int
}{
{Range(0, 5, 1), 2, 5, 1, []int{2, 3, 4}},
{Range(0, 5, 1), 0, 6, 1, []int{0, 1, 2, 3, 4, 5}},
{Range(0, 5, 1), 0, 6, 2, []int{0, 2, 4}},
{Range(0, 5, 1), 0, -1, 1, []int{0, 1, 2, 3, 4, 5}},
{Range(0, 5, 1), 0, -1, 2, []int{0, 2, 4}},
{Range(0, 5, 1), 2, -1, 2, []int{2, 4}},
}
for i := range cases {
checkIteratorEqual(t, Slice[int](cases[i].from, cases[i].to, cases[i].step)(cases[i].iter), cases[i].expected)
}
}
func TestSplice(t *testing.T) {
cases := []struct {
iter Iterator[int]
from, to int
injected Iterator[int]
expected []int
}{
{Range(0, 5, 1), 2, 5, nil, []int{0, 1, 5}},
{Range(0, 5, 1), 2, 5, FromSlice([]int{0, 1}), []int{0, 1, 0, 1, 5}},
{Range(0, 5, 1), 2, 2, FromSlice([]int{0, 1}), []int{0, 1, 0, 1, 2, 3, 4, 5}},
{Range(0, 5, 1), 2, -1, FromSlice([]int{0, 1}), []int{0, 1, 0, 1}},
{Range(0, 5, 1), 0, -1, FromSlice([]int{0, 1}), []int{0, 1}},
}
for i := range cases {
checkIteratorEqual(t, Splice(cases[i].from, cases[i].to, cases[i].injected)(cases[i].iter), cases[i].expected)
}
}