package base_quickcheck

  1. Overview
  2. Docs

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.

Sourcetype -'a t

Basic Observers

Sourceval opaque : _ t

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.

Sourceval unit : Base.unit t
Sourceval bool : Base.bool t
Sourceval char : Base.char t
Sourceval string : Base.string t
Sourceval bytes : Base.bytes t
Sourceval int : Base.int t
Sourceval int32 : Base.int32 t
Sourceval int63 : Base.Int63.t t
Sourceval int64 : Base.int64 t
Sourceval nativeint : Base.nativeint t
Sourceval float : Base.float t
Sourceval sexp : Base.Sexp.t t
Sourceval option : 'a t -> 'a Base.option t
Sourceval list : 'a t -> 'a Base.list t
Sourceval array : 'a t -> 'a Base.array t
Sourceval ref : 'a t -> 'a Base.ref t
Sourceval lazy_t : 'a t -> 'a Base.Lazy.t t
Sourceval both : 'a t -> 'b t -> ('a * 'b) t
Sourceval either : 'a t -> 'b t -> ('a, 'b) Base.Either.t t
Sourceval result : 'a t -> 'b t -> ('a, 'b) Base.Result.t t

This helper module type exists separately just to open Bigarray in its scope.

Sourceval fn : 'a Generator.t -> 'b t -> ('a -> 'b) t

Produces an observer that generates random inputs for a given function, calls the function on them, then observes the corresponding outputs.

Sourceval map_t : 'key t -> 'data t -> ('key, 'data, 'cmp) Base.Map.t t
Sourceval set_t : 'elt t -> ('elt, 'cmp) Base.Set.t t
Sourceval map_tree : 'key t -> 'data t -> ('key, 'data, 'cmp) Base.Map.Using_comparator.Tree.t t
Sourceval set_tree : 'elt t -> ('elt, 'cmp) Base.Set.Using_comparator.Tree.t t

Observers Based on Hash Functions

Sourceval of_hash_fold : (Base.Hash.state -> 'a -> Base.Hash.state) -> 'a t

Creates 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

Sourceval unmap : 'a t -> f:('b -> 'a) -> 'b t

Observers for Recursive Types

Sourceval fixed_point : ('a t -> 'a t) -> 'a t

Ties 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)))
Sourceval of_lazy : 'a t Base.Lazy.t -> 'a t

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.

Sourceval create : ('a -> size:Base.int -> hash:Base.Hash.state -> Base.Hash.state) -> 'a t
Sourceval observe : 'a t -> 'a -> size:Base.int -> hash:Base.Hash.state -> Base.Hash.state
OCaml

Innovation. Community. Security.