-
Notifications
You must be signed in to change notification settings - Fork 2
/
count_test.go
52 lines (41 loc) · 993 Bytes
/
count_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
package iterium
import (
"github.com/stretchr/testify/assert"
"testing"
)
func TestCount(t *testing.T) {
count := Count(0, -1)
var storage []int
for i := 0; i <= 10; i++ {
next, err := count.Next()
assert.Nil(t, err)
storage = append(storage, next)
}
assert.Exactly(t, []int{0, -1, -2, -3, -4, -5, -6, -7, -8, -9, -10}, storage)
}
func TestCountInfinite(t *testing.T) {
count := Count(0, -2)
slice, err := count.Slice()
assert.ErrorIs(t, err, infiniteIteratorErr)
assert.Nil(t, slice)
}
func TestCountOneArg(t *testing.T) {
count := Count(1)
var storage []int
for i := 0; i <= 3; i++ {
next, err := count.Next()
assert.Nil(t, err)
storage = append(storage, next)
}
assert.Exactly(t, []int{1, 2, 3, 4}, storage)
}
func TestCountNoArgs(t *testing.T) {
count := Count[int]()
var storage []int
for i := 0; i <= 3; i++ {
next, err := count.Next()
assert.Nil(t, err)
storage = append(storage, next)
}
assert.Exactly(t, []int{0, 1, 2, 3}, storage)
}