diff options
author | Sébastien Dailly <sebastien@dailly.me> | 2022-02-24 08:59:44 +0100 |
---|---|---|
committer | Sébastien Dailly <sebastien@dailly.me> | 2022-02-24 13:39:39 +0100 |
commit | c2bd6982e5ed845293a38ae600c239cd50924d76 (patch) | |
tree | 4e68d4e7f9c2b9d5ae597f54961891332fc0e985 /motus/test | |
parent | 89dbb39c3fcd188ef7acf092061d756046b2c5d4 (diff) |
Update code, added tests
Diffstat (limited to 'motus/test')
-rw-r--r-- | motus/test/dune | 3 | ||||
-rw-r--r-- | motus/test/motus_test.ml | 51 |
2 files changed, 54 insertions, 0 deletions
diff --git a/motus/test/dune b/motus/test/dune new file mode 100644 index 0000000..04fe199 --- /dev/null +++ b/motus/test/dune @@ -0,0 +1,3 @@ +(test + (name motus_test) + (libraries ounit2 motus_lib)) diff --git a/motus/test/motus_test.ml b/motus/test/motus_test.ml new file mode 100644 index 0000000..4ea952e --- /dev/null +++ b/motus/test/motus_test.ml @@ -0,0 +1,51 @@ +module Validity = Motus_lib.Validity +open StdLabels +open OUnit2 + +let tests = + "validity test suite" + >::: [ ( "Sequence of elements" + >:: fun _ -> + assert_equal + 243 + ( Validity.sequence 5 + |> List.of_seq + |> List.sort_uniq ~cmp:Stdlib.compare + |> List.length ) ) + ; ( "Index of element" + >:: fun _ -> + assert_equal 0 Validity.(index_of_result [| Wellplaced; Wellplaced |]) + ) + ; ( "Bijection for all the elements" + >:: fun _ -> + (* Create an array of 243 elements*) + let arr = Array.make 243 false in + let seq = Validity.sequence 5 in + (* Populate the array *) + Seq.iter + (fun v -> + let idx = Validity.index_of_result v in + Array.set arr idx true ) + seq; + + (* Now count the elements set to true *) + let count = + Array.fold_left arr ~init:0 ~f:(fun acc value -> + if value then acc + 1 else acc ) + in + + assert_equal 243 count ) + ; ( "Compare words 1" + >:: fun _ -> + assert_equal + (Some Validity.[| Wellplaced; Wellplaced; Wellplaced; Wellplaced |]) + (Validity.compare_words "Test" ~ref:"Test") ) + ; ( "Compare words 2" + >:: fun _ -> + assert_equal + (Some Validity.[| Missing; Misplaced; Wellplaced |]) + (Validity.compare_words "DAC" ~ref:"ABC") ) + ] + + +let _ = run_test_tt_main tests |