underscore/chunk_test.go
Ruidy 1031038d42
feat: add Chunk, ContainsBy, UniqueBy, ParallelMap, map helpers
- Add `Chunk` to split slices into groups of size n.
- Add `ContainsBy` for predicate-based containment checks.
- Add `UniqueBy` to deduplicate slices by key selector.
- Add `ParallelMap` for concurrent mapping with context and error
handling.
- Add `maps.Keys` and `maps.Values` helpers for extracting map
keys/values.
- Update README and docs for new features.
- Refactor `Contains` to use `slices.Contains`.
2025-09-01 18:03:38 -04:00

34 lines
636 B
Go

package underscore_test
import (
"testing"
"github.com/stretchr/testify/assert"
u "github.com/rjNemo/underscore"
)
func TestChunk(t *testing.T) {
in := []int{1, 2, 3, 4, 5}
got := u.Chunk(in, 2)
want := [][]int{{1, 2}, {3, 4}, {5}}
assert.Equal(t, want, got)
}
func TestChunkLargeSize(t *testing.T) {
in := []int{1, 2, 3}
got := u.Chunk(in, 10)
want := [][]int{{1, 2, 3}}
assert.Equal(t, want, got)
}
func TestChunkInvalidSize(t *testing.T) {
var in []int
assert.Nil(t, u.Chunk(in, 0))
assert.Nil(t, u.Chunk(in, -1))
}
func TestChunkEmpty(t *testing.T) {
got := u.Chunk([]int{}, 1)
assert.Equal(t, 0, len(got))
}