-
Notifications
You must be signed in to change notification settings - Fork 1
/
integration_test.go
50 lines (37 loc) · 976 Bytes
/
integration_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
package ranges
// This file tests how different algorithms integrate together.
import "testing"
func TestChunksAsSlices(t *testing.T) {
t.Parallel()
input := []int{1, 2, 3, 4, 5}
chunks := Slice(Map(Chunks[int](SliceRange(input), 3), Slice[int]))
assertEqual(t, chunks, [][]int{{1, 2, 3}, {4, 5}})
}
func TestFlattenChunks(t *testing.T) {
t.Parallel()
input := []int{1, 2, 3, 4, 5}
chunkOutput := [][]int{}
chunkRange := Chunks[int](SliceRange(input), 3)
for !chunkRange.Empty() {
chunkOutput = append(chunkOutput, Slice(chunkRange.Front()))
chunkRange.PopFront()
}
assertEqual(t, chunkOutput, [][]int{{1, 2, 3}, {4, 5}})
combinedOutput := Slice(Flatten(Chunks[int](SliceRange(input), 3)))
assertEqual(t, combinedOutput, input)
}
func TestTakeCycleRepeat(t *testing.T) {
t.Parallel()
result := SliceF(
TakeF(
Cycle(
ChainF(
Only(1, 2, 3),
Repeat(4),
),
),
5,
),
)
assertEqual(t, result, []int{1, 2, 3, 4, 4})
}