diff options
| author | Bruce Hill <bruce@bruce-hill.com> | 2024-08-15 14:01:36 -0400 |
|---|---|---|
| committer | Bruce Hill <bruce@bruce-hill.com> | 2024-08-15 14:01:36 -0400 |
| commit | ce6f312c94970f1aba112f5bfbe58512fbf3a5e1 (patch) | |
| tree | 4206d49487309d614b587353c1e14d8e94d8105e | |
| parent | 7c18773011aa8eaaedb9bbde6884ee7e92585fea (diff) | |
Add binary search test
| -rw-r--r-- | test/arrays.tm | 9 |
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] |
