blob: c6bd993e04ecce83547c8b6df46a8bbdf525a4cb (
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
|
open OUnit2
open Vylist
(* Searching for an element that is in the list gives Some that_element *)
let test_find_existent test_ctxt =
let xs = [1; 2; 3; 4] in
assert_equal (find (fun x -> x = 3) xs) (Some 3)
(* Searching for an element that is not in the list gives None *)
let test_find_nonexistent test_ctxt =
let xs = [1; 2; 4] in
assert_equal (find (fun x -> x = 3) xs) None
(* Removing an element that exists in the list makes a list without that element *)
let test_remove_existent test_ctct =
let xs = [1; 2; 3; 4] in
assert_equal (remove (fun x -> x = 3) xs) [1; 2; 4]
(* Trying to remove an element that is not in the list doesn't change the list *)
let test_remove_nonexistent test_ctct =
let xs = [1; 2; 4] in
assert_equal (remove (fun x -> x = 3) xs) [1; 2; 4]
(* Replacing an element works *)
let test_replace_element_existent test_ctxt =
let xs = [1; 2; 3; 4] in
assert_equal (replace ((=) 3) 7 xs) [1; 2; 7; 4]
(* Attempt to replace a nonexistent element causes an exception *)
let test_replace_element_nonexistent test_ctxt =
let xs = [1; 2; 3] in
assert_raises Not_found (fun () -> replace ((=) 4) 7 xs)
(* insert_before works if the element is there *)
let test_insert_before_existent test_ctxt =
let xs = [1; 2; 3] in
assert_equal (insert_before ((=) 2) 7 xs) [1; 7; 2; 3]
(* insert_before raises Not_found if there's not such element *)
let test_insert_before_nonexistent test_ctxt =
let xs = [1; 2; 3] in
assert_raises Not_found (fun () -> insert_before ((=) 9) 7 xs)
(* complement returns correct result when one list contains another, in any order *)
let test_complement_first_is_longer test_ctxt =
let xs = [1; 2; 3; 4; 5] and ys = [1; 2; 3] in
assert_equal (complement xs ys) [4; 5]
let test_complement_second_is_longer test_ctxt =
let xs = [1; 2] and ys = [1; 2; 3; 4; 5] in
assert_equal (complement xs ys) [3; 4; 5]
(* complement returns an empty list if one list doesn't contain another *)
let test_complement_doesnt_contain test_ctxt =
let xs = [1; 2; 3] and ys = [1; 4; 5; 6] in
assert_equal (complement xs ys) []
(* in_list works *)
let test_in_list test_ctxt =
let xs = [1; 2; 3; 4] in
assert_equal (in_list xs 3) true;
assert_equal (in_list xs 9) false
let suite =
"VyConf list tests" >::: [
"test_find_existent" >:: test_find_existent;
"test_find_nonexistent" >:: test_find_nonexistent;
"test_remove_existent" >:: test_remove_existent;
"test_remove_nonexistent" >:: test_remove_nonexistent;
"test_replace_element_existent" >:: test_replace_element_existent;
"test_replace_element_nonexistent" >:: test_replace_element_nonexistent;
"test_insert_before_existent" >:: test_insert_before_existent;
"test_insert_before_nonexistent" >:: test_insert_before_nonexistent;
"test_complement_first_is_longer" >:: test_complement_first_is_longer;
"test_complement_second_is_longer" >:: test_complement_second_is_longer;
"test_complement_doesnt_contain" >:: test_complement_doesnt_contain;
"test_in_list" >:: test_in_list;
]
let () =
run_test_tt_main suite
|