hedgehog-1.0.5: Release with confidence.
Safe HaskellNone
LanguageHaskell2010

Hedgehog.Internal.Gen

Synopsis

Transformer

type Gen = GenT Identity Source #

Generator for random values of a.

newtype GenT m a Source #

Monad transformer which can generate random values of a.

Constructors

GenT 

Fields

Instances

Instances details
MMonad GenT Source # 
Instance details

Defined in Hedgehog.Internal.Gen

Methods

embed :: forall (n :: Type -> Type) m b. Monad n => (forall a. m a -> GenT n a) -> GenT m b -> GenT n b #

MonadTrans GenT Source # 
Instance details

Defined in Hedgehog.Internal.Gen

Methods

lift :: Monad m => m a -> GenT m a #

MonadTransDistributive GenT Source # 
Instance details

Defined in Hedgehog.Internal.Gen

Associated Types

type Transformer f GenT m Source #

Methods

distributeT :: forall f (m :: Type -> Type) a. Transformer f GenT m => GenT (f m) a -> f (GenT m) a Source #

MonadBase b m => MonadBase b (GenT m) Source # 
Instance details

Defined in Hedgehog.Internal.Gen

Methods

liftBase :: b α -> GenT m α #

MonadBaseControl b m => MonadBaseControl b (GenT m) Source # 
Instance details

Defined in Hedgehog.Internal.Gen

Associated Types

type StM (GenT m) a #

Methods

liftBaseWith :: (RunInBase (GenT m) b -> b a) -> GenT m a #

restoreM :: StM (GenT m) a -> GenT m a #

MonadWriter w m => MonadWriter w (GenT m) Source # 
Instance details

Defined in Hedgehog.Internal.Gen

Methods

writer :: (a, w) -> GenT m a #

tell :: w -> GenT m () #

listen :: GenT m a -> GenT m (a, w) #

pass :: GenT m (a, w -> w) -> GenT m a #

MonadState s m => MonadState s (GenT m) Source # 
Instance details

Defined in Hedgehog.Internal.Gen

Methods

get :: GenT m s #

put :: s -> GenT m () #

state :: (s -> (a, s)) -> GenT m a #

MonadReader r m => MonadReader r (GenT m) Source # 
Instance details

Defined in Hedgehog.Internal.Gen

Methods

ask :: GenT m r #

local :: (r -> r) -> GenT m a -> GenT m a #

reader :: (r -> a) -> GenT m a #

MonadError e m => MonadError e (GenT m) Source # 
Instance details

Defined in Hedgehog.Internal.Gen

Methods

throwError :: e -> GenT m a #

catchError :: GenT m a -> (e -> GenT m a) -> GenT m a #

Monad m => Monad (GenT m) Source # 
Instance details

Defined in Hedgehog.Internal.Gen

Methods

(>>=) :: GenT m a -> (a -> GenT m b) -> GenT m b #

(>>) :: GenT m a -> GenT m b -> GenT m b #

return :: a -> GenT m a #

Functor m => Functor (GenT m) Source # 
Instance details

Defined in Hedgehog.Internal.Gen

Methods

fmap :: (a -> b) -> GenT m a -> GenT m b #

(<$) :: a -> GenT m b -> GenT m a #

Monad m => MonadFail (GenT m) Source # 
Instance details

Defined in Hedgehog.Internal.Gen

Methods

fail :: String -> GenT m a #

Monad m => Applicative (GenT m) Source # 
Instance details

Defined in Hedgehog.Internal.Gen

Methods

pure :: a -> GenT m a #

(<*>) :: GenT m (a -> b) -> GenT m a -> GenT m b #

liftA2 :: (a -> b -> c) -> GenT m a -> GenT m b -> GenT m c #

(*>) :: GenT m a -> GenT m b -> GenT m b #

(<*) :: GenT m a -> GenT m b -> GenT m a #

MonadIO m => MonadIO (GenT m) Source # 
Instance details

Defined in Hedgehog.Internal.Gen

Methods

liftIO :: IO a -> GenT m a #

Monad m => Alternative (GenT m) Source # 
Instance details

Defined in Hedgehog.Internal.Gen

Methods

empty :: GenT m a #

(<|>) :: GenT m a -> GenT m a -> GenT m a #

some :: GenT m a -> GenT m [a] #

many :: GenT m a -> GenT m [a] #

Monad m => MonadPlus (GenT m) Source # 
Instance details

