-
Notifications
You must be signed in to change notification settings - Fork 1
/
slide_test.go
61 lines (50 loc) · 1.15 KB
/
slide_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
package ranges
import "testing"
func TestSlide(t *testing.T) {
t.Parallel()
assertEqual(
t,
SliceF(MapF(SlideStep(Iota(5), 3, 3), SliceF[int])),
[][]int{{0, 1, 2}, {3, 4}},
)
assertEqual(
t,
SliceF(MapF(Slide(Iota(5), 3), SliceF[int])),
[][]int{{0, 1, 2}, {1, 2, 3}, {2, 3, 4}},
)
assertEqual(
t,
SliceF(MapF(SlideStep(Iota(5), 3, 2), SliceF[int])),
[][]int{{0, 1, 2}, {2, 3, 4}},
)
assertEqual(
t,
SliceF(MapF(SlideStep(Iota(5), 2, 2), SliceF[int])),
[][]int{{0, 1}, {2, 3}},
)
}
func TestSlidePoppingAndSaving(t *testing.T) {
t.Parallel()
r := Slide(Iota(5), 3)
r2 := r.Save()
r.PopFront()
assertEqual(t, SliceF(r.Front()), []int{1, 2, 3})
assertEqual(t, SliceF(r2.Front()), []int{0, 1, 2})
}
func TestSlideS(t *testing.T) {
t.Parallel()
assertEqual(
t,
SliceF(MapF(SlideStepS([]int{0, 1, 2, 3, 4}, 3, 3), SliceF[int])),
[][]int{{0, 1, 2}, {3, 4}},
)
assertEqual(
t,
SliceF(MapF(SlideS([]int{0, 1, 2, 3, 4}, 3), SliceF[int])),
[][]int{{0, 1, 2}, {1, 2, 3}, {2, 3, 4}},
)
}
func TestSlideSizeZeroPanics(t *testing.T) {
t.Parallel()
assertPanic(t, "windowSize < 1 for Slide", func() { Slide(Null[int](), 0) })
}