From 84b8439aa90f1465d05dcba936a25eaf96f914a0 Mon Sep 17 00:00:00 2001 From: Sébastien Dailly Date: Sat, 26 Feb 2022 13:42:32 +0100 Subject: Use the whole dictionnary when searching for a word for a faster exploration --- motus/test/entropy_tests.ml | 40 ++++++++++++++++++++++++++++++++++++++++ motus/test/motus_test.ml | 23 ++++------------------- 2 files changed, 44 insertions(+), 19 deletions(-) create mode 100644 motus/test/entropy_tests.ml (limited to 'motus/test') diff --git a/motus/test/entropy_tests.ml b/motus/test/entropy_tests.ml new file mode 100644 index 0000000..675d5b5 --- /dev/null +++ b/motus/test/entropy_tests.ml @@ -0,0 +1,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 ) + ] diff --git a/motus/test/motus_test.ml b/motus/test/motus_test.ml index 0586ffe..717db21 100644 --- a/motus/test/motus_test.ml +++ b/motus/test/motus_test.ml @@ -1,8 +1,8 @@ -module Validity = Motus_lib.Validity open StdLabels open OUnit2 +open Motus_lib -let tests = +let validiy_tests = "validity test suite" >::: [ ( "Sequence of elements" >:: fun _ -> @@ -35,23 +35,8 @@ let tests = 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 +let _ = + run_test_tt_main ("main tests" >::: [ validiy_tests; Entropy_tests.tests ]) -- cgit v1.2.3