Defined in Hedgehog.Internal.Gen

Methods

mzero :: GenT m a #

mplus :: GenT m a -> GenT m a -> GenT m a #

MonadCatch m => MonadCatch (GenT m) Source # 
Instance details

Defined in Hedgehog.Internal.Gen

Methods

catch :: Exception e => GenT m a -> (e -> GenT m a) -> GenT m a #

MonadThrow m => MonadThrow (GenT m) Source # 
Instance details

Defined in Hedgehog.Internal.Gen

Methods

throwM :: Exception e => e -> GenT m a #

PrimMonad m => PrimMonad (GenT m) Source # 
Instance details

Defined in Hedgehog.Internal.Gen

Associated Types

type PrimState (GenT m) #

Methods

primitive :: (State# (PrimState (GenT m)) -> (# State# (PrimState (GenT m)), a #)) -> GenT m a #

MonadResource m => MonadResource (GenT m) Source # 
Instance details

Defined in Hedgehog.Internal.Gen

Methods

liftResourceT :: ResourceT IO a -> GenT m a #

Monad m => MonadGen (GenT m) Source # 
Instance details

Defined in Hedgehog.Internal.Gen

Associated Types

type GenBase (GenT m) :: Type -> Type Source #

Methods

toGenT :: GenT m a -> GenT (GenBase (GenT m)) a Source #

fromGenT :: GenT (GenBase (GenT m)) a -> GenT m a Source #

MFunctor GenT Source # 
Instance details

Defined in Hedgehog.Internal.Gen

Methods

hoist :: forall m n (b :: k). Monad m => (forall a. m a -> n a) -> GenT m b -> GenT n b #

(Monad m, Semigroup a) => Semigroup (GenT m a) Source # 
Instance details

Defined in Hedgehog.Internal.Gen

Methods

(<>) :: GenT m a -> GenT m a -> GenT m a #

sconcat :: NonEmpty (GenT m a) -> GenT m a #

stimes :: Integral b => b -> GenT m a -> GenT m a #

(Monad m, Monoid a) => Monoid (GenT m a) Source # 
Instance details

Defined in Hedgehog.Internal.Gen

Methods

mempty :: GenT m a #

mappend :: GenT m a -> GenT m a -> GenT m a #

mconcat :: [GenT m a] -> GenT m a #

type Transformer t GenT m Source # 
Instance details

Defined in Hedgehog.Internal.Gen

type PrimState (GenT m) Source # 
Instance details

Defined in Hedgehog.Internal.Gen

type PrimState (GenT m) = PrimState m
type GenBase (GenT m) Source # 
Instance details

Defined in Hedgehog.Internal.Gen

type GenBase (GenT m) = m
type StM (GenT m) a Source # 
Instance details

Defined in Hedgehog.Internal.Gen

type StM (GenT m) a = StM (ReaderT Size (ReaderT Seed (TreeT (MaybeT m)))) a

class (Monad m, Monad (GenBase m)) => MonadGen m where Source #

Class of monads which can generate input data for tests.

Associated Types

type GenBase m :: Type -> Type Source #

Methods

toGenT :: m a -> GenT (GenBase m) a Source #

Extract a GenT from a MonadGen.

fromGenT :: GenT (GenBase m) a -> m a Source #

Lift a GenT in to a MonadGen.

Instances

Instances details
MonadGen m => MonadGen (MaybeT m) Source # 
Instance details

Defined in Hedgehog.Internal.Gen

Associated Types

type GenBase (MaybeT m) :: Type -> Type Source #

Methods

toGenT :: MaybeT m a -> GenT (GenBase (MaybeT m)) a Source #

fromGenT :: GenT (GenBase (MaybeT m)) a -> MaybeT m a Source #

Monad m => MonadGen (GenT m) Source # 
Instance details

Defined in Hedgehog.Internal.Gen

Associated Types

type GenBase (GenT m) :: Type -> Type Source #

Methods

toGenT :: GenT m a -> GenT (GenBase (GenT m)) a Source #

fromGenT :: GenT (GenBase (GenT m)) a -> GenT m a Source #

MonadGen m => MonadGen (ExceptT x m) Source # 
Instance details

Defined in Hedgehog.Internal.Gen

Associated Types

type GenBase (ExceptT x m) :: Type -> Type Source #

Methods

toGenT :: ExceptT x m a -> GenT (GenBase (ExceptT x m)) a Source #

fromGenT :: GenT (GenBase (ExceptT x m)) a -> ExceptT x m a Source #

(MonadGen m, Monoid w) => MonadGen (WriterT w m) Source # 
Instance details

Defined in Hedgehog.Internal.Gen

Associated Types

type GenBase (WriterT w m) :: Type -> Type Source #

Methods

toGenT :: WriterT w m a -> GenT (GenBase (WriterT w m)) a Source #

fromGenT :: GenT (GenBase (WriterT w m)) a -> WriterT w m a Source #

MonadGen m => MonadGen (StateT r m) Source # 
Instance details

Defined in Hedgehog.Internal.Gen

Associated Types

type GenBase (StateT r m) :: Type -> Type Source #

Methods

toGenT :: StateT r m a -> GenT (GenBase (StateT r m)) a Source #

fromGenT :: GenT (GenBase (StateT r m)) a -> StateT r m a Source #

MonadGen m => MonadGen (ReaderT r m) Source # 
Instance details

Defined in Hedgehog.Internal.Gen

Associated Types

type GenBase (ReaderT r m) :: Type -> Type Source #

Methods

toGenT :: ReaderT r m a -> GenT (GenBase (ReaderT r m)) a Source #

fromGenT :: GenT (GenBase (ReaderT r m)) a -> ReaderT r m a Source #

MonadGen m => MonadGen (IdentityT m) Source # 
Instance details

Defined in Hedgehog.Internal.Gen

Associated Types

type GenBase (IdentityT m) :: Type -> Type Source #

MonadGen m => MonadGen (StateT r m) Source # 
Instance details

Defined in Hedgehog.Internal.Gen

Associated Types

type GenBase (StateT r m) :: Type -> Type Source #

Methods

toGenT :: StateT r m a -> GenT (GenBase (StateT r m)) a Source #

fromGenT :: GenT (GenBase (StateT r m)) a -> StateT r m a Source #

(MonadGen m, Monoid w) => MonadGen (WriterT w m) Source # 
Instance details

Defined in Hedgehog.Internal.Gen

Associated Types

type GenBase (WriterT w m) :: Type -> Type Source #

Methods

toGenT :: WriterT w m a -> GenT (GenBase (WriterT w m)) a Source #

fromGenT :: GenT (GenBase (WriterT w m)) a -> WriterT w m a Source #

Combinators

generalize :: Monad m => Gen a -> GenT m a Source #

Lift a Gen / GenT Identity in to a Monad m => GenT m

Shrinking

shrink :: MonadGen m => (a -> [a]) -> m a -> m a Source #

Apply a shrinking function to a generator.

This will give the generator additional shrinking options, while keeping the existing shrinks intact.

prune :: MonadGen m => m a -> m a Source #

Throw away a generator's shrink tree.

Size

small :: MonadGen m => m a -> m a Source #

Make a generator smaller by scaling its size parameter.

scale :: MonadGen m => (Size -> Size) -> m a -> m a Source #

Adjust the size parameter by transforming it with the given function.

resize :: MonadGen m => Size -> m a -> m a Source #

Override the size parameter. Returns a generator which uses the given size instead of the runtime-size parameter.

sized :: MonadGen m => (Size -> m a) -> m a Source #

Construct a generator that depends on the size parameter.

Integral

integral :: forall m a. (MonadGen m, Integral a) => Range a -> m a Source #

Generates a random integral number in the given [inclusive,inclusive] range.

When the generator tries to shrink, it will shrink towards the origin of the specified Range.

For example, the following generator will produce a number between 1970 and 2100, but will shrink towards 2000:

integral (Range.constantFrom 2000 1970 2100) :: Gen Int

Some sample outputs from this generator might look like:

=== Outcome ===
1973
=== Shrinks ===
2000
1987
1980
1976
1974
=== Outcome ===
2061
=== Shrinks ===
2000
2031
2046
2054
2058
2060

integral_ :: (MonadGen m, Integral a) => Range a -> m a Source #

Generates a random integral number in the [inclusive,inclusive] range.

This generator does not shrink.

int :: MonadGen m => Range Int -> m Int Source #

Generates a random machine integer in the given [inclusive,inclusive] range.

This is a specialization of integral, offered for convenience.

int8 :: MonadGen m => Range Int8 -> m Int8 Source #

Generates a random 8-bit integer in the given [inclusive,inclusive] range.

This is a specialization of integral, offered for convenience.

int16 :: MonadGen m => Range Int16 -> m Int16 Source #

Generates a random 16-bit integer in the given [inclusive,inclusive] range.

This is a specialization of integral, offered for convenience.

int32 :: MonadGen m => Range Int32 -> m Int32 Source #

Generates a random 32-bit integer in the given [inclusive,inclusive] range.

This is a specialization of integral, offered for convenience.

int64 :: MonadGen m => Range Int64 -> m Int64 Source #

Generates a random 64-bit integer in the given [inclusive,inclusive] range.

This is a specialization of integral, offered for convenience.

word :: MonadGen m => Range Word -> m Word Source #

Generates a random machine word in the given [inclusive,inclusive] range.

This is a specialization of integral, offered for convenience.

word8 :: MonadGen m => Range Word8 -> m Word8 Source #

Generates a random byte in the given [inclusive,inclusive] range.

This is a specialization of integral, offered for convenience.

word16 :: MonadGen m => Range Word16 -> m Word16 Source #

Generates a random 16-bit word in the given [inclusive,inclusive] range.

This is a specialization of integral, offered for convenience.

word32 :: MonadGen m => Range Word32 -> m Word32 Source #

Generates a random 32-bit word in the given [inclusive,inclusive] range.

This is a specialization of integral, offered for convenience.

word64 :: MonadGen m => Range Word64 -> m Word64 Source #

Generates a random 64-bit word in the given [inclusive,inclusive] range.

This is a specialization of integral, offered for convenience.

Floating-point

realFloat :: (MonadGen m, RealFloat a) => Range a -> m a Source #

Generates a random floating-point number in the [inclusive,exclusive) range.

This generator works the same as integral, but for floating point numbers.

realFrac_ :: (MonadGen m, RealFrac a) => Range a -> m a Source #

Generates a random fractional number in the [inclusive,exclusive) range.

This generator does not shrink.

float :: MonadGen m => Range Float -> m Float Source #

Generates a random floating-point number in the [inclusive,exclusive) range.

This is a specialization of realFloat, offered for convenience.

double :: MonadGen m => Range Double -> m Double Source #

Generates a random floating-point number in the [inclusive,exclusive) range.

This is a specialization of realFloat, offered for convenience.

Enumeration

enum :: (MonadGen m, Enum a) => a -> a -> m a Source #

Generates an element from an enumeration.

This generator shrinks towards the first argument.

For example:

enum 'a' 'z' :: Gen Char

enumBounded :: (MonadGen m, Enum a, Bounded a) => m a Source #

Generates a random value from a bounded enumeration.

This generator shrinks towards minBound.

For example:

enumBounded :: Gen Bool

This is implemented in terms of the Enum class, and thus may be partial for integral types larger than Int, e.g. Word64.

bool :: MonadGen m => m Bool Source #

Generates a random boolean.

This generator shrinks to False.

This is a specialization of enumBounded, offered for convenience.

bool_ :: MonadGen m => m Bool Source #

Generates a random boolean.

This generator does not shrink.

Characters

binit :: MonadGen m => m Char Source #

Generates an ASCII binit: '0'..'1'

octit :: MonadGen m => m Char Source #

Generates an ASCII octit: '0'..'7'

digit :: MonadGen m => m Char Source #

Generates an ASCII digit: '0'..'9'

hexit :: MonadGen m => m Char Source #

Generates an ASCII hexit: '0'..'9', 'a'..'f', 'A'..'F'

lower :: MonadGen m => m Char Source #

Generates an ASCII lowercase letter: 'a'..'z'

upper :: MonadGen m => m Char Source #

Generates an ASCII uppercase letter: 'A'..'Z'

alpha :: MonadGen m => m Char Source #

Generates an ASCII letter: 'a'..'z', 'A'..'Z'

alphaNum :: MonadGen m => m Char Source #

Generates an ASCII letter or digit: 'a'..'z', 'A'..'Z', '0'..'9'

ascii :: MonadGen m => m Char Source #

Generates an ASCII character: '0'..'127'

latin1 :: MonadGen m => m Char Source #

Generates a Latin-1 character: '0'..'255'

unicode :: MonadGen m => m Char Source #

Generates a Unicode character, excluding noncharacters and invalid standalone surrogates: '0'..'1114111' (excluding '55296'..'57343', '65534', '65535')

unicodeAll :: MonadGen m => m Char Source #

Generates a Unicode character, including noncharacters and invalid standalone surrogates: '0'..'1114111'

Strings

string :: MonadGen m => Range Int -> m Char -> m String Source #

Generates a string using Range to determine the length.

This is a specialization of list, offered for convenience.

text :: MonadGen m => Range Int -> m Char -> m Text Source #

Generates a string using Range to determine the length.

utf8 :: MonadGen m => Range Int -> m Char -> m ByteString Source #

Generates a UTF-8 encoded string, using Range to determine the length.

bytes :: MonadGen m => Range Int -> m ByteString Source #

Generates a random ByteString, using Range to determine the length.

Choice

constant :: MonadGen m => a -> m a Source #

Trivial generator that always produces the same element.

This is another name for pure / return.

element :: MonadGen m => [a] -> m a Source #

Randomly selects one of the elements in the list.

This generator shrinks towards the first element in the list.

The input list must be non-empty.

element_ :: MonadGen m => [a] -> m a Source #

Randomly selects one of the elements in the list.

This generator does not shrink the choice of element.

The input list must be non-empty.

choice :: MonadGen m => [m a] -> m a Source #

Randomly selects one of the generators in the list.

This generator shrinks towards the first generator in the list.

The input list must be non-empty.

frequency :: MonadGen m => [(Int, m a)] -> m a Source #

Uses a weighted distribution to randomly select one of the generators in the list.

This generator shrinks towards the first generator in the list.

The input list must be non-empty.

recursive :: MonadGen m => ([m a] -> m a) -> [m a] -> [m a] -> m a Source #

Modifies combinators which choose from a list of generators, like choice or frequency, so that they can be used in recursive scenarios.

This combinator modifies its target to select one of the generators in either the non-recursive or the recursive list. When a selection is made from the recursive list, the Size is halved. When the Size gets to one or less, selections are no longer made from the recursive list, this ensures termination.

A good example of where this might be useful is abstract syntax trees:

data Expr =
    Var String
  | Lam String Expr
  | App Expr Expr

-- Assuming we have a name generator
genName :: MonadGen m => m String

-- We can write a generator for expressions
genExpr :: MonadGen m => m Expr
genExpr =
  Gen.recursive Gen.choice [
      -- non-recursive generators
      Var <$> genName
    ] [
      -- recursive generators
      Gen.subtermM genExpr (x -> Lam <$> genName <*> pure x)
    , Gen.subterm2 genExpr genExpr App
    ]

If we wrote the above example using only choice, it is likely that it would fail to terminate. This is because for every call to genExpr, there is a 2 in 3 chance that we will recurse again.

Conditional

discard :: MonadGen m => m a Source #

Discards the whole generator.

ensure :: MonadGen m => (a -> Bool) -> m a -> m a Source #

Discards the generator if the generated value does not satisfy the predicate.

filter :: (MonadGen m, GenBase m ~ Identity) => (a -> Bool) -> m a -> m a Source #

Generates a value that satisfies a predicate.

This is essentially:

  filter p gen = mfilter p gen <|> filter p gen

It differs from the above in that we keep some state to avoid looping forever. If we trigger these limits then the whole generator is discarded.

mapMaybe :: (MonadGen m, GenBase m ~ Identity) => (a -> Maybe b) -> m a -> m b Source #

filterT :: MonadGen m => (a -> Bool) -> m a -> m a Source #

mapMaybeT :: MonadGen m => (a -> Maybe b) -> m a -> m b Source #

just :: (MonadGen m, GenBase m ~ Identity) => m (Maybe a) -> m a Source #

Runs a Maybe generator until it produces a Just.

This is implemented using filter and has the same caveats.

justT :: MonadGen m => m (Maybe a) -> m a Source #

Runs a Maybe generator until it produces a Just.

This is implemented using filter and has the same caveats.

Collections

maybe :: MonadGen m => m a -> m (Maybe a) Source #

Generates a Nothing some of the time.

either :: MonadGen m => m a -> m b -> m (Either a b) Source #

Generates either an a or a b.

As the size grows, this generator generates Rights more often than Lefts.

either_ :: MonadGen m => m a -> m b -> m (Either a b) Source #

Generates either an a or a b, without bias.

This generator generates as many Rights as it does Lefts.

list :: MonadGen m => Range Int -> m a -> m [a] Source #

Generates a list using a Range to determine the length.

seq :: MonadGen m => Range Int -> m a -> m (Seq a) Source #

Generates a seq using a Range to determine the length.

nonEmpty :: MonadGen m => Range Int -> m a -> m (NonEmpty a) Source #

Generates a non-empty list using a Range to determine the length.

set :: (MonadGen m, Ord a) => Range Int -> m a -> m (Set a) Source #

Generates a set using a Range to determine the length.

This may fail to generate anything if the element generator cannot produce a large enough number of unique items to satify the required set size.

map :: (MonadGen m, Ord k) => Range Int -> m (k, v) -> m (Map k v) Source #

Generates a map using a Range to determine the length.

This may fail to generate anything if the keys produced by the generator do not account for a large enough number of unique items to satify the required map size.

Subterms

freeze :: MonadGen m => m a -> m (a, m a) Source #

Freeze the size and seed used by a generator, so we can inspect the value which it will produce.

This is used for implementing list and subtermMVec. It allows us to shrink the list itself before trying to shrink the values inside the list.

subterm :: MonadGen m => m a -> (a -> a) -> m a Source #

Constructs a generator from a sub-term generator.

Shrinks to the sub-term if possible.

subtermM :: MonadGen m => m a -> (a -> m a) -> m a Source #

Constructs a generator from a sub-term generator.

Shrinks to the sub-term if possible.

subterm2 :: MonadGen m => m a -> m a -> (a -> a -> a) -> m a Source #

Constructs a generator from two sub-term generators.

Shrinks to one of the sub-terms if possible.

subtermM2 :: MonadGen m => m a -> m a -> (a -> a -> m a) -> m a Source #

Constructs a generator from two sub-term generators.

Shrinks to one of the sub-terms if possible.

subterm3 :: MonadGen m => m a -> m a -> m a -> (a -> a -> a -> a) -> m a Source #

Constructs a generator from three sub-term generators.

Shrinks to one of the sub-terms if possible.

subtermM3 :: MonadGen m => m a -> m a -> m a -> (a -> a -> a -> m a) -> m a Source #

Constructs a generator from three sub-term generators.

Shrinks to one of the sub-terms if possible.

Combinations & Permutations

subsequence :: MonadGen m => [a] -> m [a] Source #

Generates a random subsequence of a list.

shuffle :: MonadGen m => [a] -> m [a] Source #

Generates a random permutation of a list.

This shrinks towards the order of the list being identical to the input list.

shuffleSeq :: MonadGen m => Seq a -> m (Seq a) Source #

Generates a random permutation of a sequence.

This shrinks towards the order of the sequence being identical to the input sequence.

Sampling Generators

sample :: MonadIO m => Gen a -> m a Source #

Generate a sample from a generator.

print :: (MonadIO m, Show a) => Gen a -> m () Source #

Run a generator with a random seed and print the outcome, and the first level of shrinks.

Gen.print (Gen.enum 'a' 'f')
=== Outcome ===
'd'
=== Shrinks ===
'a'
'b'
'c'

printTree :: (MonadIO m, Show a) => Gen a -> m () Source #

Run a generator with a random seed and print the resulting shrink tree.

Gen.printTree (Gen.enum 'a' 'f')
'd'
 ├╼'a'
 ├╼'b'
 │  └╼'a'
 └╼'c'
    ├╼'a'
    └╼'b'
       └╼'a'

This may not terminate when the tree is very large.

printWith :: (MonadIO m, Show a) => Size -> Seed -> Gen a -> m () Source #

Print the value produced by a generator, and the first level of shrinks, for the given size and seed.

Use print to generate a value from a random seed.

printTreeWith :: (MonadIO m, Show a) => Size -> Seed -> Gen a -> m () Source #

Print the shrink tree produced by a generator, for the given size and seed.

Use printTree to generate a value from a random seed.

renderTree :: Show a => Size -> Seed -> Gen a -> String Source #

Render the shrink tree produced by a generator, for the given size and seed.

Internal

These functions are exported in case you need them in a pinch, but are not part of the public API and may change at any time, even as part of a minor update.

Transfomer

runGenT :: Size -> Seed -> GenT m a -> TreeT (MaybeT m) a Source #

Runs a generator, producing its shrink tree.

evalGen :: Size -> Seed -> Gen a -> Maybe (Tree a) Source #

Run a generator, producing its shrink tree.

Nothing means discarded, Just means we have a value.

evalGenT :: Monad m => Size -> Seed -> GenT m a -> TreeT m (Maybe a) Source #

Runs a generator, producing its shrink tree.

mapGenT :: (TreeT (MaybeT m) a -> TreeT (MaybeT n) b) -> GenT m a -> GenT n b Source #

Map over a generator's shrink tree.

generate :: MonadGen m => (Size -> Seed -> a) -> m a Source #

Generate a value with no shrinks from a Size and a Seed.

toTree :: forall m a. (MonadGen m, GenBase m ~ Identity) => m a -> m (Tree a) Source #

Observe a generator's shrink tree.

toTreeMaybeT :: MonadGen m => m a -> m (TreeT (MaybeT (GenBase m)) a) Source #

Lift a predefined shrink tree in to a generator, ignoring the seed and the size.

fromTree :: MonadGen m => Tree a -> m a Source #

Lift a predefined shrink tree in to a generator, ignoring the seed and the size.

fromTreeT :: MonadGen m => TreeT (GenBase m) a -> m a Source #

Lift a predefined shrink tree in to a generator, ignoring the seed and the size.

fromTreeMaybeT :: MonadGen m => TreeT (MaybeT (GenBase m)) a -> m a Source #

Lift a predefined shrink tree in to a generator, ignoring the seed and the size.

runDiscardEffect :: TreeT (MaybeT Identity) a -> Maybe (Tree a) Source #

Lazily run the discard effects through the tree and reify it a Maybe (Tree a).

Nothing means discarded, Just means we have a value.

Discards in the child nodes of the tree are simply removed.

runDiscardEffectT :: Monad m => TreeT (MaybeT m) a -> TreeT m (Maybe a) Source #

Run the discard effects through the tree and reify them as Maybe values at the nodes.

Nothing means discarded, Just means we have a value.

Size

golden :: Size -> Size Source #

Scale a size using the golden ratio.

golden x = x / φ
golden x = x / 1.61803..

Shrinking

atLeast :: Int -> [a] -> Bool Source #

Check that list contains at least a certain number of elements.

Characters

isSurrogate :: Char -> Bool Source #

Check if a character is in the surrogate category.

isNoncharacter :: Char -> Bool Source #

Check if a character is one of the noncharacters '65534', '65535'.

Subterms

data Vec n a where Source #

Constructors

Nil :: Vec 'Z a 
(:.) :: a -> Vec n a -> Vec ('S n) a infixr 5 

Instances

Instances details
Functor (Vec n) Source # 
Instance details

Defined in Hedgehog.Internal.Gen

Methods

fmap :: (a -> b) -> Vec n a -> Vec n b #

(<$) :: a -> Vec n b -> Vec n a #

Foldable (Vec n) Source # 
Instance details

Defined in Hedgehog.Internal.Gen

Methods

fold :: Monoid m => Vec n m -> m #

foldMap :: Monoid m => (a -> m) -> Vec n a -> m #

foldMap' :: Monoid m => (a -> m) -> Vec n a -> m #

foldr :: (a -> b -> b) -> b -> Vec n a -> b #

foldr' :: (a -> b -> b) -> b -> Vec n a -> b #

foldl :: (b -> a -> b) -> b -> Vec n a -> b #

foldl' :: (b -> a -> b) -> b -> Vec n a -> b #

foldr1 :: (a -> a -> a) -> Vec n a -> a #

foldl1 :: (a -> a -> a) -> Vec n a -> a #

toList :: Vec n a -> [a] #

null :: Vec n a -> Bool #

length :: Vec n a -> Int #

elem :: Eq a => a -> Vec n a -> Bool #

maximum :: Ord a => Vec n a -> a #

minimum :: Ord a => Vec n a -> a #

sum :: Num a => Vec n a -> a #

product :: Num a => Vec n a -> a #

Traversable (Vec n) Source # 
Instance details

Defined in Hedgehog.Internal.Gen

Methods

traverse :: Applicative f => (a -> f b) -> Vec n a -> f (Vec n b) #

sequenceA :: Applicative f => Vec n (f a) -> f (Vec n a) #

mapM :: Monad m => (a -> m b) -> Vec n a -> m (Vec n b) #

sequence :: Monad m => Vec n (m a) -> m (Vec n a) #

data Nat Source #

Constructors

Z 
S Nat 

subtermMVec :: MonadGen m => Vec n (m a) -> (Vec n a -> m a) -> m a Source #

Constructs a generator from a number of sub-term generators.

Shrinks to one of the sub-terms if possible.