Module Core_kernel.Quickcheck

Quickcheck is a library that uses predicate-based tests and pseudo-random inputs to automate testing.

include Quickcheck_intf.Quickcheck
type shrink_attempts = Quickcheck_intf.shrink_attempts
module Observer : Quickcheck_intf.Observer with type gen := a Generator.t
module type S : Quickcheck_intf.S with type gen := a Generator.t with type obs := a Observer.t with type shr := a Shrinker.t
module type S1 : Quickcheck_intf.S1 with type gen := a Generator.t with type obs := a Observer.t with type shr := a Shrinker.t
module type S2 : Quickcheck_intf.S2 with type gen := a Generator.t with type obs := a Observer.t with type shr := a Shrinker.t
module type S_int : Quickcheck_intf.S_int with type gen := a Generator.t with type obs := a Observer.t with type shr := a Shrinker.t
module Let_syntax : module type of Generator.Let_syntax with module Let_syntax.Let_syntax.Open_on_rhs = Generator
module Make_int : functor (M : Quickcheck_intf.Pre_int) -> S_int with type t := M.t
module For_int : S_int with type t := Core_kernel__.Import.int
module type Quickcheck_configured : Quickcheck_intf.Quickcheck_configured with type gen := a Generator.t with type shr := a Shrinker.t

with a default config

include Quickcheck_configured
include Quickcheck_intf.Quickcheck_config
val default_seed : Quickcheck_intf.seed

default_seed is used initialize the pseudo-random generator that chooses random values from generators, in each test that is not provided its own seed.

default_sizes determines the default sequence of sizes used in generating values.

val default_trial_count : Core_kernel__.Import.int

default_trial_count determines the number of trials per test, except in tests that explicitly override it.

val default_can_generate_trial_count : Core_kernel__.Import.int

default_can_generate_trial_count determines the number of trials used in attempts to generate satisfying values, except in tests that explicitly override it.

val default_attempts_per_trial : Core_kernel__.Import.float

default_attempts_per_trial determines the maximum number of attempts to generate inputs for trials, as a multiplier for the number of trials, except in tests that explicitly override it.

val default_shrink_attempts : Quickcheck_intf.shrink_attempts

default_shrink_attempts determines the number of attempts at shrinking when running test or iter with ~shrinker and without ~shrink_attempts

type 'a gen
type 'a shr
val random_value : ?⁠seed:Quickcheck_intf.seed ‑> ?⁠size:Core_kernel__.Import.int ‑> 'a gen ‑> 'a

random_value ~seed gen produces a single value chosen from gen using seed.

val iter : ?⁠seed:Quickcheck_intf.seed ‑> ?⁠sizes:Core_kernel__.Import.int Sequence.t ‑> ?⁠trials:Core_kernel__.Import.int ‑> ?⁠attempts:Core_kernel__.Import.int ‑> ?⁠filter:('a ‑> Core_kernel__.Import.bool) ‑> 'a gen ‑> f:('a ‑> Core_kernel__.Import.unit) ‑> Core_kernel__.Import.unit

iter ~seed ~trials ~attempts ~filter gen ~f runs f on up to trials different values generated by gen. It stops successfully after trials successful trials or if gen runs out of values. It raises an exception if f raises an exception or if it fails to produce trials inputs from gen after attempts attempts. If filter is provided, iteration proceeds over Generator.filter gen ~f:filter.

val test : ?⁠seed:Quickcheck_intf.seed ‑> ?⁠sizes:Core_kernel__.Import.int Sequence.t ‑> ?⁠trials:Core_kernel__.Import.int ‑> ?⁠attempts:Core_kernel__.Import.int ‑> ?⁠filter:('a ‑> Core_kernel__.Import.bool) ‑> ?⁠shrinker:'a shr ‑> ?⁠shrink_attempts:Quickcheck_intf.shrink_attempts ‑> ?⁠sexp_of:('a ‑> Base.Sexp.t) ‑> ?⁠examples:'a Core_kernel__.Import.list ‑> 'a gen ‑> f:('a ‑> Core_kernel__.Import.unit) ‑> Core_kernel__.Import.unit

test ~seed ~trials ~attempts ~sexp_of ~examples gen ~f is like iter, with optional concrete examples that are tested before values from gen, and additional information provided on failure. If f raises an exception and sexp_of is provided, the exception is re-raised with a description of the random input that triggered the failure. If f raises an exception and shrinker is provided, it will be used to attempt to shrink the value that caused the exception with re-raising behaving the same as for unshrunk inputs.

val test_or_error : ?⁠seed:Quickcheck_intf.seed ‑> ?⁠sizes:Core_kernel__.Import.int Sequence.t ‑> ?⁠trials:Core_kernel__.Import.int ‑> ?⁠attempts:Core_kernel__.Import.int ‑> ?⁠filter:('a ‑> Core_kernel__.Import.bool) ‑> ?⁠shrinker:'a shr ‑> ?⁠shrink_attempts:Quickcheck_intf.shrink_attempts ‑> ?⁠sexp_of:('a ‑> Base.Sexp.t) ‑> ?⁠examples:'a Core_kernel__.Import.list ‑> 'a gen ‑> f:('a ‑> Core_kernel__.Import.unit Or_error.t) ‑> Core_kernel__.Import.unit Or_error.t

test_or_error is like test, except failure is determined using Or_error.t. Any exceptions raised by f are not caught.

val test_can_generate : ?⁠seed:Quickcheck_intf.seed ‑> ?⁠sizes:Core_kernel__.Import.int Sequence.t ‑> ?⁠trials:Core_kernel__.Import.int ‑> ?⁠attempts:Core_kernel__.Import.int ‑> ?⁠filter:('a ‑> Core_kernel__.Import.bool) ‑> ?⁠sexp_of:('a ‑> Base.Sexp.t) ‑> 'a gen ‑> f:('a ‑> Core_kernel__.Import.bool) ‑> Core_kernel__.Import.unit

test_can_generate ~seed ~trials ~attempts ~sexp_of gen ~f is useful for testing gen values, to make sure they can generate useful examples. It tests gen by generating up to trials values and passing them to f. Once a value satisfies f, the iteration stops. If no values satisfy f, test_can_generate raises an exception. If sexp_of is provided, the exception includes all of the generated values.

val test_distinct_values : ?⁠seed:Quickcheck_intf.seed ‑> ?⁠sizes:Core_kernel__.Import.int Sequence.t ‑> ?⁠attempts:Core_kernel__.Import.int ‑> ?⁠filter:('a ‑> Core_kernel__.Import.bool) ‑> ?⁠sexp_of:('a ‑> Base.Sexp.t) ‑> 'a gen ‑> trials:Core_kernel__.Import.int ‑> distinct_values:Core_kernel__.Import.int ‑> compare:('a ‑> 'a ‑> Core_kernel__.Import.int) ‑> Core_kernel__.Import.unit

test_distinct_values gen ~compare ~trials ~distinct_values is useful for testing gen values, to make sure they create sufficient distinct values. It tests gen by generating up to trials values and making sure at least distinct_values of the resulting values are unique with respect to compare. If too few distinct values are generated, test_distinct_values raises an exception. If sexp_of is provided, the exception includes the values generated.

val random_sequence : ?⁠seed:Quickcheck_intf.seed ‑> ?⁠sizes:Core_kernel__.Import.int Sequence.t ‑> 'a gen ‑> 'a Sequence.t

random_sequence ~seed gen produces a sequence of values chosen from gen.