mirror of
https://github.com/rjNemo/underscore
synced 2026-06-06 02:26:42 +00:00
Adds extensive edge case tests for core functions to catch regressions and ensure robust behavior. Test coverage added: - Empty slice tests: Filter, Map, Partition, Reduce, Unique, Last - Single element tests: Filter, Map, Partition, Reduce, Unique, Last - Large dataset tests: Filter (10k), Map (10k) - Boundary cases: Partition (all pass/reject), Unique (no dups/all same) Functions tested: - Filter: 4 new tests (empty, single, single no match, large) - Partition: 4 new tests (empty, single, all pass, all reject) - Last: 2 new tests (empty panic, single element) - Map: 3 new tests (empty, single, large) - Unique: 4 new tests (empty, single, no dups, all same) - Reduce: 2 new tests (empty, single) Results: - All 118 tests pass - Coverage: 98.4% (maintained high coverage) - Verified panic behavior for edge cases 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
48 lines
1.2 KiB
Go
48 lines
1.2 KiB
Go
package underscore_test
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
u "github.com/rjNemo/underscore"
|
|
)
|
|
|
|
func TestPartition(t *testing.T) {
|
|
nums := []int{0, 1, 2, 3, 4, 5, 6, 7, 8, 9}
|
|
isEven := func(n int) bool { return n%2 == 0 }
|
|
|
|
wantEvens := []int{0, 2, 4, 6, 8}
|
|
wantOdds := []int{1, 3, 5, 7, 9}
|
|
|
|
evens, odds := u.Partition(nums, isEven)
|
|
|
|
assert.Equal(t, wantEvens, evens)
|
|
assert.Equal(t, wantOdds, odds)
|
|
}
|
|
|
|
func TestPartitionEmpty(t *testing.T) {
|
|
keep, reject := u.Partition([]int{}, func(n int) bool { return n > 0 })
|
|
assert.Empty(t, keep)
|
|
assert.Empty(t, reject)
|
|
}
|
|
|
|
func TestPartitionSingleElement(t *testing.T) {
|
|
keep, reject := u.Partition([]int{5}, func(n int) bool { return n > 3 })
|
|
assert.Equal(t, []int{5}, keep)
|
|
assert.Empty(t, reject)
|
|
}
|
|
|
|
func TestPartitionAllPass(t *testing.T) {
|
|
nums := []int{2, 4, 6, 8}
|
|
keep, reject := u.Partition(nums, func(n int) bool { return n%2 == 0 })
|
|
assert.Equal(t, nums, keep)
|
|
assert.Empty(t, reject)
|
|
}
|
|
|
|
func TestPartitionAllReject(t *testing.T) {
|
|
nums := []int{1, 3, 5, 7}
|
|
keep, reject := u.Partition(nums, func(n int) bool { return n%2 == 0 })
|
|
assert.Empty(t, keep)
|
|
assert.Equal(t, nums, reject)
|
|
}
|