diff options
Diffstat (limited to 'tests/collections/ttables.nim')
-rw-r--r-- | tests/collections/ttables.nim | 45 |
1 files changed, 43 insertions, 2 deletions
diff --git a/tests/collections/ttables.nim b/tests/collections/ttables.nim index bba95c1f1..9b7506d1a 100644 --- a/tests/collections/ttables.nim +++ b/tests/collections/ttables.nim @@ -173,9 +173,14 @@ block tableconstr: block ttables2: proc TestHashIntInt() = var tab = initTable[int,int]() - for i in 1..1_000_000: + when defined(nimTestsTablesDisableSlow): + # helps every single time when this test needs to be debugged + let n = 1_000 + else: + let n = 1_000_000 + for i in 1..n: tab[i] = i - for i in 1..1_000_000: + for i in 1..n: var x = tab[i] if x != i : echo "not found ", i @@ -395,3 +400,39 @@ block tablesref: orderedTableSortTest() echo "3" + +block: # https://github.com/nim-lang/Nim/issues/13496 + template testDel(body) = + block: + body + when t is CountTable|CountTableRef: + t.inc(15, 1) + t.inc(19, 2) + t.inc(17, 3) + t.inc(150, 4) + t.del(150) + else: + t[15] = 1 + t[19] = 2 + t[17] = 3 + t[150] = 4 + t.del(150) + doAssert t.len == 3 + doAssert sortedItems(t.values) == @[1, 2, 3] + doAssert sortedItems(t.keys) == @[15, 17, 19] + doAssert sortedPairs(t) == @[(15, 1), (17, 3), (19, 2)] + var s = newSeq[int]() + for v in t.values: s.add(v) + assert s.len == 3 + doAssert sortedItems(s) == @[1, 2, 3] + when t is OrderedTable|OrderedTableRef: + doAssert toSeq(t.keys) == @[15, 19, 17] + doAssert toSeq(t.values) == @[1,2,3] + doAssert toSeq(t.pairs) == @[(15, 1), (19, 2), (17, 3)] + + testDel(): (var t: Table[int, int]) + testDel(): (let t = newTable[int, int]()) + testDel(): (var t: OrderedTable[int, int]) + testDel(): (let t = newOrderedTable[int, int]()) + testDel(): (var t: CountTable[int]) + testDel(): (let t = newCountTable[int]()) |