diff options
Diffstat (limited to 'tests/collections')
-rw-r--r-- | tests/collections/tactiontable.nim | 37 | ||||
-rw-r--r-- | tests/collections/tseq.nim | 31 | ||||
-rw-r--r-- | tests/collections/ttables.nim | 7 |
3 files changed, 68 insertions, 7 deletions
diff --git a/tests/collections/tactiontable.nim b/tests/collections/tactiontable.nim new file mode 100644 index 000000000..3f15a70bd --- /dev/null +++ b/tests/collections/tactiontable.nim @@ -0,0 +1,37 @@ +discard """ + output: ''' +action 3 arg +action 3 arg +''' +""" + +import tables + +proc action1(arg: string) = + echo "action 1 ", arg + +proc action2(arg: string) = + echo "action 2 ", arg + +proc action3(arg: string) = + echo "action 3 ", arg + +proc action4(arg: string) = + echo "action 4 ", arg + +var + actionTable1 = { + "A": action1, + "B": action2, + "C": action3, + "D": action4}.toTable + +const + actionTable2 = { + "A": action1, + "B": action2, + "C": action3, + "D": action4}.toTable + +actionTable1["C"]("arg") +actionTable2["C"]("arg") diff --git a/tests/collections/tseq.nim b/tests/collections/tseq.nim index c4dd40052..0f8084c78 100644 --- a/tests/collections/tseq.nim +++ b/tests/collections/tseq.nim @@ -12,6 +12,7 @@ FilterIt: [1, 3, 7] Concat: [1, 3, 5, 7, 2, 4, 6] Deduplicate: [1, 2, 3, 4, 5, 7] @[()] +Minmax: (1, 7) 2345623456 ''' """ @@ -156,6 +157,13 @@ block tsequtils: let someObjSeq = aSeq.mapIt(it.field) echo someObjSeq + block minmax: + doAssert minmax(@[0]) == (0, 0) + doAssert minmax(@[0, 1]) == (0, 1) + doAssert minmax(@[1, 0]) == (0, 1) + doAssert minmax(@[8,2,1,7,3,9,4,0,5]) == (0, 9) + echo "Minmax: ", $(minmax(concat(seq1, seq2))) + when not defined(nimseqsv2): block tshallowseq: @@ -175,12 +183,14 @@ when not defined(nimseqsv2): var emptySeq: seq[int] = newSeq[int]() block: var t = @[1,2,3] - shallow(nilSeq) + when defined(gcRefc): + shallow(nilSeq) t = nilSeq doAssert t == @[] block: var t = @[1,2,3] - shallow(emptySeq) + when defined(gcRefc): + shallow(emptySeq) t = emptySeq doAssert t == @[] block: @@ -213,3 +223,20 @@ for i in 0..100: var test = newSeqOfCap[uint32](1) test.setLen(1) doAssert test[0] == 0, $(test[0], i) + + +# bug #22560 +doAssert len(newSeqOfCap[int](42)) == 0 + +block: # bug #17197 + type Matrix = seq[seq[int]] + + proc needlemanWunsch(sequence1: string, sequence2: string, gap_penal: int8, match: int8, indel_penal: int8): bool = + let seq2_len = sequence2.len + + var grid: Matrix + for i in sequence1: + grid.add(newSeqOfCap[seq[int]](seq2_len)) + result = true + + doAssert needlemanWunsch("ABC", "DEFG", 1, 2, 3) diff --git a/tests/collections/ttables.nim b/tests/collections/ttables.nim index 638f4241b..95f9418a0 100644 --- a/tests/collections/ttables.nim +++ b/tests/collections/ttables.nim @@ -177,16 +177,14 @@ block tableconstr: block ttables2: proc TestHashIntInt() = var tab = initTable[int,int]() - let n = 100_000 + let n = 10 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() = - for i in 1 .. 50: - TestHashIntInt() + TestHashIntInt() # bug #2107 @@ -198,7 +196,6 @@ block ttables2: delTab[5] = 5 - run1() echo "2" block tablesref: |