diff options
-rw-r--r-- | lib/pure/algorithm.nim | 1 | ||||
-rw-r--r-- | tests/stdlib/talgorithm.nim | 5 |
2 files changed, 6 insertions, 0 deletions
diff --git a/lib/pure/algorithm.nim b/lib/pure/algorithm.nim index b71b2c0fc..921c659de 100644 --- a/lib/pure/algorithm.nim +++ b/lib/pure/algorithm.nim @@ -148,6 +148,7 @@ proc product*[T](x: openarray[seq[T]]): seq[seq[T]] = var next: seq[T] = @[] next.setLen(x.len) for i in 0..(x.len-1): + if len(x[i]) == 0: return initial[i] = len(x[i])-1 indexes = initial while true: diff --git a/tests/stdlib/talgorithm.nim b/tests/stdlib/talgorithm.nim index ea57883b0..37de1262f 100644 --- a/tests/stdlib/talgorithm.nim +++ b/tests/stdlib/talgorithm.nim @@ -1,6 +1,11 @@ import unittest +import algorithm suite "product": + test "empty input": + check product[int](newSeq[seq[int]]()) == newSeq[seq[int]]() + test "bit more empty input": + check product[int](@[newSeq[int](), @[], @[]]) == newSeq[seq[int]]() test "a simple case of one element": check product(@[@[1,2]]) == @[@[1,2]] test "two elements": |