genvalidity-1.1.0.0: Testing utilities for the validity library
Safe HaskellSafe-Inferred
LanguageHaskell2010

Data.GenValidity.Utils

Synopsis

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] #

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.

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

A version of genNonEmptyOf that returns a list instead of a NonEmptyList.

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

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.

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]] #

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

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