summaryrefslogtreecommitdiff
path: root/lib/std/test/search.myr
diff options
context:
space:
mode:
Diffstat (limited to 'lib/std/test/search.myr')
-rw-r--r--lib/std/test/search.myr34
1 files changed, 34 insertions, 0 deletions
diff --git a/lib/std/test/search.myr b/lib/std/test/search.myr
new file mode 100644
index 0000000..342a406
--- /dev/null
+++ b/lib/std/test/search.myr
@@ -0,0 +1,34 @@
+use std
+
+const sl = [1, 3, 5, 8, 9, 33]
+
+const main = {
+
+ expect(std.lsearch(sl[:], 1, std.numcmp), `std.Some 0)
+ expect(std.lsearch(sl[:], 33, std.numcmp), `std.Some sl.len - 1)
+ expect(std.lsearch(sl[:], 5, std.numcmp), `std.Some 2)
+ expect(std.lsearch(sl[:], 6, std.numcmp), `std.None)
+
+ expect(std.bsearch(sl[:], 1, std.numcmp), `std.Some 0)
+ expect(std.bsearch(sl[:], 33, std.numcmp), `std.Some sl.len - 1)
+ expect(std.bsearch(sl[:], 5, std.numcmp), `std.Some 2)
+ expect(std.bsearch(sl[:], 6, std.numcmp), `std.None)
+}
+
+const expect = {a, b
+ match a
+ | `std.None:
+ match b
+ | `std.Some x: std.fatal("Expected `std.None, `std.None, got `std.None, `std.Some %i\n", x)
+ | `std.None: /* nothing */
+ ;;
+ | `std.Some x:
+ match b
+ | `std.None: std.fatal("Expected `std.Some %i, `std.Some %i, got `std.Some %i, `std.None\n", x, x, x)
+ | `std.Some y:
+ if x != y
+ std.fatal("Expected `std.Some %i, `std.Some %i, got `std.Some %i, `std.Some %i\n", x, x, x, y)
+ ;;
+ ;;
+ ;;
+}