summaryrefslogtreecommitdiff
path: root/libstd/test/search.myr
blob: 342a40620c5cad0b43084f389763b428e24ba813 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
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)
			;;
		;;
	;;
}