From 6d6b9e94100a0ceeb72c7b030f9ae871087f6889 Mon Sep 17 00:00:00 2001 From: Daniil Baturin Date: Wed, 4 Mar 2015 22:24:09 +0600 Subject: Add some tests for the vylist module. --- _oasis | 14 ++++++++++++++ test/vylist_test.ml | 37 +++++++++++++++++++++++++++++++++++++ 2 files changed, 51 insertions(+) create mode 100644 test/vylist_test.ml 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 + -- cgit v1.2.3