genvalidity-1.1.1.0: Testing utilities for the validity library

Safe Haskell | Safe-Inferred
Language | Haskell2010

Data.GenValidity.Utils

Contents

- Helper functions for implementing generators
- Helper functions for implementing shrinking functions

Synopsis

- upTo :: Int -> Gen Int
- genSplit :: Int -> Gen (Int, Int)
- genSplit3 :: Int -> Gen (Int, Int, Int)
- genSplit4 :: Int -> Gen (Int, Int, Int, Int)
- genSplit5 :: Int -> Gen (Int, Int, Int, Int, Int)
- genSplit6 :: Int -> Gen (Int, Int, Int, Int, Int, Int)
- genSplit7 :: Int -> Gen (Int, Int, Int, Int, Int, Int, Int)
- genSplit8 :: Int -> Gen (Int, Int, Int, Int, Int, Int, Int, Int)
- arbPartition :: Int -> Gen [Int]
- shuffle :: [a] -> Gen [a]
- genListLength :: Gen Int
- genStringBy :: Gen Char -> Gen String
- genStringBy1 :: Gen Char -> Gen String
- genListOf :: Gen a -> Gen [a]
- genListOf1 :: Gen a -> Gen [a]
- genMaybe :: Gen a -> Gen (Maybe a)
- genNonEmptyOf :: Gen a -> Gen (NonEmpty a)
- genIntX :: (Integral a, Bounded a, Random a) => Gen a
- genWordX :: (Integral a, Bounded a, Random a) => Gen a
- genFloat :: Gen Float
- genDouble :: Gen Double
- genFloatX :: (Read a, RealFloat a, Bounded w, Random w) => (w -> a) -> Gen a
- genInteger :: Gen Integer
- shrinkMaybe :: (a -> [a]) -> Maybe a -> [Maybe a]
- shrinkTuple :: (a -> [a]) -> (b -> [b]) -> (a, b) -> [(a, b)]
- shrinkTriple :: (a -> [a]) -> (b -> [b]) -> (c -> [c]) -> (a, b, c) -> [(a, b, c)]
- shrinkQuadruple :: (a -> [a]) -> (b -> [b]) -> (c -> [c]) -> (d -> [d]) -> (a, b, c, d) -> [(a, b, c, d)]
- shrinkT2 :: (a -> [a]) -> (a, a) -> [(a, a)]
- shrinkT3 :: (a -> [a]) -> (a, a, a) -> [(a, a, a)]
- shrinkT4 :: (a -> [a]) -> (a, a, a, a) -> [(a, a, a, a)]
- shrinkList :: (a -> [a]) -> [a] -> [[a]]
- shrinkNonEmpty :: (a -> [a]) -> NonEmpty a -> [NonEmpty a]

## Helper functions for implementing generators

upTo :: Int -> Gen Int Source #

`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 :: Int -> Gen [Int] Source #

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

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

Generates a random permutation of the given list.

genListLength :: Gen Int Source #

genStringBy :: Gen Char -> Gen String Source #

genStringBy1 :: Gen Char -> Gen String Source #

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.

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

A version of `genNonEmptyOf` that returns a list instead of a `NonEmpty`.

genMaybe :: Gen a -> Gen (Maybe a) Source #

genNonEmptyOf :: Gen a -> Gen (NonEmpty a) Source #

genIntX :: (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 :: (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

genFloat :: Gen Float Source #

See `genFloatX`

genDouble :: Gen Double Source #

See `genFloatX`

genFloatX :: (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.

genInteger :: Gen Integer Source #

## Helper functions for implementing shrinking functions

shrinkMaybe :: (a -> [a]) -> Maybe a -> [Maybe a] Source #

Lift a shrinker function into a maybe

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

Combine two shrinking functions to shrink a tuple.

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

Like `shrinkTuple`, but for triples

shrinkQuadruple :: (a -> [a]) -> (b -> [b]) -> (c -> [c]) -> (d -> [d]) -> (a, b, c, d) -> [(a, b, c, d)] Source #

Like `shrinkTuple`, but for quadruples

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.

shrinkList :: (a -> [a]) -> [a] -> [[a]] Source #

Shrink a list of values given a shrinking function for individual values.

shrinkNonEmpty :: (a -> [a]) -> NonEmpty a -> [NonEmpty a] Source #