mirror of
https://github.com/nim-lang/Nim.git
synced 2026-04-19 22:10:33 +00:00
product more robust against empty input
This commit is contained in:
@@ -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:
|
||||
|
||||
@@ -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":
|
||||
|
||||
Reference in New Issue
Block a user