summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorDaniil Baturin <daniil@baturin.org>2015-04-24 11:16:49 +0600
committerDaniil Baturin <daniil@baturin.org>2015-04-24 11:16:49 +0600
commitf6fad748cd5e68c36d4ed55e76c020d10d9bb7bd (patch)
treecc74a8a55d2863b869c0fb1068a5f7b8d683425e /test
parenta15396525e442acc76cca061e0cbe1bc98af83d0 (diff)
downloadvyconf-f6fad748cd5e68c36d4ed55e76c020d10d9bb7bd.tar.gz
vyconf-f6fad748cd5e68c36d4ed55e76c020d10d9bb7bd.zip
Add Vylist.complement for calculating difference between two lists
where one contains another (starting with the first element).
Diffstat (limited to 'test')
-rw-r--r--test/vylist_test.ml17
1 files changed, 17 insertions, 0 deletions
diff --git a/test/vylist_test.ml b/test/vylist_test.ml
index c27aa5c..45336bb 100644
--- a/test/vylist_test.ml
+++ b/test/vylist_test.ml
@@ -41,6 +41,20 @@ 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;
@@ -51,6 +65,9 @@ let suite =
"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 () =