• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

mbarbin / super-master-mind / 116

22 Aug 2024 10:20AM UTC coverage: 96.343% (-0.2%) from 96.56%
116

push

github

mbarbin
Fix test coverage

843 of 875 relevant lines covered (96.34%)

3354487.23 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

90.63
/lib/super_master_mind/src/example.ml
1
let solve ~task_pool ~color_permutation ~solution =
2
  let steps = Queue.create () in
3✔
3
  let step_index = ref 0 in
3✔
4
  let add (t : Guess.t) ~by_cue =
5
    let by_cue =
16✔
6
      Nonempty_list.singleton
7
        { by_cue with Guess.By_cue.next_best_guesses = Not_computed }
8
    in
9
    let t = { t with by_cue } in
16✔
10
    Queue.enqueue steps t;
11
    Int.incr step_index;
16✔
12
    print_s [%sexp (!step_index : int), (t : Guess.t)]
16✔
13
  in
14
  let rec aux (t : Guess.t) ~possible_solutions =
15
    let cue = Code.analyze ~solution ~candidate:t.candidate in
13✔
16
    let by_cue =
17
      Nonempty_list.find t.by_cue ~f:(fun by_cue -> Cue.equal cue by_cue.cue)
73✔
18
      |> Option.value_exn ~here:[%here]
13✔
19
    in
20
    add t ~by_cue;
13✔
21
    let possible_solutions =
13✔
22
      Codes.filter possible_solutions ~candidate:t.candidate ~cue
23
    in
24
    if Codes.size possible_solutions = 1
13✔
25
    then (
3✔
26
      let solution = List.hd_exn (Codes.to_list possible_solutions) in
3✔
27
      let guess = Guess.compute ~possible_solutions ~candidate:solution in
3✔
28
      add guess ~by_cue:(Nonempty_list.hd guess.by_cue))
3✔
29
    else (
10✔
30
      match by_cue.next_best_guesses with
31
      | Computed [] -> ()
×
32
      | Computed (guess :: _) -> aux guess ~possible_solutions
6✔
33
      | Not_computed ->
4✔
34
        (match Guess.compute_k_best ~task_pool ~possible_solutions ~k:1 () with
35
         | [] -> ()
×
36
         | guess :: _ -> aux guess ~possible_solutions))
4✔
37
  in
38
  let opening_book = Lazy.force Opening_book.opening_book in
39
  let root =
3✔
40
    Opening_book.root opening_book ~color_permutation:(force color_permutation)
3✔
41
  in
42
  aux root ~possible_solutions:Codes.all;
3✔
43
  Queue.to_list steps
3✔
44
;;
45

46
let cmd =
47
  Command.make
19✔
48
    ~summary:"run through an example"
49
    (let%map_open.Command solution =
50
       Arg.named_opt
19✔
51
         [ "solution" ]
52
         Code.param
53
         ~doc:"CODE chosen solution (default is arbitrary)"
54
     and task_pool_config = Task_pool.Config.arg in
55
     Task_pool.with_t task_pool_config ~f:(fun ~task_pool ->
1✔
56
       let solution =
1✔
57
         match solution with
58
         | Some solution -> solution
1✔
59
         | None -> Code.create_exn [| Green; Blue; Orange; White; Red |]
×
60
       in
61
       ignore
62
         (solve ~task_pool ~color_permutation:Color_permutation.identity ~solution
63
          : Guess.t list)))
64
;;
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc