package base_quickcheck

  1. Overview
  2. Docs

Module Base_quickcheck.ShrinkerSource

Shrinkers produce small values from large values. When a random test case fails, a shrinker finds the simplest version of the problem.

Sourcetype 'a t

Basic Shrinkers

Sourceval atomic : _ t

This shrinker treats a type as atomic, never attempting to produce smaller values.

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 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_using_comparator : comparator:('key, 'cmp) Base.Comparator.t -> 'key t -> 'data t -> ('key, 'data, 'cmp) Base.Map.Using_comparator.Tree.t t
Sourceval set_tree_using_comparator : comparator:('elt, 'cmp) Base.Comparator.t -> 'elt t -> ('elt, 'cmp) Base.Set.Using_comparator.Tree.t t

Modifying Shrinkers

Sourceval map : 'a t -> f:('a -> 'b) -> f_inverse:('b -> 'a) -> 'b t
Sourceval filter : 'a t -> f:('a -> Base.bool) -> 'a t
Sourceval filter_map : 'a t -> f:('a -> 'b Base.option) -> f_inverse:('b -> 'a) -> 'b t

Filters and maps according to f, and provides input to t via f_inverse. Only the f direction produces options, intentionally.

Shrinkers for Recursive Types

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

Ties the recursive knot to shrink recursive types.

For example, here is an shrinker for binary trees:

  let tree_shrinker leaf_shrinker =
    fixed_point (fun self ->
      either leaf_shrinker (both self self)
      |> map
           ~f:(function
             | First leaf -> `Leaf leaf
             | Second (l, r) -> `Node (l, r))
           ~f_inverse:(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 will not need to call these.

Sourceval create : ('a -> 'a Base.Sequence.t) -> 'a t
Sourceval shrink : 'a t -> 'a -> 'a Base.Sequence.t
OCaml

Innovation. Community. Security.