summary refs log tree commit diff stats
path: root/tests/collections/tseq.nim
diff options
context:
space:
mode:
Diffstat (limited to 'tests/collections/tseq.nim')
-rw-r--r--tests/collections/tseq.nim106
1 files changed, 66 insertions, 40 deletions
diff --git a/tests/collections/tseq.nim b/tests/collections/tseq.nim
index 263a571bf..0f8084c78 100644
--- a/tests/collections/tseq.nim
+++ b/tests/collections/tseq.nim
@@ -1,4 +1,5 @@
 discard """
+  matrix: "--mm:refc; --mm:orc"
   output: '''
 Hithere, what's your name?Hathere, what's your name?
 fA13msg1falsefB14msg2truefC15msg3false
@@ -11,8 +12,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]
+Minmax: (1, 7)
 2345623456
 '''
 """
@@ -24,7 +24,7 @@ block tseq2:
     # 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])
+  doAssert(@[1, 2, 3] * @[1, 2, 3] == @[1, 4, 9])
 
 
 
@@ -157,42 +157,51 @@ block tsequtils:
   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()
+  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:
+    proc xxx() =
+      var x: seq[int] = @[1, 2, 3]
+      var y: seq[int]
+      system.shallowCopy(y, x)
+      y[1] = 42
+      doAssert y == @[1, 42, 3]
+      doAssert x == @[1, 42, 3]
+    xxx()
+
+
+  block tshallowemptyseq:
+    proc test() =
+      var nilSeq: seq[int] = @[]
+      var emptySeq: seq[int] = newSeq[int]()
+      block:
+        var t = @[1,2,3]
+        when defined(gcRefc):
+          shallow(nilSeq)
+        t = nilSeq
+        doAssert t == @[]
+      block:
+        var t = @[1,2,3]
+        when defined(gcRefc):
+          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
@@ -201,7 +210,7 @@ block ttoseq:
     stdout.write(x)
   for x in items(toSeq(countup(2, 6))):
     stdout.write(x)
-  var y: type("a b c".split)
+  var y: typeof("a b c".split)
   y = "xzy"
   stdout.write("\n")
 
@@ -214,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)