Skip to content

Commit

Permalink
fixed ranged for negative step values, add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Dima Kossovich committed Nov 12, 2023
1 parent 9f58f51 commit 00792fc
Show file tree
Hide file tree
Showing 4 changed files with 189 additions and 83 deletions.
130 changes: 65 additions & 65 deletions cover.cov
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,56 @@ github.com/koss-null/funcfrog/pkg/pipies/not.go:15.31,17.3 1 1
github.com/koss-null/funcfrog/pkg/pipies/not.go:21.82,22.37 1 1
github.com/koss-null/funcfrog/pkg/pipies/not.go:22.37,24.3 1 1
github.com/koss-null/funcfrog/pkg/pipies/reducers.go:9.72,12.2 2 1
github.com/koss-null/funcfrog/internal/algo/parallel/qsort/qsort.go:12.69,13.19 1 1
github.com/koss-null/funcfrog/internal/algo/parallel/qsort/qsort.go:13.19,15.3 1 1
github.com/koss-null/funcfrog/internal/algo/parallel/qsort/qsort.go:16.2,16.17 1 1
github.com/koss-null/funcfrog/internal/algo/parallel/qsort/qsort.go:16.17,18.3 1 1
github.com/koss-null/funcfrog/internal/algo/parallel/qsort/qsort.go:19.2,19.18 1 1
github.com/koss-null/funcfrog/internal/algo/parallel/qsort/qsort.go:19.18,20.40 1 1
github.com/koss-null/funcfrog/internal/algo/parallel/qsort/qsort.go:20.40,22.4 1 1
github.com/koss-null/funcfrog/internal/algo/parallel/qsort/qsort.go:23.3,23.14 1 1
github.com/koss-null/funcfrog/internal/algo/parallel/qsort/qsort.go:26.2,30.13 5 1
github.com/koss-null/funcfrog/internal/algo/parallel/qsort/qsort.go:39.3,41.14 2 1
github.com/koss-null/funcfrog/internal/algo/parallel/qsort/qsort.go:41.14,43.3 1 1
github.com/koss-null/funcfrog/internal/algo/parallel/qsort/qsort.go:45.2,46.15 2 1
github.com/koss-null/funcfrog/internal/algo/parallel/qsort/qsort.go:46.15,46.40 1 1
github.com/koss-null/funcfrog/internal/algo/parallel/qsort/qsort.go:48.2,48.38 1 1
github.com/koss-null/funcfrog/internal/algo/parallel/qsort/qsort.go:48.38,49.49 1 1
github.com/koss-null/funcfrog/internal/algo/parallel/qsort/qsort.go:49.49,51.4 1 1
github.com/koss-null/funcfrog/internal/algo/parallel/qsort/qsort.go:53.3,53.9 1 1
github.com/koss-null/funcfrog/internal/algo/parallel/qsort/qsort.go:56.2,59.44 4 1
github.com/koss-null/funcfrog/internal/algo/parallel/qsort/qsort.go:62.73,66.16 3 1
github.com/koss-null/funcfrog/internal/algo/parallel/qsort/qsort.go:67.9,68.50 1 1
github.com/koss-null/funcfrog/internal/algo/parallel/qsort/qsort.go:69.9,70.50 1 1
github.com/koss-null/funcfrog/internal/algo/parallel/qsort/qsort.go:73.2,73.15 1 1
github.com/koss-null/funcfrog/internal/algo/parallel/qsort/qsort.go:73.15,74.28 1 1
github.com/koss-null/funcfrog/internal/algo/parallel/qsort/qsort.go:74.28,76.4 1 1
github.com/koss-null/funcfrog/internal/algo/parallel/qsort/qsort.go:77.3,77.28 1 1
github.com/koss-null/funcfrog/internal/algo/parallel/qsort/qsort.go:77.28,79.4 1 1
github.com/koss-null/funcfrog/internal/algo/parallel/qsort/qsort.go:80.3,80.15 1 1
github.com/koss-null/funcfrog/internal/algo/parallel/qsort/qsort.go:80.15,81.9 1 1
github.com/koss-null/funcfrog/internal/algo/parallel/qsort/qsort.go:83.3,85.7 3 1
github.com/koss-null/funcfrog/internal/algo/parallel/qsort/qsort.go:88.2,88.11 1 1
github.com/koss-null/funcfrog/internal/algo/parallel/qsort/qsort.go:92.68,93.62 1 1
github.com/koss-null/funcfrog/internal/algo/parallel/qsort/qsort.go:93.62,95.3 1 1
github.com/koss-null/funcfrog/internal/algo/parallel/qsort/qsort.go:96.2,96.62 1 1
github.com/koss-null/funcfrog/internal/algo/parallel/qsort/qsort.go:96.62,98.3 1 1
github.com/koss-null/funcfrog/internal/algo/parallel/qsort/qsort.go:100.2,100.62 1 1
github.com/koss-null/funcfrog/internal/algo/parallel/qsort/qsort.go:100.62,102.3 1 1
github.com/koss-null/funcfrog/internal/algo/parallel/qsort/qsort.go:103.2,103.62 1 1
github.com/koss-null/funcfrog/internal/algo/parallel/qsort/qsort.go:103.62,105.3 1 1
github.com/koss-null/funcfrog/internal/algo/parallel/qsort/qsort.go:107.2,107.62 1 1
github.com/koss-null/funcfrog/internal/algo/parallel/qsort/qsort.go:107.62,109.3 1 1
github.com/koss-null/funcfrog/internal/algo/parallel/qsort/qsort.go:110.2,110.62 1 1
github.com/koss-null/funcfrog/internal/algo/parallel/qsort/qsort.go:110.62,112.3 1 1
github.com/koss-null/funcfrog/internal/algo/parallel/qsort/qsort.go:115.2,115.64 1 1
github.com/koss-null/funcfrog/internal/algo/parallel/qsort/qsort.go:115.64,117.3 1 1
github.com/koss-null/funcfrog/internal/algo/parallel/qsort/qsort.go:118.2,118.64 1 1
github.com/koss-null/funcfrog/internal/algo/parallel/qsort/qsort.go:118.64,120.3 1 1
github.com/koss-null/funcfrog/internal/algo/parallel/qsort/qsort.go:121.2,121.21 1 1
github.com/koss-null/funcfrog/internal/algo/parallel/qsort/qsort.go:124.38,126.25 2 1
github.com/koss-null/funcfrog/internal/algo/parallel/qsort/qsort.go:126.25,128.3 1 1
github.com/koss-null/funcfrog/internal/algo/parallel/qsort/qsort.go:129.2,129.16 1 1
github.com/koss-null/funcfrog/internal/internalpipe/any.go:7.75,10.54 3 1
github.com/koss-null/funcfrog/internal/internalpipe/any.go:10.54,11.37 1 1
github.com/koss-null/funcfrog/internal/internalpipe/any.go:11.37,13.4 1 1
Expand Down Expand Up @@ -192,7 +242,7 @@ github.com/koss-null/funcfrog/internal/internalpipe/first.go:109.32,110.17 1 1
github.com/koss-null/funcfrog/internal/internalpipe/first.go:110.17,112.5 1 1
github.com/koss-null/funcfrog/internal/internalpipe/first.go:114.4,115.29 2 1
github.com/koss-null/funcfrog/internal/internalpipe/first.go:115.29,116.12 1 1
github.com/koss-null/funcfrog/internal/internalpipe/first.go:117.17,118.12 1 0
github.com/koss-null/funcfrog/internal/internalpipe/first.go:117.17,118.12 1 1
github.com/koss-null/funcfrog/internal/internalpipe/first.go:119.13,121.18 2 1
github.com/koss-null/funcfrog/internal/internalpipe/first.go:121.18,124.7 2 1
github.com/koss-null/funcfrog/internal/internalpipe/first.go:127.4,127.25 1 1
Expand Down Expand Up @@ -287,56 +337,6 @@ github.com/koss-null/funcfrog/internal/internalpipe/yeet.go:50.2,55.29 5 1
github.com/koss-null/funcfrog/internal/internalpipe/yeet.go:55.29,56.37 1 1
github.com/koss-null/funcfrog/internal/internalpipe/yeet.go:56.37,58.4 1 1
github.com/koss-null/funcfrog/internal/internalpipe/yeet.go:62.33,66.2 3 1
github.com/koss-null/funcfrog/internal/algo/parallel/qsort/qsort.go:12.69,13.19 1 1
github.com/koss-null/funcfrog/internal/algo/parallel/qsort/qsort.go:13.19,15.3 1 1
github.com/koss-null/funcfrog/internal/algo/parallel/qsort/qsort.go:16.2,16.17 1 1
github.com/koss-null/funcfrog/internal/algo/parallel/qsort/qsort.go:16.17,18.3 1 1
github.com/koss-null/funcfrog/internal/algo/parallel/qsort/qsort.go:19.2,19.18 1 1
github.com/koss-null/funcfrog/internal/algo/parallel/qsort/qsort.go:19.18,20.40 1 1
github.com/koss-null/funcfrog/internal/algo/parallel/qsort/qsort.go:20.40,22.4 1 1
github.com/koss-null/funcfrog/internal/algo/parallel/qsort/qsort.go:23.3,23.14 1 1
github.com/koss-null/funcfrog/internal/algo/parallel/qsort/qsort.go:26.2,30.13 5 1
github.com/koss-null/funcfrog/internal/algo/parallel/qsort/qsort.go:39.3,41.14 2 1
github.com/koss-null/funcfrog/internal/algo/parallel/qsort/qsort.go:41.14,43.3 1 1
github.com/koss-null/funcfrog/internal/algo/parallel/qsort/qsort.go:45.2,46.15 2 1
github.com/koss-null/funcfrog/internal/algo/parallel/qsort/qsort.go:46.15,46.40 1 1
github.com/koss-null/funcfrog/internal/algo/parallel/qsort/qsort.go:48.2,48.38 1 1
github.com/koss-null/funcfrog/internal/algo/parallel/qsort/qsort.go:48.38,49.49 1 1
github.com/koss-null/funcfrog/internal/algo/parallel/qsort/qsort.go:49.49,51.4 1 1
github.com/koss-null/funcfrog/internal/algo/parallel/qsort/qsort.go:53.3,53.9 1 1
github.com/koss-null/funcfrog/internal/algo/parallel/qsort/qsort.go:56.2,59.44 4 1
github.com/koss-null/funcfrog/internal/algo/parallel/qsort/qsort.go:62.73,66.16 3 1
github.com/koss-null/funcfrog/internal/algo/parallel/qsort/qsort.go:67.9,68.50 1 1
github.com/koss-null/funcfrog/internal/algo/parallel/qsort/qsort.go:69.9,70.50 1 1
github.com/koss-null/funcfrog/internal/algo/parallel/qsort/qsort.go:73.2,73.15 1 1
github.com/koss-null/funcfrog/internal/algo/parallel/qsort/qsort.go:73.15,74.28 1 1
github.com/koss-null/funcfrog/internal/algo/parallel/qsort/qsort.go:74.28,76.4 1 1
github.com/koss-null/funcfrog/internal/algo/parallel/qsort/qsort.go:77.3,77.28 1 1
github.com/koss-null/funcfrog/internal/algo/parallel/qsort/qsort.go:77.28,79.4 1 1
github.com/koss-null/funcfrog/internal/algo/parallel/qsort/qsort.go:80.3,80.15 1 1
github.com/koss-null/funcfrog/internal/algo/parallel/qsort/qsort.go:80.15,81.9 1 1
github.com/koss-null/funcfrog/internal/algo/parallel/qsort/qsort.go:83.3,85.7 3 1
github.com/koss-null/funcfrog/internal/algo/parallel/qsort/qsort.go:88.2,88.11 1 1
github.com/koss-null/funcfrog/internal/algo/parallel/qsort/qsort.go:92.68,93.62 1 1
github.com/koss-null/funcfrog/internal/algo/parallel/qsort/qsort.go:93.62,95.3 1 1
github.com/koss-null/funcfrog/internal/algo/parallel/qsort/qsort.go:96.2,96.62 1 1
github.com/koss-null/funcfrog/internal/algo/parallel/qsort/qsort.go:96.62,98.3 1 1
github.com/koss-null/funcfrog/internal/algo/parallel/qsort/qsort.go:100.2,100.62 1 1
github.com/koss-null/funcfrog/internal/algo/parallel/qsort/qsort.go:100.62,102.3 1 1
github.com/koss-null/funcfrog/internal/algo/parallel/qsort/qsort.go:103.2,103.62 1 1
github.com/koss-null/funcfrog/internal/algo/parallel/qsort/qsort.go:103.62,105.3 1 1
github.com/koss-null/funcfrog/internal/algo/parallel/qsort/qsort.go:107.2,107.62 1 1
github.com/koss-null/funcfrog/internal/algo/parallel/qsort/qsort.go:107.62,109.3 1 1
github.com/koss-null/funcfrog/internal/algo/parallel/qsort/qsort.go:110.2,110.62 1 1
github.com/koss-null/funcfrog/internal/algo/parallel/qsort/qsort.go:110.62,112.3 1 1
github.com/koss-null/funcfrog/internal/algo/parallel/qsort/qsort.go:115.2,115.64 1 1
github.com/koss-null/funcfrog/internal/algo/parallel/qsort/qsort.go:115.64,117.3 1 1
github.com/koss-null/funcfrog/internal/algo/parallel/qsort/qsort.go:118.2,118.64 1 1
github.com/koss-null/funcfrog/internal/algo/parallel/qsort/qsort.go:118.64,120.3 1 1
github.com/koss-null/funcfrog/internal/algo/parallel/qsort/qsort.go:121.2,121.21 1 1
github.com/koss-null/funcfrog/internal/algo/parallel/qsort/qsort.go:124.38,126.25 2 1
github.com/koss-null/funcfrog/internal/algo/parallel/qsort/qsort.go:126.25,128.3 1 1
github.com/koss-null/funcfrog/internal/algo/parallel/qsort/qsort.go:129.2,129.16 1 1
github.com/koss-null/funcfrog/pkg/pipe/collectors.go:6.50,9.33 2 0
github.com/koss-null/funcfrog/pkg/pipe/collectors.go:9.33,10.42 1 0
github.com/koss-null/funcfrog/pkg/pipe/collectors.go:10.42,13.5 2 0
Expand Down Expand Up @@ -372,28 +372,28 @@ github.com/koss-null/funcfrog/pkg/pipe/pipe.go:64.28,66.2 1 1
github.com/koss-null/funcfrog/pkg/pipe/pipe.go:69.31,71.2 1 1
github.com/koss-null/funcfrog/pkg/pipe/pipe.go:75.49,77.2 1 1
github.com/koss-null/funcfrog/pkg/pipe/pipe.go:81.38,83.2 1 1
github.com/koss-null/funcfrog/pkg/pipe/pipe.go:86.48,88.2 1 0
github.com/koss-null/funcfrog/pkg/pipe/pipe.go:91.58,93.2 1 0
github.com/koss-null/funcfrog/pkg/pipe/pipe.go:86.48,88.2 1 1
github.com/koss-null/funcfrog/pkg/pipe/pipe.go:91.58,93.2 1 1
github.com/koss-null/funcfrog/pkg/pipe/pipe.go:96.52,98.2 1 1
github.com/koss-null/funcfrog/pkg/pipe/pipenl.go:15.53,17.2 1 0
github.com/koss-null/funcfrog/pkg/pipe/pipenl.go:15.53,17.2 1 1
github.com/koss-null/funcfrog/pkg/pipe/pipenl.go:20.59,22.2 1 1
github.com/koss-null/funcfrog/pkg/pipe/pipenl.go:27.67,29.2 1 0
github.com/koss-null/funcfrog/pkg/pipe/pipenl.go:27.67,29.2 1 1
github.com/koss-null/funcfrog/pkg/pipe/pipenl.go:32.32,34.2 1 1
github.com/koss-null/funcfrog/pkg/pipe/pipenl.go:37.30,39.2 1 0
github.com/koss-null/funcfrog/pkg/pipe/pipenl.go:37.30,39.2 1 1
github.com/koss-null/funcfrog/pkg/pipe/pipenl.go:43.42,45.2 1 1
github.com/koss-null/funcfrog/pkg/pipe/pipenl.go:49.41,51.2 1 1
github.com/koss-null/funcfrog/pkg/pipe/pipenl.go:55.54,57.2 1 0
github.com/koss-null/funcfrog/pkg/pipe/pipenl.go:61.45,63.2 1 0
github.com/koss-null/funcfrog/pkg/pipe/pipenl.go:66.55,68.2 1 0
github.com/koss-null/funcfrog/pkg/pipe/pipenl.go:71.65,73.2 1 0
github.com/koss-null/funcfrog/pkg/pipe/pipenl.go:76.54,78.2 1 0
github.com/koss-null/funcfrog/pkg/pipe/pipenl.go:55.54,57.2 1 1
github.com/koss-null/funcfrog/pkg/pipe/pipenl.go:61.45,63.2 1 1
github.com/koss-null/funcfrog/pkg/pipe/pipenl.go:66.55,68.2 1 1
github.com/koss-null/funcfrog/pkg/pipe/pipenl.go:71.65,73.2 1 1
github.com/koss-null/funcfrog/pkg/pipe/pipenl.go:76.54,78.2 1 1
github.com/koss-null/funcfrog/pkg/pipe/prefixpipe.go:13.15,16.33 2 1
github.com/koss-null/funcfrog/pkg/pipe/prefixpipe.go:16.33,17.42 1 1
github.com/koss-null/funcfrog/pkg/pipe/prefixpipe.go:17.42,20.5 2 1
github.com/koss-null/funcfrog/pkg/pipe/prefixpipe.go:21.4,21.20 1 0
github.com/koss-null/funcfrog/pkg/pipe/prefixpipe.go:33.20,36.33 2 0
github.com/koss-null/funcfrog/pkg/pipe/prefixpipe.go:36.33,37.42 1 0
github.com/koss-null/funcfrog/pkg/pipe/prefixpipe.go:37.42,40.5 2 0
github.com/koss-null/funcfrog/pkg/pipe/prefixpipe.go:33.20,36.33 2 1
github.com/koss-null/funcfrog/pkg/pipe/prefixpipe.go:36.33,37.42 1 1
github.com/koss-null/funcfrog/pkg/pipe/prefixpipe.go:37.42,40.5 2 1
github.com/koss-null/funcfrog/pkg/pipe/prefixpipe.go:41.4,41.20 1 0
github.com/koss-null/funcfrog/pkg/pipe/prefixpipe.go:51.98,53.22 2 0
github.com/koss-null/funcfrog/pkg/pipe/prefixpipe.go:53.22,55.3 1 0
Expand All @@ -403,4 +403,4 @@ github.com/koss-null/funcfrog/pkg/pipe/prefixpipe.go:60.9,61.29 1 0
github.com/koss-null/funcfrog/pkg/pipe/prefixpipe.go:62.10,64.27 2 0
github.com/koss-null/funcfrog/pkg/pipe/prefixpipe.go:64.27,66.4 1 0
github.com/koss-null/funcfrog/pkg/pipe/prefixpipe.go:67.3,67.13 1 0
github.com/koss-null/funcfrog/pkg/pipe/yeet.go:13.38,15.2 1 0
github.com/koss-null/funcfrog/pkg/pipe/yeet.go:13.38,15.2 1 1
36 changes: 31 additions & 5 deletions internal/internalpipe/constructor.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package internalpipe

