blob: 45336bb7547c9866bd7dfdb172c0953ceaf1dd67 (
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
|
open OUnit2
open Vylist
(* Searching for an element that is there 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 there gives None *)
let test_find_nonexistent test_ctxt =
let xs = [1; 2; 4] in
assert_equal (find (fun x -> x = 3) xs) None
(* Removing a list that is there 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]
(* Removing an element that is already not there returns the same 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 nonexisten child rauses 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) (Some [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) (Some [3;4;5])
(* complement returns None 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) None
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;
]
let () =
run_test_tt_main suite
|