aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBruce Hill <bruce@bruce-hill.com>2024-08-15 14:01:36 -0400
committerBruce Hill <bruce@bruce-hill.com>2024-08-15 14:01:36 -0400
commitce6f312c94970f1aba112f5bfbe58512fbf3a5e1 (patch)
tree4206d49487309d614b587353c1e14d8e94d8105e
parent7c18773011aa8eaaedb9bbde6884ee7e92585fea (diff)
Add binary search test
-rw-r--r--test/arrays.tm9
1 files changed, 9 insertions, 0 deletions
diff --git a/test/arrays.tm b/test/arrays.tm
index 2b5a8474..c870ce04 100644
--- a/test/arrays.tm
+++ b/test/arrays.tm
@@ -149,3 +149,12 @@ func main():
for i,x in xs:to(-2):
for y in xs:from(i+1):
say("{x}{y}")
+
+ do:
+ >> nums := [-7, -4, -1, 2, 5]
+ >> nums:sort()
+ >> [nums:binary_search(i) for i in nums]
+ = [1, 2, 3, 4, 5]
+ >> nums:sort(func(a,b:&%Int): a:abs() <> b:abs())
+ >> [nums:binary_search(i, func(a,b:&Int): a:abs() <> b:abs()) for i in nums]
+ = [1, 2, 3, 4, 5]