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

mbarbin / catch-the-bunny / 38

10 Feb 2024 09:00AM UTC coverage: 97.642% (+2.1%) from 95.588%
38

push

github

mbarbin
Tweak coverage tests

207 of 212 relevant lines covered (97.64%)

200505.99 hits per line

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

91.43
/src/status_line.ml
1
module May_be_located = struct
2
  type t = bool array
3

4
  let sexp_of_t t =
5
    Sexp.Atom (String.init (Array.length t) ~f:(fun i -> if t.(i) then '1' else '0'))
111✔
6
  ;;
7
end
8

9
type t =
111✔
10
  { code : int
111✔
11
  ; may_be_located : May_be_located.t
111✔
12
  }
13
[@@deriving sexp_of]
14

15
let equal t1 t2 = t1.code = t2.code
1✔
16
let compare t1 t2 = Int.compare t1.code t2.code
9,187✔
17
let code t = t.code
6,471,936✔
18

19
let compute_code ~may_be_located =
20
  Array.fold may_be_located ~init:0 ~f:(fun acc j -> (2 * acc) + if j then 1 else 0)
15,892✔
21
;;
22

23
let create ~size ~code =
24
  if code < 0 then raise_s [%sexp "invalid negative code", { size : int; code : int }];
×
25
  let may_be_located = Array.create ~len:size false in
1,230✔
26
  let rec aux i code =
1,229✔
27
    if i >= 0 && i < size
9,393✔
28
    then (
9,393✔
29
      may_be_located.(i) <- code % 2 = 1;
9,393✔
30
      aux (i - 1) (code / 2))
9,393✔
31
    else code
1,229✔
32
  in
33
  let remainder = aux (size - 1) code in
34
  if remainder <> 0 then raise_s [%sexp "code out of bounds", { size : int; code : int }];
×
35
  let code' = compute_code ~may_be_located in
1,228✔
36
  if code <> code'
37
  then
38
    raise_s
39
      [%sexp "code does not round trip", { code : int; code' : int }] [@coverage off];
40
  { code; may_be_located }
1,228✔
41
;;
42

43
let size t = Array.length t.may_be_located
14,666✔
44

45
let remove t ~index =
46
  let size = size t in
7,344✔
47
  let may_be_located = Array.copy t.may_be_located in
7,344✔
48
  if index >= 0 && index < size
7,343✔
49
  then may_be_located.(index) <- false
7,342✔
50
  else raise_s [%sexp "index out of bounds", { size : int; index : int }];
×
51
  { code = compute_code ~may_be_located; may_be_located }
52
;;
53

54
let move t =
55
  let size = size t in
7,322✔
56
  let may_be_located = Array.create ~len:size false in
7,322✔
57
  for i = 0 to Int.pred size do
7,322✔
58
    if t.may_be_located.(i)
56,152✔
59
    then
60
      Array.iter [| -1; 1 |] ~f:(fun j ->
24,421✔
61
        let index = i + j in
48,842✔
62
        if index >= 0 && index < size then may_be_located.(index) <- true)
42,487✔
63
  done;
64
  { code = compute_code ~may_be_located; may_be_located }
65
;;
66

67
let catch_the_bunny t =
68
  if 1 = Array.count t.may_be_located ~f:Fn.id
340✔
69
  then Array.find_mapi t.may_be_located ~f:(fun i b -> Option.some_if b i)
16✔
70
  else None
324✔
71
;;
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

© 2025 Coveralls, Inc