NoRedInk/elm-shrink/1.0.1

NOTE: this package is not compatible with Elm 0.19.1

Shrink

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

Shinker

type alias Shrinker a =
a -> LazyList a

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.

Shrinkers

noShrink : Shrinker a

Empty shrinker. Always returns the empty list.

void : Shrinker ()

Shrink the empty tuple. Equivalent to noShrink.

bool : Shrinker Bool

Shrinker of bools.

order : Shrinker Order

Shrinker of Order.

int : Shrinker Int

Shrinker of integers.

atLeastInt : Int -> Shrinker Int

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

float : Shrinker Float

Shrinker of floats.

atLeastFloat : Float -> Shrinker 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 -> Shrinker (Maybe a)

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

result : Shrinker error -> Shrinker value -> Shrinker (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 -> Shrinker (LazyList a)

Lazy List shrinker constructor. (must be finite) Takes a shrinker of values and returns a shrinker of Lazy Lists.

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 ) -> Shrinker ( a, b )

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

tuple3 : ( Shrinker a, Shrinker b, Shrinker c ) -> Shrinker ( a, b, c )

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

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

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

( Shrinker a, Shrinker b, Shrinker c, Shrinker d, Shrinker e )
-> Shrinker ( a, b, c, d, e )

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

Useful functions

convert : (a -> b) -> (b -> a) -> Shrinker a -> Shrinker 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 -> Shrinker 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 -> Shrinker a

Merge two shrinkers.

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. Example: type alias Vector = { x : Float , y : Float , z : Float } vector : Shrinker Float vector {x,y,z} = Vector map float x andMap float y andMap float z

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

Apply a lazy list of functions on a lazy list of values. andMap = Lazy.List.map2 (<|) This is useful in order to compose shrinkers, especially when used in conjunction with andMap.