kotest-property / io.kotest.property / Shrinker

Shrinker

interface Shrinker<A>

Given a value, T, this function returns reduced values to be used as candidates for shrinking.

A smaller value is defined per Shrinker. For a string it may be considered a string with less characters, or less duplication/variation in the characters. For an integer it is typically considered a smaller value with a positive sign.

Shrinkers can return one or more values in a shrink step. Shrinkers can return more than one value if there is no single "best path". For example, when shrinking an integer, you probably want to return a single smaller value at a time. For strings, you may wish to return a string that is simpler (YZ -> YY), as well as smaller (YZ -> Y).

If the value cannot be shrunk further, or the type does not support meaningful shrinking, then this function should return an empty list.

Functions

shrink

Returns the "next level" of shrinks for the given value, or empty list if a "base case" has been reached. For example, to shrink an int k we may decide to return k/2 and k-1.

abstract fun shrink(value: A): List<A>

Extension Functions

bimap

fun <A, B> Shrinker<A>.bimap(f: (B) -> A, g: (A) -> B): Shrinker<B>

rtree

Generates an RTree of all shrinks from an initial value.

fun <A> Shrinker<A>.rtree(a: A): RTree<A>

Inheritors

DoubleShrinker

object DoubleShrinker : Shrinker<Double>

FloatShrinker

object FloatShrinker : Shrinker<Float>

IntShrinker

object IntShrinker : Shrinker<Int>

ListShrinker

class ListShrinker<A> : Shrinker<List<A>>

LongShrinker

object LongShrinker : Shrinker<Long>

MapShrinker

class MapShrinker<K, V> : Shrinker<Map<K, V>>

MultiplesShrinker

class MultiplesShrinker : Shrinker<Int>

StringShrinker

object StringShrinker : Shrinker<String>