-
Notifications
You must be signed in to change notification settings - Fork 1
/
test_bitset.ml
49 lines (42 loc) · 1.56 KB
/
test_bitset.ml
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
open Bitset
let () = assert (cardinal full = Sys.int_size)
let () = assert (max_elt full = Sys.int_size - 1)
let () = assert (max_elt full = max_value)
let () = assert (min_elt full = 0)
let () = assert (union full full = full)
let () = assert (union empty full = full)
let () = assert (inter full full = full)
let () = assert (inter full empty = empty)
let () = assert (diff empty full = empty)
let () = assert (diff full empty = full)
let () = assert (disjoint empty full)
let () = assert (find_first (fun x -> x > 10) full = 11)
let () = assert (find_last (fun x -> x > 10) full = Sys.int_size - 1)
let testl l =
let s = List.fold_left (fun s x -> add x s) empty l in
assert (cardinal s = List.length l);
List.iter (fun x -> assert (mem x s)) l;
assert (min_elt s = List.fold_left min (List.hd l) l);
assert (max_elt s = List.fold_left max (List.hd l) l);
assert (of_seq (List.to_seq l) = s);
assert (inter s s = s);
assert (union s s = s);
assert (diff s s = empty);
assert (disjoint empty s);
assert (List.of_seq (to_seq s) = l);
assert (List.of_seq (to_rev_seq s) = List.rev l);
()
let () =
let f i = if i mod 2 = 0 && i >= 2 then Some (i-1) else None in
let s = filter_map f full in
assert (cardinal s = Sys.int_size / 2);
for i = 0 to Sys.int_size - 1 do
if i land 1 = 1 then assert (mem i s) else assert (not (mem i s))
done
let () = testl [1; 3; 8; 11]
let () = testl [2; 3; 4; 5]
let () = testl [62]
let () = testl [0; 62]
let () = testl [60; 61; 62]
let () = assert (to_seq empty () = Seq.Nil)
let () = assert (to_rev_seq empty () = Seq.Nil)