mirror of
https://github.com/rjNemo/underscore
synced 2026-06-06 02:26:42 +00:00
- 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`.
34 lines
636 B
Go
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))
|
|
}
|