aboutsummaryrefslogtreecommitdiff
path: root/motus/test/motus_test.ml
blob: 0586ffe9eb0d7c8faca34b5d1e8e54740e5b26fa (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
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 _ ->
         let w = "Test" in

         let ref = (w, Validity.CharSet.of_seq (String.to_seq w)) in

         assert_equal
           (Some Validity.[| Wellplaced; Wellplaced; Wellplaced; Wellplaced |])
           (Validity.compare_words "Test" ~ref) )
       ; ( "Compare words 2"
         >:: fun _ ->
         let w = "ABC" in
         let ref = (w, Validity.CharSet.of_seq (String.to_seq w)) in
         assert_equal
           (Some Validity.[| Missing; Misplaced; Wellplaced |])
           (Validity.compare_words "DAC" ~ref) )
       ]


let _ = run_test_tt_main tests