-
Notifications
You must be signed in to change notification settings - Fork 1
/
stride_test.go
59 lines (49 loc) · 1 KB
/
stride_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
package ranges
// Tests for stride rely slices.go, and iota.go.
import "testing"
func TestStride(t *testing.T) {
t.Parallel()
assertEqual(
t,
Slice(Stride[int](Iota(10), 1)),
SliceB(Iota(10)),
)
assertEqual(
t,
Slice(Stride[int](Iota(10), 3)),
[]int{0, 3, 6, 9},
)
}
func TestStrideF(t *testing.T) {
t.Parallel()
assertEqual(
t,
SliceF(StrideF(Iota(10), 1)),
SliceB(Iota(10)),
)
assertEqual(
t,
SliceF(StrideF(Iota(10), 3)),
[]int{0, 3, 6, 9},
)
}
func TestStrideS(t *testing.T) {
t.Parallel()
assertEmpty(t, StrideS([]int{}, 1))
assertEqual(
t,
SliceF(StrideS(SliceF(Iota(10)), 1)),
SliceB(Iota(10)),
)
assertEqual(
t,
SliceF(StrideS(SliceB(Iota(10)), 3)),
[]int{0, 3, 6, 9},
)
}
func TestStrideInvalidStepPanic(t *testing.T) {
t.Parallel()
assertPanic(t, "step < 1 for Stride", func() { Stride[int](Iota(0), 0) })
assertPanic(t, "step < 1 for Stride", func() { StrideF(Iota(0), 0) })
assertPanic(t, "step < 1 for Stride", func() { StrideS([]int{}, 0) })
}