mirror of
https://github.com/rjNemo/underscore
synced 2026-06-06 02:26:42 +00:00
BREAKING CHANGE: Drop function now correctly drops first N elements
instead of removing element at specific index.
Changes:
- Renamed old Drop behavior to RemoveAt function
- Implemented correct Drop semantics (drop first N elements)
- Added comprehensive tests for both functions
Drop (NEW behavior):
- Drop([]int{1,2,3,4,5}, 2) → [3,4,5] (drops first 2 elements)
- Returns empty slice if n >= len(values)
- Returns original slice if n <= 0
RemoveAt (OLD Drop behavior):
- RemoveAt([]int{1,2,3,4,5}, 2) → [1,2,4,5] (removes index 2)
- Returns original slice if index out of bounds
- Pre-allocates with capacity len(values)-1
Tests added:
- Drop: 5 tests (basic, none, all, empty, single)
- RemoveAt: 6 tests (basic, first, last, bounds, empty, single)
Documentation updated:
- README.md: Added RemoveAt to function list
- CLAUDE.md: Marked Drop semantics as fixed
- ACTION_PLAN.md: Updated completion status
Migration guide:
- Old: Drop(slice, index) → New: RemoveAt(slice, index)
- New Drop usage: Drop(slice, n) drops first n elements
Coverage: 98.8% (maintained)
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
50 lines
986 B
Go
50 lines
986 B
Go
package underscore_test
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
u "github.com/rjNemo/underscore"
|
|
)
|
|
|
|
func TestRemoveAt(t *testing.T) {
|
|
nums := []int{1, 9, 2, 8, 3, 7, 4, 6, 5}
|
|
want := []int{1, 9, 2, 3, 7, 4, 6, 5}
|
|
|
|
assert.Equal(t, want, u.RemoveAt(nums, 3))
|
|
}
|
|
|
|
func TestRemoveAtFirst(t *testing.T) {
|
|
nums := []int{1, 2, 3, 4, 5}
|
|
want := []int{2, 3, 4, 5}
|
|
|
|
assert.Equal(t, want, u.RemoveAt(nums, 0))
|
|
}
|
|
|
|
func TestRemoveAtLast(t *testing.T) {
|
|
nums := []int{1, 2, 3, 4, 5}
|
|
want := []int{1, 2, 3, 4}
|
|
|
|
assert.Equal(t, want, u.RemoveAt(nums, 4))
|
|
}
|
|
|
|
func TestRemoveAtOutOfBounds(t *testing.T) {
|
|
nums := []int{1, 2, 3}
|
|
|
|
// Negative index
|
|
assert.Equal(t, nums, u.RemoveAt(nums, -1))
|
|
|
|
// Index too large
|
|
assert.Equal(t, nums, u.RemoveAt(nums, 10))
|
|
}
|
|
|
|
func TestRemoveAtEmpty(t *testing.T) {
|
|
result := u.RemoveAt([]int{}, 0)
|
|
assert.Empty(t, result)
|
|
}
|
|
|
|
func TestRemoveAtSingleElement(t *testing.T) {
|
|
result := u.RemoveAt([]int{42}, 0)
|
|
assert.Empty(t, result)
|
|
}
|