underscore/reduce_test.go
Ruidy 106b713cc5
test: add comprehensive edge case tests
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>
2025-11-14 13:57:33 +01:00

29 lines
650 B
Go

package underscore_test
import (
"testing"
"github.com/stretchr/testify/assert"
u "github.com/rjNemo/underscore"
)
func TestReduce(t *testing.T) {
nums := []int{0, 1, 2, 3, 4, 5, 6, 7, 8, 9}
reducer := func(n, acc int) int {
return n + acc
}
want := 45
assert.Equal(t, want, u.Reduce(nums, reducer, 0))
}
func TestReduceEmpty(t *testing.T) {
result := u.Reduce([]int{}, func(n, acc int) int { return n + acc }, 10)
assert.Equal(t, 10, result) // Should return initial accumulator
}
func TestReduceSingleElement(t *testing.T) {
result := u.Reduce([]int{5}, func(n, acc int) int { return n + acc }, 0)
assert.Equal(t, 5, result)
}