diff options
author | Timothee Cour <timothee.cour2@gmail.com> | 2020-02-26 13:07:09 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-02-26 22:07:09 +0100 |
commit | 42dad3a836f7eed860f300e68b33d4c0b39bd1f4 (patch) | |
tree | 1d079a4107f081212a11dde90ec489c49d675cb3 /tests/collections | |
parent | 9a93f73983945a44d891013f728e407ee421287b (diff) | |
download | Nim-42dad3a836f7eed860f300e68b33d4c0b39bd1f4.tar.gz |
tables/sharedtables/intsets/etc: fix #13496, #13504, #13505; add lots of tests (#13498) [backport]
* fix #13496 handle tombstones * add test * more tests * fix #13504; add SharedTable tests * fix #https://github.com/nim-lang/Nim/issues/13505 intsets.missingOrExcl silently gave wrong results sometimes * add test for tintsets
Diffstat (limited to 'tests/collections')
-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]()) |