package core

  1. Overview
  2. Docs
Legend:
Library
Module
Module type
Parameter
Class
Class type

A 'a Quickcheck.Shrinker.t takes a value of type 'a and produces similar values that are smaller by some metric.

The defined shrinkers generally try to make a single change for each value based on the assumption that the first resulting value that preserves the desired property will be used to create another sequence of shrunk values.

Within Quickcheck.test the shrinker is used as described above.

Shrinkers aim to aid understanding of what's causing an error by reducing the input down to just the elements making it fail. The default shrinkers remove elements of compound structures, but leave atomic values alone. For example, the default list shrinker tries removing elements from the list, but the default int shrinker does nothing. This default strikes a balance between performance and precision. Individual tests can use different shrinking behavior as necessary.

See lib/core/example/quickcheck/shrinker_example.ml for some example shrinkers.

val shrink : 'a t -> 'a -> 'a Sequence.t
val create : ('a -> 'a Sequence.t) -> 'a t
val empty : Base.Unit.t -> 'a t
val bool : Base.Bool.t t
val char : Base.Char.t t
val map : 'a t -> f:('a -> 'b) -> f_inverse:('b -> 'a) -> 'b t
val filter : 'a t -> f:('a -> Base.Bool.t) -> 'a t
val filter_map : 'a t -> f:('a -> 'b Base.Option.t) -> 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.

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 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 fixed_point : ('a t -> 'a t) -> 'a t

fixed_point assists with shrinking structures recursively. Its advantage over directly using rec in the definition of the shrinker is that it causes lazy evaluation where possible.

OCaml

Innovation. Community. Security.