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

mbarbin / fingerboard / 118

23 Dec 2025 10:30PM UTC coverage: 92.134% (-3.0%) from 95.087%
118

Pull #11

github

web-flow
Merge b17e74f06 into ccb9da732
Pull Request #11: Reduce deps

323 of 528 new or added lines in 29 files covered. (61.17%)

1 existing line in 1 file now uncovered.

3830 of 4157 relevant lines covered (92.13%)

20265.99 hits per line

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

88.89
/src/stdlib/fingerboard_stdlib.ml
1
(**********************************************************************************)
2
(*  Fingerboard - a microtonal geography of the cello fingerboard                 *)
3
(*  Copyright (C) 2022-2024 Mathieu Barbin <mathieu.barbin@gmail.com>             *)
4
(*                                                                                *)
5
(*  This file is part of Fingerboard.                                             *)
6
(*                                                                                *)
7
(*  Fingerboard is free software: you can redistribute it and/or modify it under  *)
8
(*  the terms of the GNU Affero General Public License as published by the Free   *)
9
(*  Software Foundation, either version 3 of the License, or any later version.   *)
10
(*                                                                                *)
11
(*  Fingerboard is distributed in the hope that it will be useful, but WITHOUT    *)
12
(*  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or         *)
13
(*  FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License   *)
14
(*  for more details.                                                             *)
15
(*                                                                                *)
16
(*  You should have received a copy of the GNU Affero General Public License      *)
17
(*  along with Fingerboard. If not, see <https://www.gnu.org/licenses/>.          *)
18
(**********************************************************************************)
19

20
(* Some functions are copied from [Base] version [v0.17] which is released
21
   under MIT and may be found at [https://github.com/janestreet/base].
22

23
   See Base's LICENSE below:
24

25
   ----------------------------------------------------------------------------
26

27
   The MIT License
28

29
   Copyright (c) 2016--2024 Jane Street Group, LLC <opensource-contacts@janestreet.com>
30

31
   Permission is hereby granted, free of charge, to any person obtaining a copy
32
   of this software and associated documentation files (the "Software"), to deal
33
   in the Software without restriction, including without limitation the rights
34
   to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
35
   copies of the Software, and to permit persons to whom the Software is
36
   furnished to do so, subject to the following conditions:
37

38
   The above copyright notice and this permission notice shall be included in all
39
   copies or substantial portions of the Software.
40

41
   THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
42
   IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
43
   FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
44
   AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
45
   LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
46
   OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
47
   SOFTWARE.
48

49
   ----------------------------------------------------------------------------
50

51
   When this is the case, we clearly indicate it next to the copied function. *)
52

53
module Code_error = Code_error
54
module Dyn = Dyn0
55
module Ordering = Ordering
56

57
let print pp = Format.printf "%a@." Pp.to_fmt pp
480✔
58
let print_dyn dyn = print (Dyn.pp dyn)
480✔
59
let phys_equal a b = a == b
177,324✔
60

61
module Array = struct
62
  include Stdlib.ArrayLabels
63

64
  let create ~len a = make len a
118✔
65
  let exists t ~f = exists ~f t
76✔
66
  let iter t ~f = iter ~f t
20,240✔
67
  let fold t ~init ~f = fold_left t ~init ~f
42✔
68
  let map t ~f = map ~f t
1,561✔
69

70
  let rev t =
71
    let len = Array.length t in
42✔
72
    let pred_len = pred len in
42✔
73
    init len ~f:(fun i -> t.(pred_len - i))
42✔
74
  ;;
75
end
76

77
module Bool = struct
78
  include Stdlib.Bool
79

80
  let compare a b = Ordering.of_int (Bool.compare a b)
38✔
81
end
82

83
module Float = struct
84
  include Stdlib.Float
85

86
  let compare a b = Ordering.of_int (Float.compare a b)
368,822✔
87

88
  let iround_nearest_exn f =
89
    let i = Int.of_float f in
17,068✔
90
    if i >= 0
17,068✔
91
    then (
17,066✔
92
      match compare (f -. Int.to_float i) 0.5 with
17,066✔
93
      | Gt -> i + 1
7,855✔
NEW
94
      | Eq | Lt -> i)
×
95
    else (
2✔
96
      match compare (Int.to_float i -. f) 0.5 with
2✔
97
      | Gt -> i - 1
1✔
NEW
98
      | Eq | Lt -> i)
×
99
  ;;
100
end
101

102
module Int = struct
103
  include Stdlib.Int
104

105
  let compare a b = Ordering.of_int (Int.compare a b)
698,041✔
106
  let incr = Stdlib.incr
107
end
108

109
module List = struct
110
  include Stdlib.ListLabels
111

112
  let filter t ~f = filter ~f t
6✔
113
  let filter_map t ~f = filter_map ~f t
2✔
114
  let init len ~f = init ~len ~f
2,025,499✔
115
  let iter t ~f = iter ~f t
176✔
116
  let map t ~f = map ~f t
226,465✔
117
  let mapi t ~f = mapi ~f t
21✔
118
  let partition t ~f = partition ~f t
1,521✔
119

120
  let reduce t ~f =
121
    match t with
1,999,696✔
NEW
122
    | [] -> None
×
123
    | hd :: tl -> Some (Stdlib.ListLabels.fold_left tl ~init:hd ~f)
1,999,696✔
124
  ;;
125

126
  let sort t ~compare = sort ~cmp:(fun a b -> compare a b |> Ordering.to_int) t
2,877✔
127

128
  (* ---------------------------------------------------------------------------- *)
129
  (* [groupi] and [group] are copied from [Base] (MIT). See notice at the top of
130
     the file and project global notice for licensing information. *)
131
  let groupi l ~break =
132
    (* We allocate shared position and list references so we can make the inner loop use
133
       [[@tail_mod_cons]], and still return back information about position and where in the
134
       list we left off. *)
135
    let pos = ref 0 in
105✔
136
    let l = ref l in
137
    (* As a result of using local references, our inner loop does not need arguments. *)
138
    let[@tail_mod_cons] rec take_group () =
139
      match !l with
2,850✔
NEW
140
      | ([] | [ _ ]) as group ->
×
141
        l := [];
142
        group
143
      | x :: (y :: _ as tl) ->
2,745✔
144
        pos := !pos + 1;
145
        l := tl;
146
        if break !pos x y
147
        then [ x ]
275✔
148
        else
149
          (* Coverage is off in the second part of the expression because the
150
             instrumentation breaks [@tail_mod_cons], triggering warning 71. *)
151
          x :: (take_group () [@coverage off])
2,470✔
152
    in
153
    (* Our outer loop does not need arguments, either. *)
154
    let[@tail_mod_cons] rec groups () =
155
      if is_empty !l
485✔
156
      then []
105✔
157
      else (
380✔
158
        let group = take_group () in
159
        (* Coverage is off in the second part of the expression because the
160
           instrumentation breaks [@tail_mod_cons], triggering warning 71. *)
161
        group :: (groups () [@coverage off]))
380✔
162
    in
163
    (groups () [@nontail])
164
  ;;
165

166
  let group l ~break = groupi l ~break:(fun _ x y -> break x y) [@nontail]
103✔
167
  (* ---------------------------------------------------------------------------- *)
168

169
  let[@tail_mod_cons] rec range start stop =
170
    if start >= stop
200✔
171
    then []
2✔
172
    else
173
      (* Coverage is off in the second part of the expression because the
174
         instrumentation breaks [@tail_mod_cons], triggering warning 71. *)
175
      start :: (range (start + 1) stop [@coverage off])
198✔
176
  ;;
177

178
  let sort_then_dedup t ~compare =
179
    let sorted = sort t ~compare in
248✔
180
    let[@tail_mod_cons] rec dedup = function
248✔
NEW
181
      | [] -> []
×
182
      | [ x ] -> [ x ]
248✔
183
      | x :: (y :: _ as rest) ->
1,340✔
184
        (match compare x y with
185
         | Eq -> dedup rest
580✔
NEW
186
         | Lt | Gt -> x :: dedup rest)
×
187
    in
188
    dedup sorted
189
  ;;
190
end
191

192
module Option = struct
193
  include Stdlib.Option
194

195
  let bind t ~f = bind t f
358,937✔
196
  let map t ~f = map f t
3,557✔
197
end
198

199
module String = struct
200
  include Stdlib.StringLabels
201

202
  let chop_prefix t ~prefix =
203
    if String.starts_with t ~prefix
3,862✔
204
    then (
467✔
205
      let prefix_len = String.length prefix in
206
      Some (StringLabels.sub t ~pos:prefix_len ~len:(String.length t - prefix_len)))
467✔
207
    else None
3,395✔
208
  ;;
209

NEW
210
  let compare a b = String.compare a b |> Ordering.of_int
×
211
end
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