QCheck2.Observable
An observable is a random function argument.
While random functions don't need to generate values of their arguments, they need the abilities to:
equal
and hash
, so that the same argument always returns the same generated valueprint
, in order to print the function implementation (bindings) in case of test failureInspired by:
make ?eq ?hash print
creates an observable of 'a
.
If eq
is None
, uses the standard polymorphic (=)
function.
If hash
is None
, uses a default hashing function.
val equal : 'a t -> 'a -> 'a -> bool
equal o
returns the equality function of o
.
val hash : 'a t -> 'a -> int
hash o
returns the hashing function of o
.
val unit : unit t
unit
is an observable of unit
.
val bool : bool t
bool
is an observable of bool
.
val int : int t
int
is an observable of int
.
val float : float t
float
is an observable of float
.
val bytes : bytes t
bytes
is an observable of bytes
.
val string : string t
string
is an observable of string
.
val char : char t
char
is an observable of char
.
contramap f o
maps the function f
on observable o
.
Note the reverse order of types in f
which may be conter-intuitive: indeed a function that consumes values of type 'b
can be obtained by transforming a value of type 'b
to 'a
using f
, and then by consuming this value of type 'a
using o
.
option o
wraps the observable o
of 'a
into an observable of 'a option
.
triple o1 o2 o3
is an observable of triples of ('a * 'b * 'c)
.