import (
"math"

"golang.org/x/exp/constraints"
)

Expand Down Expand Up @@ -40,7 +42,10 @@ func Func[T any](fn func(i int) (T, bool)) Pipe[T] {

func FuncP[T any](fn func(i int) (*T, bool)) Pipe[T] {
return Pipe[T]{
Fn: fn,
Fn: func(i int) (*T, bool) {
obj, exist := fn(i)
return obj, !exist
},
Len: notSet,
ValLim: notSet,
GoroutinesCnt: defaultParallelWrks,
Expand All @@ -59,10 +64,23 @@ func Cycle[T any](a []T) Pipe[T] {
})
}

func abs[T constraints.Integer | constraints.Float](a T) T {
if a < 0 {
return -a
}
return a
}

func ceil[T constraints.Integer | constraints.Float](a T) int {
return int(math.Ceil(float64(a)))
}

func Range[T constraints.Integer | constraints.Float](start, finish, step T) Pipe[T] {
if start >= finish {
if (step == 0) ||
(step > 0 && start >= finish) ||
(step < 0 && finish >= start) {
return Pipe[T]{
Fn: func(int) (*T, bool) {
Fn: func(i int) (*T, bool) {
return nil, true
},
Len: 0,
Expand All @@ -71,12 +89,20 @@ func Range[T constraints.Integer | constraints.Float](start, finish, step T) Pip
}
}

pred := func(x T) bool {
return x >= finish
}
if step < 0 {
pred = func(x T) bool {
return x <= finish
}
}
return Pipe[T]{
Fn: func(i int) (*T, bool) {
val := start + T(i)*step
return &val, val >= finish
return &val, pred(val)
},
Len: max(int((finish-start)/step), 1),
Len: ceil(abs(float64(finish-start) / float64(step))),
ValLim: notSet,
GoroutinesCnt: defaultParallelWrks,
}
Expand Down
45 changes: 32 additions & 13 deletions internal/internalpipe/constructor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,32 +87,51 @@ func Test_Range(t *testing.T) {
t.Run("happy", func(t *testing.T) {
t.Parallel()
p := Range(0, 10, 1)
require.Equal(t, p.Len, 10)
require.Equal(t, p.ValLim, notSet)
require.Equal(t, p.GoroutinesCnt, defaultParallelWrks)
res := p.Do()
require.Equal(t, 10, len(res))
for i := 0; i < 10; i++ {
require.Equal(t, i, res[i])
}
})
t.Run("single step owerflow", func(t *testing.T) {
t.Run("single_step_owerflow", func(t *testing.T) {
t.Parallel()
p := Range(1, 10, 100)
require.Equal(t, 1, p.Len)
require.Equal(t, notSet, p.ValLim)
require.Equal(t, defaultParallelWrks, p.GoroutinesCnt)
p := Range(1, 10, 50)
res := p.Do()
require.Equal(t, 1, len(res))
require.Equal(t, 1, res[0])
})
t.Run("finish less than start", func(t *testing.T) {
t.Run("finish_is_less_than_start", func(t *testing.T) {
t.Parallel()
p := Range(100, 10, 100)
require.Equal(t, 0, p.Len)
require.Equal(t, notSet, p.ValLim)
require.Equal(t, defaultParallelWrks, p.GoroutinesCnt)
p := Range(100, 10, 50)
res := p.Do()
require.Equal(t, 0, len(res))
})
t.Run("step_is_0", func(t *testing.T) {
t.Parallel()
p := Range(1, 10, 0)
res := p.Do()
require.Equal(t, 0, len(res))
})
t.Run("start_is_finish", func(t *testing.T) {
t.Parallel()
p := Range(1, 1, 1)
res := p.Do()
require.Equal(t, 0, len(res))
})
t.Run("start_is_finish_negative", func(t *testing.T) {
t.Parallel()
p := Range(1, 1, -1)
res := p.Do()
require.Equal(t, 0, len(res))
})
t.Run("finish_is_less_than_start_and_step_is_negative", func(t *testing.T) {
t.Parallel()
p := Range(100, 10, -50)
res := p.Do()
require.Equal(t, 2, len(res))
require.Equal(t, 100, res[0])
require.Equal(t, 50, res[1])
})
}

func Test_Repeat(t *testing.T) {
Expand Down
61 changes: 61 additions & 0 deletions pkg/pipe/pipe_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ import (
"github.com/koss-null/funcfrog/pkg/pipies"
)

// testing constructions

func TestSlice(t *testing.T) {
t.Parallel()

Expand Down Expand Up @@ -172,6 +174,65 @@ func TestFunc(t *testing.T) {
}
}

func TestFuncP(t *testing.T) {
t.Parallel()

const testSize = 10_000
p := pipe.FuncP(func(i int) (*int, bool) { return &i, true }).Gen(testSize).Do()
for i := 0; i < testSize; i++ {
require.Equal(t, i, p[i])
}
}

func TestCycle(t *testing.T) {
t.Parallel()

const testSize = 10_000
c := pipe.Cycle([]int{0, 1, 2, 3, 4}).Take(testSize).Do()
for i := 0; i < testSize; i++ {
require.Equal(t, i%5, c[i])
}
}

func TestRange(t *testing.T) {
t.Parallel()

t.Run("asc", func(t *testing.T) {
t.Parallel()

r := pipe.Range(0, 10_000, 5).Do()
idx := 0
for i := 0; i < 10_000; i += 5 {
require.Equal(t, i, r[idx])
idx++
}
})

t.Run("desc", func(t *testing.T) {
t.Parallel()

r := pipe.Range(10_000, 0, -5).Do()
idx := 0
for i := 10_000; i > 0; i -= 5 {
require.Equal(t, i, r[idx])
idx++
}
})

t.Run("desc2", func(t *testing.T) {
t.Parallel()

r := pipe.Range(0, -10_000, -5).Do()
idx := 0
for i := 0; i > -10_000; i -= 5 {
require.Equal(t, i, r[idx])
idx++
}
})
}

// testing pipe and pipeNL functions

func TestMap(t *testing.T) {
t.Parallel()

Expand Down

0 comments on commit 00792fc

Please sign in to comment.