-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathslices_test.go
80 lines (76 loc) · 2.07 KB
/
slices_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
package pp
import (
"context"
"testing"
"github.com/stretchr/testify/require"
)
func TestDivideSliceInSize(t *testing.T) {
mockFactory := func() (*int, func(i int) Step) {
var count int
return &count, func(_ int) Step {
count++
return func(ctx context.Context) (err error) {
return nil
}
}
}
t.Run("empty", func(t *testing.T) {
count, empty := mockFactory()
steps := DivideSliceInSize([]int{}, 1, empty)
require.Empty(t, steps)
require.Equal(t, 0, *count)
})
t.Run("exact size", func(t *testing.T) {
count, empty := mockFactory()
steps := DivideSliceInSize([]int{1, 2, 3, 4}, 2, empty)
require.Len(t, steps, 2)
require.Equal(t, 4, *count)
})
t.Run("non matching size", func(t *testing.T) {
count, empty := mockFactory()
steps := DivideSliceInSize([]int{1, 2, 3, 4}, 3, empty)
require.Len(t, steps, 2)
require.Equal(t, 4, *count)
})
t.Run("size bigger than slice", func(t *testing.T) {
count, empty := mockFactory()
steps := DivideSliceInSize([]int{1, 2, 3, 4}, 5, empty)
require.Len(t, steps, 1)
require.Equal(t, 4, *count)
})
}
func TestDivideSliceInGroups(t *testing.T) {
mockFactory := func() (*int, func(i int) Step) {
var count int
return &count, func(_ int) Step {
count++
return func(ctx context.Context) (err error) {
return nil
}
}
}
t.Run("empty", func(t *testing.T) {
count, empty := mockFactory()
steps := DivideSliceInGroups([]int{}, 1, empty)
require.Empty(t, steps)
require.Equal(t, 0, *count)
})
t.Run("exact size", func(t *testing.T) {
count, empty := mockFactory()
steps := DivideSliceInGroups([]int{1, 2, 3, 4}, 2, empty)
require.Len(t, steps, 2)
require.Equal(t, 4, *count)
})
t.Run("non matching size", func(t *testing.T) {
count, empty := mockFactory()
steps := DivideSliceInGroups([]int{1, 2, 3, 4}, 3, empty)
require.Len(t, steps, 3)
require.Equal(t, 4, *count)
})
t.Run("size bigger than slice", func(t *testing.T) {
count, empty := mockFactory()
steps := DivideSliceInGroups([]int{1, 2, 3, 4}, 5, empty)
require.Len(t, steps, 4)
require.Equal(t, 4, *count)
})
}