Merge branch 'devel' of https://github.com/Araq/Nimrod into devel
This commit is contained in:
commit
d07d83d8fc
6 changed files with 77 additions and 33 deletions
22
tests/collections/ttables.nim
Normal file
22
tests/collections/ttables.nim
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
import tables
|
||||
|
||||
doAssert indexBy(newSeq[int](), proc(x: int):int = x) == initTable[int, int](), "empty int table"
|
||||
|
||||
var tbl1 = initTable[int, int]()
|
||||
tbl1.add(1,1)
|
||||
tbl1.add(2,2)
|
||||
doAssert indexBy(@[1,2], proc(x: int):int = x) == tbl1, "int table"
|
||||
|
||||
type
|
||||
TElem = object
|
||||
foo: int
|
||||
bar: string
|
||||
|
||||
let
|
||||
elem1 = TElem(foo: 1, bar: "bar")
|
||||
elem2 = TElem(foo: 2, bar: "baz")
|
||||
|
||||
var tbl2 = initTable[string, TElem]()
|
||||
tbl2.add("bar", elem1)
|
||||
tbl2.add("baz", elem2)
|
||||
doAssert indexBy(@[elem1,elem2], proc(x: TElem): string = x.bar) == tbl2, "element table"
|
||||
|
|
@ -1,14 +1,8 @@
|
|||
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":
|
||||
check product(@[@[1,2], @[3,4]]) == @[@[2,4],@[1,4],@[2,3],@[1,3]]
|
||||
test "three elements":
|
||||
check product(@[@[1,2], @[3,4], @[5,6]]) == @[@[2,4,6],@[1,4,6],@[2,3,6],@[1,3,6], @[2,4,5],@[1,4,5],@[2,3,5],@[1,3,5]]
|
||||
doAssert product[int](newSeq[seq[int]]()) == newSeq[seq[int]](), "empty input"
|
||||
doAssert product[int](@[newSeq[int](), @[], @[]]) == newSeq[seq[int]](), "bit more empty input"
|
||||
doAssert product(@[@[1,2]]) == @[@[1,2]], "a simple case of one element"
|
||||
doAssert product(@[@[1,2], @[3,4]]) == @[@[2,4],@[1,4],@[2,3],@[1,3]], "two elements"
|
||||
doAssert product(@[@[1,2], @[3,4], @[5,6]]) == @[@[2,4,6],@[1,4,6],@[2,3,6],@[1,3,6], @[2,4,5],@[1,4,5],@[2,3,5],@[1,3,5]], "three elements"
|
||||
doAssert product(@[@[1,2], @[]]) == newSeq[seq[int]](), "two elements, but one empty"
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue