Module QCheck2.Test
A test is a pair of an generator and a property thar all generated values must satisfy.
type 'a cellA single property test on a value of type
'a. ATest.twraps acelland hides its type parameter.
val make_cell : ?if_assumptions_fail:([ `Fatal | `Warning ] * float) -> ?count:int -> ?long_factor:int -> ?max_gen:int -> ?max_fail:int -> ?name:string -> ?print:'a Print.t -> ?collect:('a -> string) -> ?stats:'a stat list -> 'a Gen.t -> ('a -> bool) -> 'a cellmake_cell gen propbuilds a test that checks propertypropon instances of the generatorgen.- parameter name
the name of the test.
- parameter count
number of test cases to run, counting only the test cases which satisfy preconditions.
- parameter long_factor
the factor by which to multiply count, max_gen and max_fail when running a long test (default: 1).
- parameter max_gen
maximum number of times the generation function is called in total to replace inputs that do not satisfy preconditions (should be >= count).
- parameter max_fail
maximum number of failures before we stop generating inputs. This is useful if shrinking takes too much time.
- parameter if_assumptions_fail
the minimum fraction of tests that must satisfy the precondition for a success to be considered valid. The fraction should be between 0. and 1. A warning will be emitted otherwise if the flag is
`Warning, the test will be a failure if the flag is`Fatal. (since 0.10)
- parameter print
used in
Printto display generated values failing theprop
- parameter collect
(* collect values by tag, useful to display distribution of generated *)
- parameter stats
on a distribution of values of type 'a
val make_cell_from_QCheck1 : ?if_assumptions_fail:([ `Fatal | `Warning ] * float) -> ?count:int -> ?long_factor:int -> ?max_gen:int -> ?max_fail:int -> ?name:string -> gen:(Stdlib.Random.State.t -> 'a) -> ?shrink:('a -> ('a -> unit) -> unit) -> ?print:('a -> string) -> ?collect:('a -> string) -> stats:'a stat list -> ('a -> bool) -> 'a cell⚠️ Do not use, this is exposed for internal reasons only. ⚠️
- deprecated
Migrate to QCheck2 and use
make_cellinstead.
val get_law : 'a cell -> 'a -> boolval get_name : _ cell -> stringval get_gen : 'a cell -> 'a Gen.tval get_print_opt : 'a cell -> 'a Print.t optionval get_collect_opt : 'a cell -> ('a -> string) optionval get_stats : 'a cell -> 'a stat listval set_name : _ cell -> string -> unitval get_count : _ cell -> intGet the count of a cell.
- since
- 0.5.3
val get_long_factor : _ cell -> intGet the long factor of a cell.
- since
- 0.5.3
type t=|Test : 'a cell -> tSame as
'a cell, but masking the type parameter. This allows to put tests on different types in the same list of tests.
val make : ?if_assumptions_fail:([ `Fatal | `Warning ] * float) -> ?count:int -> ?long_factor:int -> ?max_gen:int -> ?max_fail:int -> ?name:string -> ?print:'a Print.t -> ?collect:('a -> string) -> ?stats:'a stat list -> 'a Gen.t -> ('a -> bool) -> tmake gen propbuilds a test that checks propertypropon instances of the generatorgen. Seemake_cellfor a description of the parameters.
val test_get_count : t -> intval fail_report : string -> 'aFail the test with some additional message that will be reported.
- since
- 0.7
val fail_reportf : ('a, Stdlib.Format.formatter, unit, 'b) Stdlib.format4 -> 'aFormat version of
fail_report.Example:
Test.fail_reportf "Value N = %i should be greater than M = %i for Foo = %a" n m pp_foo foo- since
- 0.7
Running the test
include module type of Test_exceptions
val print_instance : 'a cell -> 'a -> stringval print_c_ex : 'a cell -> 'a TestResult.counter_ex -> stringval print_fail : 'a cell -> string -> 'a TestResult.counter_ex list -> stringval print_fail_other : string -> msg:string -> stringval print_error : ?st:string -> 'a cell -> string -> ('a TestResult.counter_ex * exn) -> stringval print_test_fail : string -> string list -> stringval print_test_error : string -> string -> exn -> string -> stringval print_collect : (string, int) Stdlib.Hashtbl.t -> stringPrint "collect" results.
- since
- 0.6
val print_stat : ('a stat * (int, int) Stdlib.Hashtbl.t) -> stringPrint statistics.
- since
- 0.6
val check_result : 'a cell -> 'a TestResult.t -> unitcheck_result cell reschecks thatresisOk _, and returns unit. Otherwise, it raises some exception.- raises Test_error
if
res = Error _
- raises Test_error
if
res = Failed _
type res=|Success|Failure|FalseAssumption|Error of exn * stringtype 'a event=|Generating|Collecting of 'a|Testing of 'a|Shrunk of int * 'a|Shrinking of int * int * 'atype 'a handler= string -> 'a cell -> 'a event -> unitHandler executed after each event during testing of an instance.
type 'a step= string -> 'a cell -> 'a -> res -> unitCallback executed after each instance of a test has been run. The callback is given the instance tested, and the current results of the test.
type 'a callback= string -> 'a cell -> 'a TestResult.t -> unitCallback executed after each test has been run.
f name cell resmeans testcell, namedname, gaveres.
val check_cell : ?long:bool -> ?call:'a callback -> ?step:'a step -> ?handler:'a handler -> ?rand:Stdlib.Random.State.t -> 'a cell -> 'a TestResult.tcheck_cell ~long ~rand testgenerates up tocountrandom values of type'ausingGen.tand the random statest. The predicatelawis called on them and if it returnsfalseor raises an exception then we have a counter-example for thelaw.- parameter long
if
truethen multiply the number of instances to generate by the cell's long_factor.
- parameter call
function called on each test case, with the result.
- parameter step
function called on each instance of the test case, with the result.
- returns
the result of the test.
val check_cell_exn : ?long:bool -> ?call:'a callback -> ?step:'a step -> ?rand:Stdlib.Random.State.t -> 'a cell -> unitSame as
check_cellbut callscheck_resulton the result.- raises Test_error
if
res = Error _
- raises Test_error
if
res = Failed _
val check_exn : ?long:bool -> ?rand:Stdlib.Random.State.t -> t -> unitChecks the property against some test cases, and calls
check_result, which might raise an exception in case of failure.- raises Test_error
if
res = Error _
- raises Test_error
if
res = Failed _