package core

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

Module Quickcheck.ShrinkerSource

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.

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

Sourceval tuple2 : 'a t -> 'b t -> ('a * 'b) t
Sourceval tuple3 : 'a t -> 'b t -> 'c t -> ('a * 'b * 'c) t
Sourceval tuple4 : 'a t -> 'b t -> 'c t -> 'd t -> ('a * 'b * 'c * 'd) t
Sourceval tuple5 : 'a t -> 'b t -> 'c t -> 'd t -> 'e t -> ('a * 'b * 'c * 'd * 'e) t
Sourceval tuple6 : 'a t -> 'b t -> 'c t -> 'd t -> 'e t -> 'f t -> ('a * 'b * 'c * 'd * 'e * 'f) t
Sourceval variant2 : 'a t -> 'b t -> [ `A of 'a | `B of 'b ] t
Sourceval variant3 : 'a t -> 'b t -> 'c t -> [ `A of 'a | `B of 'b | `C of 'c ] t
Sourceval variant4 : 'a t -> 'b t -> 'c t -> 'd t -> [ `A of 'a | `B of 'b | `C of 'c | `D of 'd ] t
Sourceval 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
Sourceval 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
Sourceval 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.