-
Notifications
You must be signed in to change notification settings - Fork 0
/
split_test.go
98 lines (87 loc) · 2.04 KB
/
split_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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
package iterator
import (
"testing"
)
func TestSplit(t *testing.T) {
cases := []struct {
iter Iterator[[]int]
expected [][]int
}{
{ToSlices(Split(0)(Empty[int]())), [][]int{}},
{ToSlices(Split(0)(FromSlice([]int{1, 2, 3, 1, 2, 3}))), [][]int{{1, 2, 3, 1, 2, 3}}},
{
ToSlices(
Split(3)(FromSlice([]int{1, 2, 3, 1, 2, 3})),
),
[][]int{{1, 2}, {1, 2}},
},
}
for i := range cases {
checkIteratorSliceEqual(t, cases[i].iter, cases[i].expected)
}
}
func TestSplitLeading(t *testing.T) {
cases := []struct {
iter Iterator[[]int]
expected [][]int
}{
{ToSlices(SplitLeading(0)(Empty[int]())), [][]int{}},
{
ToSlices(
SplitLeading(3)(FromSlice([]int{1, 2, 3, 1, 2, 3})),
),
[][]int{{1, 2, 3}, {1, 2, 3}},
},
}
for i := range cases {
checkIteratorSliceEqual(t, cases[i].iter, cases[i].expected)
}
}
func TestSplitTrailing(t *testing.T) {
cases := []struct {
iter Iterator[[]int]
expected [][]int
}{
{ToSlices(SplitLeading(0)(Empty[int]())), [][]int{}},
{
ToSlices(
SplitTrailing(3)(FromSlice([]int{1, 2, 3, 1, 2, 3})),
),
[][]int{{1, 2}, {3, 1, 2}, {3}},
},
}
for i := range cases {
checkIteratorSliceEqual(t, cases[i].iter, cases[i].expected)
}
}
func TestChunk(t *testing.T) {
cases := []struct {
iter Iterator[[]int]
expected [][]int
}{
{ToSlices(Chunk[int](0)(Empty[int]())), [][]int{}},
{ToSlices(Chunk[int](0)(FromSlice([]int{1, 2, 3, 1, 2, 3}))), [][]int{{1, 2, 3, 1, 2, 3}}},
{
ToSlices(
Chunk[int](3)(FromSlice([]int{1, 2, 3, 1, 2, 3})),
),
[][]int{{1, 2, 3}, {1, 2, 3}},
},
}
for i := range cases {
checkIteratorSliceEqual(t, cases[i].iter, cases[i].expected)
}
}
func TestRuns(t *testing.T) {
cases := []struct {
iter Iterator[int]
expected [][]int
}{
{Empty[int](), [][]int{}},
{FromSlice([]int{1, 2, 1, 2}), [][]int{{1}, {2}, {1}, {2}}},
{FromSlice([]int{1, 1, 2, 2, 3, 3}), [][]int{{1, 1}, {2, 2}, {3, 3}}},
}
for i := range cases {
checkIteratorSliceEqual(t, ToSlices(Runs(cases[i].iter)), cases[i].expected)
}
}