feat(testlib): optional arguments for q

This commit is contained in:
Simon Cruanes 2022-07-04 21:47:24 -04:00
parent 090945c3f8
commit 75fe196d3a
No known key found for this signature in database
GPG key ID: EBFFF6F283F3A2B4
2 changed files with 34 additions and 4 deletions

View file

@ -14,6 +14,9 @@ module Test = struct
arb: 'a Q.arbitrary; arb: 'a Q.arbitrary;
prop: 'a -> bool; prop: 'a -> bool;
long_factor: int option; long_factor: int option;
max_gen: int option;
max_fail: int option;
if_assumptions_fail: ([ `Fatal | `Warning ] * float) option;
} }
-> run -> run
@ -69,7 +72,16 @@ module Test = struct
in in
Error msg Error msg
) )
| Q { count; arb; prop; long_factor } -> | Q
{
count;
arb;
prop;
long_factor;
max_fail;
max_gen;
if_assumptions_fail;
} ->
(* create a random state from the seed *) (* create a random state from the seed *)
let rand = let rand =
let bits = let bits =
@ -80,7 +92,8 @@ module Test = struct
let module Fmt = CCFormat in let module Fmt = CCFormat in
let cell = let cell =
Q.Test.make_cell ?count ?long_factor ~name:(str_loc self) arb prop Q.Test.make_cell ?if_assumptions_fail ?max_gen ?max_fail ?count
?long_factor ~name:(str_loc self) arb prop
in in
let pp_cex out (cx : _ Q.TestResult.counter_ex) = let pp_cex out (cx : _ Q.TestResult.counter_ex) =
@ -135,6 +148,9 @@ module type S = sig
?name:string -> ?name:string ->
?count:int -> ?count:int ->
?long_factor:int -> ?long_factor:int ->
?max_gen:int ->
?max_fail:int ->
?if_assumptions_fail:[ `Fatal | `Warning ] * float ->
'a Q.arbitrary -> 'a Q.arbitrary ->
('a -> bool) -> ('a -> bool) ->
unit unit
@ -168,8 +184,19 @@ struct
let eq ?name ?cmp ?printer lhs rhs : unit = let eq ?name ?cmp ?printer lhs rhs : unit =
add_ @@ mk ?name @@ Test.Eq { eq = cmp; print = printer; lhs; rhs } add_ @@ mk ?name @@ Test.Eq { eq = cmp; print = printer; lhs; rhs }
let q ?name ?count ?long_factor arb prop : unit = let q ?name ?count ?long_factor ?max_gen ?max_fail ?if_assumptions_fail arb
add_ @@ mk ?name @@ Test.Q { arb; prop; count; long_factor } prop : unit =
add_ @@ mk ?name
@@ Test.Q
{
arb;
prop;
count;
long_factor;
max_gen;
max_fail;
if_assumptions_fail;
}
let assert_equal ?printer ?(cmp = ( = )) x y : unit = let assert_equal ?printer ?(cmp = ( = )) x y : unit =
if not @@ cmp x y then ( if not @@ cmp x y then (

View file

@ -15,6 +15,9 @@ module type S = sig
?name:string -> ?name:string ->
?count:int -> ?count:int ->
?long_factor:int -> ?long_factor:int ->
?max_gen:int ->
?max_fail:int ->
?if_assumptions_fail:[ `Fatal | `Warning ] * float ->
'a Q.arbitrary -> 'a Q.arbitrary ->
('a -> bool) -> ('a -> bool) ->
unit unit