This commit is contained in:
parent
cdaa1c8abb
commit
31c6b125c9
2 changed files with 72 additions and 0 deletions
52
moslice/batch_test.go
Normal file
52
moslice/batch_test.go
Normal file
|
|
@ -0,0 +1,52 @@
|
|||
package moslice
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestBatch(t *testing.T) {
|
||||
t.Run("empty slice", func(t *testing.T) {
|
||||
result := Batch([]int{}, 3)
|
||||
assert.Nil(t, result)
|
||||
})
|
||||
|
||||
t.Run("zero or negative size", func(t *testing.T) {
|
||||
result := Batch([]int{1, 2, 3}, 0)
|
||||
assert.Nil(t, result)
|
||||
|
||||
result = Batch([]int{1, 2, 3}, -1)
|
||||
assert.Nil(t, result)
|
||||
})
|
||||
|
||||
t.Run("slice smaller than batch size", func(t *testing.T) {
|
||||
result := Batch([]int{1, 2}, 5)
|
||||
assert.Equal(t, [][]int{{1, 2}}, result)
|
||||
})
|
||||
|
||||
t.Run("slice equal to batch size", func(t *testing.T) {
|
||||
result := Batch([]int{1, 2, 3}, 3)
|
||||
assert.Equal(t, [][]int{{1, 2, 3}}, result)
|
||||
})
|
||||
|
||||
t.Run("slice evenly divisible by batch size", func(t *testing.T) {
|
||||
result := Batch([]int{1, 2, 3, 4, 5, 6}, 2)
|
||||
assert.Equal(t, [][]int{{1, 2}, {3, 4}, {5, 6}}, result)
|
||||
})
|
||||
|
||||
t.Run("slice not evenly divisible by batch size", func(t *testing.T) {
|
||||
result := Batch([]int{1, 2, 3, 4, 5}, 2)
|
||||
assert.Equal(t, [][]int{{1, 2}, {3, 4}, {5}}, result)
|
||||
})
|
||||
|
||||
t.Run("batch size of 1", func(t *testing.T) {
|
||||
result := Batch([]int{1, 2, 3}, 1)
|
||||
assert.Equal(t, [][]int{{1}, {2}, {3}}, result)
|
||||
})
|
||||
|
||||
t.Run("string slice", func(t *testing.T) {
|
||||
result := Batch([]string{"a", "b", "c", "d", "e"}, 2)
|
||||
assert.Equal(t, [][]string{{"a", "b"}, {"c", "d"}, {"e"}}, result)
|
||||
})
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue