summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--_oasis14
-rw-r--r--test/vylist_test.ml37
2 files changed, 51 insertions, 0 deletions
diff --git a/_oasis b/_oasis
index 17612e7..f13a146 100644
--- a/_oasis
+++ b/_oasis
@@ -28,8 +28,22 @@ Executable "vyconf_tree_test"
Install: false
BuildDepends: oUnit, vytree
+Executable "vylist_test"
+ Path: test
+ MainIs: vylist_test.ml
+ Build$: flag(tests)
+ CompiledObject: best
+ Install: false
+ BuildDepends: oUnit
+
Test "vyconf_tree_test"
Run$: flag(tests)
TestTools: vyconf_tree_test
Command: $vyconf_tree_test
WorkingDirectory: test
+
+Test "vylist_test"
+ Run$: flag(tests)
+ TestTools: vylist_test
+ Command: $vylist_test
+ WorkingDirectory: test
diff --git a/test/vylist_test.ml b/test/vylist_test.ml
new file mode 100644
index 0000000..3f702ed
--- /dev/null
+++ b/test/vylist_test.ml
@@ -0,0 +1,37 @@
+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 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;
+ ]
+
+let () =
+ run_test_tt_main suite
+