Skip to content

Commit

Permalink
Add Test.make_indexed_with_resource
Browse files Browse the repository at this point in the history
  • Loading branch information
craigfe committed Dec 23, 2021
1 parent 0e66bdb commit d1759cc
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
21 changes: 21 additions & 0 deletions lib/test.ml
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,27 @@ let make_indexed ~name ?(fmt : fmt_indexed = "%s:%d") ~args fn =
args;
}

let make_indexed_with_resource ~name ?(fmt : fmt_indexed = "%s:%d") ~args
~allocate ~free fn =
{
name;
set =
List.map
(fun key ->
{
Elt.key;
Elt.name = Fmt.str fmt name key;
Elt.fn =
V
{
fn = (fun `Init -> Staged.unstage (fn key));
resource = make_allocate (fun () -> allocate key);
free = make_free free;
};
})
args;
}

let name { name; _ } = name
let names { set; _ } = List.map Elt.name set
let elements { set; _ } = set
Expand Down
9 changes: 9 additions & 0 deletions lib/test.mli
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,15 @@ val make_indexed :
This kind of test is helpful to see results of the {b same} implementation
with differents arguments (indexed by the given [int]). *)

val make_indexed_with_resource :
name:string ->
?fmt:fmt_indexed ->
args:int list ->
allocate:(int -> 'a) ->
free:('a -> unit) ->
(int -> ('a -> 'b) Staged.t) ->
t

val make_grouped : name:string -> ?fmt:fmt_grouped -> t list -> t
(** [make_grouped ~name ~fmt tests] is naming benchmarks. Name of each benchmark
is [Fmt.strf fmt name arg] (default to [%s/%s]).
Expand Down

0 comments on commit d1759cc

Please sign in to comment.