Skip to content

Commit 39be942

Browse files
committed
test: add coverage for ParallelMap and ParallelFilter workers
Add tests to verify default worker behavior in ParallelMap and ParallelFilter. Add internal test to cover unexported Result marker methods for coverage.
1 parent 9cf61ec commit 39be942

File tree

4 files changed

+31
-1
lines changed

4 files changed

+31
-1
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ build:
66
docker build -t $(IMAGE):latest .
77

88
test: build
9-
docker run --name $(IMAGE) --rm -i -t $(IMAGE) sh -c "$(TEST) $(COVER)"
9+
docker run --name $(IMAGE) --rm -i $(IMAGE) sh -c "$(TEST) $(COVER)"
1010

1111
scan:
1212
trivy --cache-dir .trivycache/ image --exit-code 0 --no-progress --severity CRITICAL $(IMAGE)

parallel_filter_test.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,3 +31,12 @@ func TestParallelFilter_Error(t *testing.T) {
3131
assert.Error(t, err)
3232
assert.Nil(t, out)
3333
}
34+
35+
func TestParallelFilter_DefaultWorkers(t *testing.T) {
36+
values := []int{1, 2, 3, 4}
37+
out, err := u.ParallelFilter(context.Background(), values, 0, func(_ context.Context, n int) (bool, error) {
38+
return n%2 == 1, nil
39+
})
40+
assert.NoError(t, err)
41+
assert.Equal(t, []int{1, 3}, out)
42+
}

parallel_map_test.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,3 +31,12 @@ func TestParallelMap_Error(t *testing.T) {
3131
assert.Error(t, err)
3232
assert.Nil(t, out)
3333
}
34+
35+
func TestParallelMap_DefaultWorkers(t *testing.T) {
36+
values := []int{1, 2, 3}
37+
out, err := u.ParallelMap(context.Background(), values, 0, func(_ context.Context, n int) (int, error) {
38+
return n + 1, nil
39+
})
40+
assert.NoError(t, err)
41+
assert.Equal(t, []int{2, 3, 4}, out)
42+
}

result_internal_test.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package underscore
2+
3+
import "testing"
4+
5+
// Ensure the unexported marker methods are executed for coverage.
6+
func TestResultIsResultMarker(t *testing.T) {
7+
var ok Ok[int]
8+
ok.isResult()
9+
10+
var er Err[int]
11+
er.isResult()
12+
}

0 commit comments

Comments
 (0)