Module QCheck.ShrinkSource

The Shrink module contains combinators to build up composite shrinkers for user-defined types

⚠️ Warning: QCheck's shrinking phase may loop infinitely if

Sourcetype 'a t = 'a -> 'a Iter.t

Given a counter-example, return an iterator on smaller versions of the counter-example.

Sourceval nil : 'a t

No shrink

Sourceval unit : unit t

unit shrinker. Does not produce any shrinking candidates.

  • since 0.6
Sourceval bool : bool t

bool shrinker. Shrinks towards false.

  • since 0.23
Sourceval char : char t

char shrinker. Shrinks towards 'a'.

  • since 0.6
Sourceval char_numeral : char t

char digit shrinker. Shrinks towards '0'.

  • since 0.19
Sourceval char_printable : char t

Printable char shrinker. Shrinks towards 'a' like !char. The output is also a printable character.

  • since 0.19
Sourceval int : int t

int shrinker. Shrinks towards 0.

Sourceval int32 : int32 t

int32 shrinker. Shrinks towards 0l.

  • since 0.14
Sourceval int64 : int64 t

int64 shrinker. Shrinks towards 0L.

  • since 0.14
Sourceval option : 'a t -> 'a option t

option shrinker. Shrinks towards None. option shk reduces Some v values using shk to reduce v.

Sourceval result : 'a t -> 'e t -> ('a, 'e) result t

result shrinker. result ashk eshk reduces Ok a values using ashk and Error e values using eshk.

  • since 0.24
Sourceval bytes : ?shrink:char t -> bytes t

bytes shrinker. Shrinks towards shorter byte strings.

  • parameter shrink

    an optional char shrinker.

  • since 0.20
Sourceval string : ?shrink:char t -> string t

string shrinker. Shrinks towards "".

  • parameter shrink

    an optional char shrinker.

Sourceval filter : ('a -> bool) -> 'a t -> 'a t

filter f shrink shrinks values the same as shrink, but only keep smaller values that satisfy f. This way it's easy to preserve invariants that are enforced by generators, when shrinking values

  • since 0.8
Sourceval int_aggressive : int t

Shrink integers by trying all smaller integers (can take a lot of time!)

  • since 0.7
Sourceval list : ?shrink:'a t -> 'a list t

Try to shrink lists by removing one or more elements.

  • parameter shrink

    if provided, will be used to also try to reduce the elements of the list themselves (e.g. in an int list one can try to decrease the integers).

Sourceval list_spine : 'a list t

Try to shrink lists by removing one or more elements.

  • since 0.10
Sourceval list_elems : 'a t -> 'a list t

Shrinks the elements of a list, without changing the list size.

  • since 0.10
Sourceval array : ?shrink:'a t -> 'a array t

Shrink an array.

  • parameter shrink

    see list

Sourceval pair : 'a t -> 'b t -> ('a * 'b) t

pair a b uses a to shrink the first element of tuples, then tries to shrink the second element using b. It is often better, when generating tuples, to put the "simplest" element first (atomic type rather than list, etc.) because it will be shrunk earlier. In particular, putting functions last might help.

Sourceval triple : 'a t -> 'b t -> 'c t -> ('a * 'b * 'c) t

Similar to pair

Sourceval quad : 'a t -> 'b t -> 'c t -> 'd t -> ('a * 'b * 'c * 'd) t

Similar to pair

Sourceval tup2 : 'a t -> 'b t -> ('a * 'b) t

tup2 a b uses a to shrink the first element of tuples, then tries to shrink the second element using b. It is often better, when generating tuples, to put the "simplest" element first (atomic type rather than list, etc.) because it will be shrunk earlier. In particular, putting functions last might help.

Sourceval tup3 : 'a t -> 'b t -> 'c t -> ('a * 'b * 'c) t

Similar to tup2

Sourceval tup4 : 'a t -> 'b t -> 'c t -> 'd t -> ('a * 'b * 'c * 'd) t

Similar to tup2

Sourceval tup5 : 'a t -> 'b t -> 'c t -> 'd t -> 'e t -> ('a * 'b * 'c * 'd * 'e) t

Similar to tup2

Sourceval tup6 : 'a t -> 'b t -> 'c t -> 'd t -> 'e t -> 'f t -> ('a * 'b * 'c * 'd * 'e * 'f) t

Similar to tup2

Sourceval tup7 : 'a t -> 'b t -> 'c t -> 'd t -> 'e t -> 'f t -> 'g t -> ('a * 'b * 'c * 'd * 'e * 'f * 'g) t

Similar to tup2

Sourceval tup8 : 'a t -> 'b t -> 'c t -> 'd t -> 'e t -> 'f t -> 'g t -> 'h t -> ('a * 'b * 'c * 'd * 'e * 'f * 'g * 'h) t

Similar to tup2

Sourceval tup9 : 'a t -> 'b t -> 'c t -> 'd t -> 'e t -> 'f t -> 'g t -> 'h t -> 'i t -> ('a * 'b * 'c * 'd * 'e * 'f * 'g * 'h * 'i) t

Similar to tup2