Module type Quickcheck_intf.Observer
type -'a t
= 'a Base_quickcheck.Observer.t
val create : ('a -> size:Core_kernel__.Import.int -> hash:Core_kernel__.Import.Hash.state -> Core_kernel__.Import.Hash.state) -> 'a t
val observe : 'a t -> 'a -> size:Core_kernel__.Import.int -> hash:Core_kernel__.Import.Hash.state -> Core_kernel__.Import.Hash.state
val of_hash : (module Deriving_hash with type t = 'a) -> 'a t
of_hash
creates an observer for any hashable type.
val bool : Core_kernel__.Import.bool t
val char : Core_kernel__.Import.char t
val doubleton : ('a -> Core_kernel__.Import.bool) -> 'a t
doubleton f
maps values to two "buckets" (as described int
above), depending on whether they satisfyf
.
val enum : Core_kernel__.Import.int -> f:('a -> Core_kernel__.Import.int) -> 'a t
enum n ~f
maps values ton
buckets, wheref
produces the index for a bucket from0
ton-1
for each value.
val of_list : 'a Core_kernel__.Import.list -> equal:('a -> 'a -> Core_kernel__.Import.bool) -> 'a t
of_list list ~equal
maps values inlist
to separate buckets, and compares observed values to the elements oflist
usingequal
.
val fixed_point : ('a t -> 'a t) -> 'a t
Fixed point observer for recursive types. For example:
let sexp_obs = fixed_point (fun sexp_t -> unmap (variant2 string (list sexp_t)) ~f:(function | Sexp.Atom atom -> `A atom | Sexp.List list -> `B list))
val variant2 : 'a t -> 'b t -> [ `A of 'a | `B of 'b ] t
val variant3 : 'a t -> 'b t -> 'c t -> [ `A of 'a | `B of 'b | `C of 'c ] t
val variant4 : 'a t -> 'b t -> 'c t -> 'd t -> [ `A of 'a | `B of 'b | `C of 'c | `D of 'd ] t
val variant5 : 'a t -> 'b t -> 'c t -> 'd t -> 'e t -> [ `A of 'a | `B of 'b | `C of 'c | `D of 'd | `E of 'e ] t
val variant6 : 'a t -> 'b t -> 'c t -> 'd t -> 'e t -> 'f t -> [ `A of 'a | `B of 'b | `C of 'c | `D of 'd | `E of 'e | `F of 'f ] t
val of_predicate : 'a t -> 'a t -> f:('a -> Core_kernel__.Import.bool) -> 'a t
of_predicate t1 t2 ~f
combinest1
andt2
, wheret1
observes values that satisfyf
andt2
observes values that do not satisfyf
.
val comparison : compare:('a -> 'a -> Core_kernel__.Import.int) -> eq:'a -> lt:'a t -> gt:'a t -> 'a t
comparison ~compare ~eq ~lt ~gt
combines observerslt
andgt
, wherelt
observes values less thaneq
according tocompare
, andgt
observes values greater thaneq
according tocompare
.
val singleton : Core_kernel__.Import.unit -> _ t
maps all values to a single bucket.
val unmap : 'a t -> f:('b -> 'a) -> 'b t
unmap t ~f
appliesf
to values before observing them usingt
.
val tuple2 : 'a t -> 'b t -> ('a * 'b) t
val tuple3 : 'a t -> 'b t -> 'c t -> ('a * 'b * 'c) t
val tuple4 : 'a t -> 'b t -> 'c t -> 'd t -> ('a * 'b * 'c * 'd) t
val tuple5 : 'a t -> 'b t -> 'c t -> 'd t -> 'e t -> ('a * 'b * 'c * 'd * 'e) t
val tuple6 : 'a t -> 'b t -> 'c t -> 'd t -> 'e t -> 'f t -> ('a * 'b * 'c * 'd * 'e * 'f) t
val fn : 'a Base_quickcheck.Generator.t -> 'b t -> ('a -> 'b) t
Observer for function type.
fn gen t
observes a function by generating random inputs fromgen
, applying the function, and observing the output usingt
.
val of_fun : (Core_kernel__.Import.unit -> 'a t) -> 'a t
of_fun f
produces an observer that lazily appliesf
.It is recommended that
f
should not do a lot of expensive work and should not be memoized. Instead, spread out the work of generating an observer over manyof_fun
calls combined with, e.g.,variant
ortuple
. This allows lazily generated observers to be garbage collected after each test and the relevant portions cheaply recomputed in subsequent tests, rather than accumulating without bound over time.