Module Base_quickcheck.ObserverSource
Observers create random functions. Generator.fn creates a random function using an observer for the input type and a generator for the output type.
Basic Observers
Produces an observer that treats all values as equivalent. Random functions generated using this observer will be constant with respect to the value(s) it observes.
val both :
'a Base_quickcheck.Observer.t ->
'b Base_quickcheck.Observer.t ->
('a * 'b) Base_quickcheck.Observer.tval either :
'a Base_quickcheck.Observer.t ->
'b Base_quickcheck.Observer.t ->
('a, 'b) Base.Either.t Base_quickcheck.Observer.tval result :
'a Base_quickcheck.Observer.t ->
'b Base_quickcheck.Observer.t ->
('a, 'b) Base.Result.t Base_quickcheck.Observer.tThis helper module type exists separately just to open Bigarray in its scope.
val fn :
'a Base_quickcheck.Generator.t ->
'b Base_quickcheck.Observer.t ->
('a -> 'b) Base_quickcheck.Observer.tProduces an observer that generates random inputs for a given function, calls the function on them, then observes the corresponding outputs.
val map_t :
'key Base_quickcheck.Observer.t ->
'data Base_quickcheck.Observer.t ->
('key, 'data, 'cmp) Base.Map.t Base_quickcheck.Observer.tval set_t :
'elt Base_quickcheck.Observer.t ->
('elt, 'cmp) Base.Set.t Base_quickcheck.Observer.tval map_tree :
'key Base_quickcheck.Observer.t ->
'data Base_quickcheck.Observer.t ->
('key, 'data, 'cmp) Base.Map.Using_comparator.Tree.t
Base_quickcheck.Observer.tval set_tree :
'elt Base_quickcheck.Observer.t ->
('elt, 'cmp) Base.Set.Using_comparator.Tree.t Base_quickcheck.Observer.tObservers Based on Hash Functions
val of_hash_fold :
(Base.Hash.state -> 'a -> Base.Hash.state) ->
'a Base_quickcheck.Observer.tCreates an observer that just calls a hash function. This is a good default for most hashable types not covered by the basic observers above.
Modifying Observers
Observers for Recursive Types
val fixed_point :
('a Base_quickcheck.Observer.t -> 'a Base_quickcheck.Observer.t) ->
'a Base_quickcheck.Observer.tTies the recursive knot to observe recursive types.
For example, here is an observer for binary trees:
let tree_observer leaf_observer =
fixed_point (fun self ->
either leaf_observer (both self self)
|> unmap ~f:(function
| `Leaf leaf -> First leaf
| `Node (l, r) -> Second (l, r)))Creates a t that forces the lazy argument as necessary. Can be used to tie (mutually) recursive knots.
Low-Level functions
Most users do not need to call these functions.
val create :
('a -> size:Base.int -> hash:Base.Hash.state -> Base.Hash.state) ->
'a Base_quickcheck.Observer.tval observe :
'a Base_quickcheck.Observer.t ->
'a ->
size:Base.int ->
hash:Base.Hash.state ->
Base.Hash.state