underscore/unzip_test.go
Ruidy f33e86d502
feat: add Tap, Transpose, Unzip, ParallelReduce, and Replicate (#49)
* feat: add Tap, Transpose, Unzip, ParallelReduce, and Replicate

- Add Tap: for side effects/debugging in pipelines
- Add Transpose: flip matrix rows and columns
- Add Unzip: split tuple slice into two slices
- Add ParallelReduce: parallel reduction (experimental)
- Add Replicate: create n copies of a value

Comprehensive tests included for all functions.

Resolves Issues 21, 22, 23, 24, 25

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>

* test: improve ParallelReduce test coverage to 97.5%

Add comprehensive tests covering:
- Default workers (workers <= 0)
- Negative workers
- Error handling and propagation
- Context cancellation during execution
- Context timeout
- Single element processing
- Many workers (more workers than elements)
- Benchmark for performance validation

Coverage increased from 68.75% to 97.5%

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>

---------

Co-authored-by: Claude <noreply@anthropic.com>
2025-11-16 09:02:47 +01:00

26 lines
551 B
Go

package underscore_test
import (
"testing"
"github.com/stretchr/testify/assert"
u "github.com/rjNemo/underscore"
)
func TestUnzip(t *testing.T) {
pairs := []u.Tuple[int, string]{
{Left: 1, Right: "a"},
{Left: 2, Right: "b"},
{Left: 3, Right: "c"},
}
lefts, rights := u.Unzip(pairs)
assert.Equal(t, []int{1, 2, 3}, lefts)
assert.Equal(t, []string{"a", "b", "c"}, rights)
}
func TestUnzipEmpty(t *testing.T) {
lefts, rights := u.Unzip([]u.Tuple[int, string]{})
assert.Equal(t, []int{}, lefts)
assert.Equal(t, []string{}, rights)
}