From ce6f312c94970f1aba112f5bfbe58512fbf3a5e1 Mon Sep 17 00:00:00 2001 From: Bruce Hill Date: Thu, 15 Aug 2024 14:01:36 -0400 Subject: [PATCH] Add binary search test --- test/arrays.tm | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/test/arrays.tm b/test/arrays.tm index 2b5a847..c870ce0 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]