mirror of
https://github.com/rjNemo/underscore
synced 2026-06-06 10:36:43 +00:00
Adds length checks to Max and Min functions to provide clear, explicit panic messages when called with empty slices, rather than allowing confusing index-out-of-bounds panics. Changes: - Max: Added check for empty slice with "underscore.Max: empty slice" panic - Min: Added check for empty slice with "underscore.Min: empty slice" panic - Updated doc comments to document panic behavior - Added TestMaxEmpty and TestMinEmpty to verify panic behavior Impact: - Better error messages for debugging - Documented behavior prevents user surprises - Non-breaking change (still panics, just with clearer message) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
21 lines
327 B
Go
21 lines
327 B
Go
package underscore_test
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
u "github.com/rjNemo/underscore"
|
|
)
|
|
|
|
func TestMax(t *testing.T) {
|
|
nums := []int{1, 9, 2, 8, 3, 7, 4, 6, 5}
|
|
want := 9
|
|
assert.Equal(t, want, u.Max(nums))
|
|
}
|
|
|
|
func TestMaxEmpty(t *testing.T) {
|
|
assert.Panics(t, func() {
|
|
u.Max([]int{})
|
|
})
|
|
}
|