aboutsummaryrefslogtreecommitdiff
path: root/motus/test/entropy_tests.ml
blob: 675d5b5dd7d95e7ece8b02e46255d924f20c4a53 (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
open StdLabels
open OUnit2
open Motus_lib

let format_validity = function
  | Validity.Wellplaced -> 'W'
  | Validity.Misplaced -> 'M'
  | Validity.Missing -> '_'


let printer : Validity.t array option -> string = function
  | None -> ""
  | Some v ->
      String.init (Array.length v) ~f:(fun i ->
          format_validity @@ Array.get v i )


let tests =
  "entropy test suite"
  >::: [ ( "Compare words 1"
         >:: fun _ ->
         let w = "Test" in

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

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

         assert_equal
           ~printer
           (Some Validity.[| Missing; Misplaced; Wellplaced |])
           result )
       ]