summary refs log tree commit diff stats
path: root/tests
diff options
context:
space:
mode:
authorMatt Wilson <matt@culturethree.com>2023-05-12 18:02:09 +1200
committerGitHub <noreply@github.com>2023-05-12 14:02:09 +0800
commitea39c600abcb8853791404145c3038ea9488d0f4 (patch)
tree136b94bf1d92bfad7e2eb57405b569cb035dbd68 /tests
parent9810b8cf7ff85a306699d8393ce516501d938e05 (diff)
downloadNim-ea39c600abcb8853791404145c3038ea9488d0f4.tar.gz
Add `minmax` to comparisons (#21820)
* Add `minmax` to sequtils

This adds a `minmax` proc to complement `min` and `max`; it computes
both results in a single pass for efficiency.

* Update lib/pure/collections/sequtils.nim

* Add minmax note to changelog.

---------

Co-authored-by: Andreas Rumpf <rumpf_a@web.de>
Diffstat (limited to 'tests')
-rw-r--r--tests/collections/tseq.nim8
1 files changed, 8 insertions, 0 deletions
diff --git a/tests/collections/tseq.nim b/tests/collections/tseq.nim
index 39f066f4c..5fca784e7 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: