diff options
author | Miran <narimiran@disroot.org> | 2020-03-30 13:18:12 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-03-30 13:18:12 +0200 |
commit | 8088633250872de8777c7078e636b2379780e107 (patch) | |
tree | 3ec6b06db9c970da5f9f2b80f1d7053c4021e34f /tests/collections | |
parent | 2a278f6eba5b154920177154bb48733268cacfc5 (diff) | |
download | Nim-8088633250872de8777c7078e636b2379780e107.tar.gz |
faster CIs (#13803)
* ttables: smaller table, 5x speedup * thavlak: less iterations, less loops; 30% speedup * tasyncclosestall: shorter timeout; 35% speedup * gcleak4: less iterations, 2x speedup * ttimes: remove deprecated stuff * tdangerisrelease: remove cpp backend, 3x speedup * tfrexp1: smaller range, 2x speedup * trtree: fix warnings, less iterations, 6x speedup * tasyncawait_cyclebreaker: smaller swarm size; 2x speedup * trealloc: smaller number of iterations; 10x speedup * towned_binary_tree: less iterations, 4x speedup * tclosure: remove unused code, less iterations; 2x speedup * twaitany: less durations; 1.4x speedup * tasync_misc: less iterations, 2x speedup * t8535: smaller sleep, 1.5x speedup * tmanyjoin: smaller sleep, 2x speedup * t12221: shorter sleeps, removed two slower tests; 1.6x speedup * tfuturestream: smaller sleep; 1.5x speedup * growobjcrash: less iterations; 2x speedup * ttryrecv: smaller sleep; 1.5x speedup * treusetvar: less threads; 2x speedup * delete tthreadanalysis2, basically a duplicate of tthreadanalysis * t7758: less iterations, 1.5x speedup * tasyncawait: smaller swarm, less messages; 1.5x speedup * tjsandnativeasync: smaller sleep, 1.5x speedup * tpendingcheck: smaller sleep, 1.5x speedup * remove rodfiles test category * move tseq from its own category to 'collections' category * remove unneeded tests and helpers from 'assert' category * stdlib: merge tbitops2 into tbitops * remove 'trepr2' from 'stdlib' cat * merge 'tstreams' into one file * remove 'tinefficient_const_table' from 'ccbugs' cat * merge 'tcollections_to_string' into 'tcollections' * tblocking_channel: smaller sleep, small speedup * tconvexhull: less iterartions; 1.2x speedup * merge 'tdeepcopy2' into 'tdeepcopy' * merge 'tdisjoint_slice2' into 'tdisjoint_slice1' * tmissing_deepcopy: smaller sequence * tsendtwice: smaller arrays; 5x speedup * remove 'tindexerrorformatbounds' * disable multimethod tests * remove 'gc:none' and 'refc' without 'd:useRealtimeGC' from gc tests * koch.nim: bootstrap just with '-d:release', no need for 'csource' * add github workflow for documentation * testament: no need for 8 sub-second decimals
Diffstat (limited to 'tests/collections')
-rw-r--r-- | tests/collections/tcollections.nim | 108 | ||||
-rw-r--r-- | tests/collections/tseq.nim | 206 | ||||
-rw-r--r-- | tests/collections/ttables.nim | 10 |
3 files changed, 316 insertions, 8 deletions
diff --git a/tests/collections/tcollections.nim b/tests/collections/tcollections.nim index 2f8cfece7..5c95cee28 100644 --- a/tests/collections/tcollections.nim +++ b/tests/collections/tcollections.nim @@ -2,7 +2,7 @@ discard """ output: "" """ -import deques, sequtils +import sets, tables, deques, lists, critbits, sequtils block tapply: @@ -52,3 +52,109 @@ block tmapit: # since ``len`` is not available var r = st.mapIt($(it+10)) doAssert r == @["10", "11", "12", "13", "14"] + + + +# Collections to string: + +# Tests for tuples +doAssert $(1, 2, 3) == "(1, 2, 3)" +doAssert $("1", "2", "3") == """("1", "2", "3")""" +doAssert $('1', '2', '3') == """('1', '2', '3')""" + +# Tests for seqs +doAssert $(@[1, 2, 3]) == "@[1, 2, 3]" +doAssert $(@["1", "2", "3"]) == """@["1", "2", "3"]""" +doAssert $(@['1', '2', '3']) == """@['1', '2', '3']""" + +# Tests for sets +doAssert $(toHashSet([1])) == "{1}" +doAssert $(toHashSet(["1"])) == """{"1"}""" +doAssert $(toHashSet(['1'])) == """{'1'}""" +doAssert $(toOrderedSet([1, 2, 3])) == "{1, 2, 3}" +doAssert $(toOrderedSet(["1", "2", "3"])) == """{"1", "2", "3"}""" +doAssert $(toOrderedSet(['1', '2', '3'])) == """{'1', '2', '3'}""" + +# Tests for tables +doAssert $({1: "1", 2: "2"}.toTable) == """{1: "1", 2: "2"}""" +doAssert $({"1": 1, "2": 2}.toTable) == """{"1": 1, "2": 2}""" + +# Tests for deques +block: + var d = initDeque[int]() + d.addLast(1) + doAssert $d == "[1]" +block: + var d = initDeque[string]() + d.addLast("1") + doAssert $d == """["1"]""" +block: + var d = initDeque[char]() + d.addLast('1') + doAssert $d == "['1']" + +# Tests for lists +block: + var l = initDoublyLinkedList[int]() + l.append(1) + l.append(2) + l.append(3) + doAssert $l == "[1, 2, 3]" +block: + var l = initDoublyLinkedList[string]() + l.append("1") + l.append("2") + l.append("3") + doAssert $l == """["1", "2", "3"]""" +block: + var l = initDoublyLinkedList[char]() + l.append('1') + l.append('2') + l.append('3') + doAssert $l == """['1', '2', '3']""" + +# Tests for critbits +block: + var t: CritBitTree[int] + t["a"] = 1 + doAssert $t == """{"a": 1}""" +block: + var t: CritBitTree[string] + t["a"] = "1" + doAssert $t == """{"a": "1"}""" +block: + var t: CritBitTree[char] + t["a"] = '1' + doAssert $t == """{"a": '1'}""" + + +# Test escaping behavior +block: + var s = "" + s.addQuoted('\0') + s.addQuoted('\31') + s.addQuoted('\127') + doAssert s == "'\\x00''\\x1F''\\x7F'" +block: + var s = "" + s.addQuoted('\\') + s.addQuoted('\'') + s.addQuoted('\"') + doAssert s == """'\\''\'''\"'""" +block: + var s = "" + s.addQuoted("å") + s.addQuoted("ä") + s.addQuoted("ö") + s.addEscapedChar('\xFF') + doAssert s == """"å""ä""ö"\xFF""" + +# Test customized element representation +type CustomString = object + +proc addQuoted(s: var string, x: CustomString) = + s.add("<CustomString>") + +block: + let s = @[CustomString()] + doAssert $s == "@[<CustomString>]" diff --git a/tests/collections/tseq.nim b/tests/collections/tseq.nim new file mode 100644 index 000000000..6a28bc8e6 --- /dev/null +++ b/tests/collections/tseq.nim @@ -0,0 +1,206 @@ +discard """ + output: ''' +Hithere, what's your name?Hathere, what's your name? +fA13msg1falsefB14msg2truefC15msg3false +Zip: [{"Field0": 1, "Field1": 2}, {"Field0": 3, "Field1": 4}, {"Field0": 5, "Field1": 6}] +Filter Iterator: 3 +Filter Iterator: 5 +Filter Iterator: 7 +Filter: [3, 5, 7] +FilterIt: [1, 3, 7] +Concat: [1, 3, 5, 7, 2, 4, 6] +Deduplicate: [1, 2, 3, 4, 5, 7] +@[()] +@[1, 42, 3] +@[1, 42, 3] +2345623456 +''' +""" + +block tseq2: + proc `*`(a, b: seq[int]): seq[int] = + # allocate a new sequence: + newSeq(result, len(a)) + # multiply two int sequences: + for i in 0..len(a)-1: result[i] = a[i] * b[i] + + assert(@[1, 2, 3] * @[1, 2, 3] == @[1, 4, 9]) + + + +block tseqcon: + const nestedFixed = true + + type + TRec {.final.} = object + x, y: int + s: string + seq: seq[string] + TRecSeq = seq[TRec] + + proc test() = + var s, b: seq[string] + s = @[] + add(s, "Hi") + add(s, "there, ") + add(s, "what's your name?") + + b = s # deep copying here! + b[0][1] = 'a' + + for i in 0 .. len(s)-1: + write(stdout, s[i]) + for i in 0 .. len(b)-1: + write(stdout, b[i]) + + when nestedFixed: + proc nested() = + var + s: seq[seq[string]] + for i in 0..10_000: # test if the garbage collector + # now works with sequences + s = @[ + @["A", "B", "C", "D"], + @["E", "F", "G", "H"], + @["I", "J", "K", "L"], + @["M", "N", "O", "P"]] + + test() + when nestedFixed: + nested() + echo "" + + + +import os +block tseqcon2: + proc rec_dir(dir: string): seq[string] = + result = @[] + for kind, path in walk_dir(dir): + if kind == pcDir: + add(result, rec_dir(path)) + else: + add(result, path) + + + +block tseqtuple: + type + TMsg = tuple[ + file: string, + line: int, + msg: string, + err: bool] + + var s: seq[TMsg] = @[] + + s.add(("fA", 13, "msg1", false)) + s.add(("fB", 14, "msg2", true)) + s.add(("fC", 15, "msg3", false)) + + for file, line, msg, err in items(s): + stdout.write(file) + stdout.write($line) + stdout.write(msg) + stdout.write($err) + echo "" + + +import sequtils, marshal +block tsequtils: + proc testFindWhere(item : int) : bool = + if item != 1: return true + + var seq1: seq[int] = @[] + + seq1.add(1) + seq1.add(3) + seq1.add(5) + seq1.add(7) + + var seq2: seq[int] = @[2, 4, 6] + var final = zip(seq1, seq2) + + echo "Zip: ", $$(final) + + #Test findWhere as a iterator + + for itms in filter(seq1, testFindWhere): + echo "Filter Iterator: ", $$(itms) + + + #Test findWhere as a proc + + var fullseq: seq[int] = filter(seq1, testFindWhere) + + echo "Filter: ", $$(fullseq) + + #Test findIt as a template + + var finditval: seq[int] = filterIt(seq1, it!=5) + + echo "FilterIt: ", $$(finditval) + + var concatseq = concat(seq1,seq2) + echo "Concat: ", $$(concatseq) + + var seq3 = @[1,2,3,4,5,5,5,7] + var dedupseq = deduplicate(seq3) + echo "Deduplicate: ", $$(dedupseq) + # bug #4973 + type + SomeObj = object + OtherObj = object + field: SomeObj + + let aSeq = @[OtherObj(field: SomeObj())] + let someObjSeq = aSeq.mapIt(it.field) + echo someObjSeq + + + +block tshallowseq: + proc xxx() = + var x: seq[int] = @[1, 2, 3] + var y: seq[int] + system.shallowCopy(y, x) + y[1] = 42 + echo y + echo x + xxx() + + +block tshallowemptyseq: + proc test() = + var nilSeq: seq[int] = @[] + var emptySeq: seq[int] = newSeq[int]() + block: + var t = @[1,2,3] + shallow(nilSeq) + t = nilSeq + doAssert t == @[] + block: + var t = @[1,2,3] + shallow(emptySeq) + t = emptySeq + doAssert t == @[] + block: + var t = @[1,2,3] + shallowCopy(t, nilSeq) + doAssert t == @[] + block: + var t = @[1,2,3] + shallowCopy(t, emptySeq) + doAssert t == @[] + test() + + +import strutils +block ttoseq: + for x in toSeq(countup(2, 6)): + stdout.write(x) + for x in items(toSeq(countup(2, 6))): + stdout.write(x) + var y: type("a b c".split) + y = "xzy" + stdout.write("\n") diff --git a/tests/collections/ttables.nim b/tests/collections/ttables.nim index 9b7506d1a..a59707865 100644 --- a/tests/collections/ttables.nim +++ b/tests/collections/ttables.nim @@ -173,19 +173,15 @@ block tableconstr: block ttables2: proc TestHashIntInt() = var tab = initTable[int,int]() - when defined(nimTestsTablesDisableSlow): - # helps every single time when this test needs to be debugged - let n = 1_000 - else: - let n = 1_000_000 + let n = 100_000 for i in 1..n: tab[i] = i for i in 1..n: var x = tab[i] if x != i : echo "not found ", i - proc run1() = # occupied Memory stays constant, but - for i in 1 .. 50: # aborts at run: 44 on win32 with 3.2GB with out of memory + proc run1() = + for i in 1 .. 50: TestHashIntInt() # bug #2107 |