elm-explorations/test/1.1.0

NOTE: the latest version is 2.2.1

Shrink

Library containing a collection of basic shrinking strategies and helper functions to help you construct shrinking strategies.

Shrinking Basics

type alias Shrinker a =
a -> LazyList a

The shrinker type. A shrinker is a function that takes a value and returns a list of values that are in some sense "smaller" than the given value. If there are no such values conceptually, then the shrinker should just return the empty list.

shrink : (a -> Bool) -> Shrinker a -> a -> a

Perform shrinking. Takes a predicate that returns True if you want shrinking to continue (e.g. the test failed). Also takes a shrinker and a value to shrink. It returns the shrunken value, or the input value if no shrunken values that satisfy the predicate are found.

Shrinkers

noShrink : a -> LazyList a

Perform no shrinking. Equivalent to the empty lazy list.

unit : Shrinker ()

Shrink the empty tuple. Equivalent to noShrink.

bool : Bool -> LazyList Bool

Shrinker of bools.

order : Order -> LazyList Order

Shrinker of Order values.

int : Int -> LazyList Int

Shrinker of integers.

atLeastInt : Int -> Int -> LazyList Int

Construct a shrinker of ints which considers the given int to be most minimal.

float : Float -> LazyList Float

Shrinker of floats.

atLeastFloat : Float -> Float -> LazyList Float

Construct a shrinker of floats which considers the given float to be most minimal.

char : Shrinker Char

Shrinker of chars.

atLeastChar : Char -> Shrinker Char

Construct a shrinker of chars which considers the given char to be most minimal.

character : Shrinker Char

Shrinker of chars which considers the empty space as the most minimal char and omits the control key codes.

Equivalent to:

atLeastChar (Char.fromCode 32)
string : Shrinker String

Shrinker of strings. Considers the empty string to be the most minimal string and the space to be the most minimal char.

Equivalent to:

convert String.fromList String.toList (list character)
maybe : Shrinker a -> Maybe a -> LazyList (Maybe a)

Maybe shrinker constructor. Takes a shrinker of values and returns a shrinker of Maybes.

Shrinker error
-> Shrinker value
-> Result error value
-> LazyList (Result error value)

Result shrinker constructor. Takes a shrinker of errors and a shrinker of values and returns a shrinker of Results.

lazylist : Shrinker a -> LazyList a -> LazyList (LazyList a)

Lazy List shrinker constructor. Takes a shrinker of values and returns a shrinker of Lazy Lists. The lazy list being shrunk must be finite. (I mean really, how do you shrink infinity?)

list : Shrinker a -> Shrinker (List a)

List shrinker constructor. Takes a shrinker of values and returns a shrinker of Lists.

array : Shrinker a -> Shrinker (Array a)

Array shrinker constructor. Takes a shrinker of values and returns a shrinker of Arrays.

tuple : ( Shrinker a, Shrinker b ) -> ( a, b ) -> LazyList ( a, b )

2-Tuple shrinker constructor. Takes a tuple of shrinkers and returns a shrinker of tuples.

( Shrinker a, Shrinker b, Shrinker c )
-> ( a, b, c )
-> LazyList ( a, b, c )

3-Tuple shrinker constructor. Takes a tuple of shrinkers and returns a shrinker of tuples.

Functions on Shrinkers

convert : (a -> b) -> (b -> a) -> Shrinker a -> b -> LazyList b

Convert a Shrinker of a's into a Shrinker of b's using two inverse functions. ) If you use this function as follows:

shrinkerB =
    f g shrinkerA

Make sure that

`f(g(x)) == x` for all x

Or else this process will generate garbage.

keepIf : (a -> Bool) -> Shrinker a -> a -> LazyList a

Filter out the results of a shrinker. The resulting shrinker will only produce shrinks which satisfy the given predicate.

dropIf : (a -> Bool) -> Shrinker a -> Shrinker a

Filter out the results of a shrinker. The resulting shrinker will only throw away shrinks which satisfy the given predicate.

merge : Shrinker a -> Shrinker a -> a -> LazyList a

Merge two shrinkers. Generates all the values in the first shrinker, and then all the non-duplicated values in the second shrinker.

map : (a -> b) -> LazyList a -> LazyList b

Re-export of Lazy.List.map This is useful in order to compose shrinkers, especially when used in conjunction with andMap. For example:

type alias Vector =
    { x : Float
    , y : Float
    , z : Float
    }


vector : Shrinker Vector
vector { x, y, z } =
    Vector
        `map` float x
        `andMap` float y
        `andMap` float z
andMap : LazyList a -> LazyList (a -> b) -> LazyList b

Apply a lazy list of functions on a lazy list of values.

The argument order is so that it is easy to use in |> chains.