Module Quickcheck.Shrinker
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.
type 'a t
= 'a Base_quickcheck.Shrinker.t
val shrink : 'a t -> 'a -> 'a Core_kernel.Sequence.t
val create : ('a -> 'a Core_kernel.Sequence.t ) -> 'a t
val empty : Core_kernel__.Import.unit -> 'a t
val bool : Core_kernel__.Import.bool t
val char : Core_kernel__.Import.char t
val map : 'a t -> f:('a -> 'b ) -> f_inverse:('b -> 'a ) -> 'b t
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.