genvalidity-0.11.0.0: Testing utilities for the validity library

Data.GenValidity.Utils

Synopsis

## Helper functions for implementing generators

upTo generates an integer between 0 (inclusive) and n.

genSplit :: Int -> Gen (Int, Int) Source #

'genSplit a' generates a tuple '(b, c)' such that 'b + c' equals a.

genSplit3 :: Int -> Gen (Int, Int, Int) Source #

'genSplit3 a' generates a triple '(b, c, d)' such that 'b + c + d' equals a.

genSplit4 :: Int -> Gen (Int, Int, Int, Int) Source #

'genSplit4 a' generates a quadruple '(b, c, d, e)' such that 'b + c + d + e' equals a.

genSplit5 :: Int -> Gen (Int, Int, Int, Int, Int) Source #

'genSplit5 a' generates a quintuple '(b, c, d, e, f)' such that 'b + c + d + e + f' equals a.

genSplit6 :: Int -> Gen (Int, Int, Int, Int, Int, Int) Source #

'genSplit6 a' generates a sextuple '(b, c, d, e, f, g)' such that 'b + c + d + e + f + g' equals a.

genSplit7 :: Int -> Gen (Int, Int, Int, Int, Int, Int, Int) Source #

'genSplit7 a' generates a septtuple '(b, c, d, e, f, g)' such that 'b + c + d + e + f + g' equals a.

genSplit8 :: Int -> Gen (Int, Int, Int, Int, Int, Int, Int, Int) Source #

'genSplit8 a' generates a octtuple '(b, c, d, e, f, g, h)' such that 'b + c + d + e + f + g + h' equals a.

'arbPartition n' generates a list ls such that 'sum ls' equals n, approximately.

shuffle :: [a] -> Gen [a] #

Generates a random permutation of the given list.

genListOf :: Gen a -> Gen [a] Source #

A version of listOf that takes size into account more accurately.

This generator distributes the size that is is given among the values in the list that it generates.

## Helper functions for implementing shrinking functions

shrinkTuple :: (a -> [a]) -> (b -> [b]) -> (a, b) -> [(a, b)] Source #

shrinkT2 :: (a -> [a]) -> (a, a) -> [(a, a)] Source #

Turn a shrinking function into a function that shrinks tuples.

shrinkT3 :: (a -> [a]) -> (a, a, a) -> [(a, a, a)] Source #

Turn a shrinking function into a function that shrinks triples.

shrinkT4 :: (a -> [a]) -> (a, a, a, a) -> [(a, a, a, a)] Source #

Turn a shrinking function into a function that shrinks quadruples.

genIntX :: forall a. (Integral a, Bounded a, Random a) => Gen a Source #

Generate Int, Int8, Int16, Int32 and Int64 values smartly.

• Some at the border
• Some around zero
• Mostly uniformly

genWordX :: forall a. (Integral a, Bounded a, Random a) => Gen a Source #

Generate Word, Word8, Word16, Word32 and Word64 values smartly.

• Some at the border
• Some around zero
• Mostly uniformly

See genFloatX

See genFloatX

genFloatX :: forall a w. (Read a, RealFloat a, Bounded w, Random w) => (w -> a) -> Gen a Source #

Generate floating point numbers smartly:

• Some denormalised
• Some around zero
• Some around the bounds
• Some by encoding an Integer and an Int to a floating point number.
• Some accross the entire range
• Mostly uniformly via the bitrepresentation

The function parameter is to go from the bitrepresentation to the floating point value.

shrinkUncheckedInt :: (Int -> a) -> (a -> Int) -> a -> [a] Source #

shrinkUncheckedWord :: (Word -> a) -> (a -> Word) -> a -> [a] Source #