summary refs log tree commit diff stats
path: root/tests
diff options
context:
space:
mode:
authorAraq <rumpf_a@web.de>2014-02-07 18:21:25 +0100
committerAraq <rumpf_a@web.de>2014-02-07 18:21:25 +0100
commitd07d83d8fcca8394f2cf00aa78e357c736ed2534 (patch)
tree3156c19f6c7988d6759915154bd8d5ff61b18df7 /tests
parenta087f6057e70e8b7c57ec9a20ac7f7815afe9327 (diff)
parent5498415f3b44048739c9b7116638824713d9c1df (diff)
downloadNim-d07d83d8fcca8394f2cf00aa78e357c736ed2534.tar.gz
Merge branch 'devel' of https://github.com/Araq/Nimrod into devel
Diffstat (limited to 'tests')
-rw-r--r--tests/collections/ttables.nim22
-rw-r--r--tests/stdlib/talgorithm.nim18
2 files changed, 28 insertions, 12 deletions
diff --git a/tests/collections/ttables.nim b/tests/collections/ttables.nim
new file mode 100644
index 000000000..f374d5504
--- /dev/null
+++ b/tests/collections/ttables.nim
@@ -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"
diff --git a/tests/stdlib/talgorithm.nim b/tests/stdlib/talgorithm.nim
index 37de1262f..7ab652c82 100644
--- a/tests/stdlib/talgorithm.nim
+++ b/tests/stdlib/talgorithm.nim
@@ -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"