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

mbarbin / super-master-mind / 217

31 Jan 2026 12:24PM UTC coverage: 50.206% (-38.1%) from 88.313%
217

Pull #45

github

web-flow
Merge 235b668da into 3d48eb3d9
Pull Request #45: Dune pkg ci migration

610 of 1215 relevant lines covered (50.21%)

597078.5 hits per line

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

52.0
/src/codes.ml
1
(*********************************************************************************)
2
(*  super-master-mind: A solver for the super master mind game                   *)
3
(*  SPDX-FileCopyrightText: 2021-2025 Mathieu Barbin <mathieu.barbin@gmail.com>  *)
4
(*  SPDX-License-Identifier: MIT                                                 *)
5
(*********************************************************************************)
6

7
type t =
8
  | All
9
  | Only of { codes : Code.t list }
10

11
let to_dyn = function
12
  | All -> Dyn.variant "All" []
×
13
  | Only { codes } -> Dyn.variant "Only" [ Dyn.list Code.to_dyn codes ]
×
14
;;
15

16
let all = All
17

18
let size = function
19
  | All -> Lazy.force Code.cardinality
3✔
20
  | Only { codes } -> List.length codes
101,706✔
21
;;
22

23
let bits t = Float.log2 (Float.of_int (size t))
×
24

25
let is_empty = function
26
  | All -> false
3✔
27
  | Only { codes } -> List.is_empty codes
101,665✔
28
;;
29

30
let all_as_list =
31
  lazy
32
    (let code_cardinality = Lazy.force Code.cardinality in
×
33
     let rec aux acc i =
×
34
       if i < code_cardinality
×
35
       then (
×
36
         let acc = Code.of_index_exn i :: acc in
×
37
         aux acc (Int.succ i))
×
38
       else acc
×
39
     in
40
     List.rev (aux [] 0))
×
41
;;
42

43
let to_list = function
44
  | All -> Lazy.force all_as_list
×
45
  | Only { codes } -> codes
2✔
46
;;
47

48
let iter t ~f =
49
  match t with
102,360✔
50
  | All ->
54✔
51
    for i = 0 to Lazy.force Code.cardinality - 1 do
54✔
52
      f (Code.of_index_exn i)
1,442,432✔
53
    done
54
  | Only { codes } -> List.iter codes ~f
102,328✔
55
;;
56

57
let filter t ~candidate ~cue =
58
  let keep = ref [] in
605✔
59
  iter t ~f:(fun solution ->
60
    if Cue.equal cue (Code.analyze ~solution ~candidate) then keep := solution :: !keep);
137,662✔
61
  Only { codes = List.rev !keep }
605✔
62
;;
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