Module

Test.QuickCheck.Gen

Package
purescript-quickcheck
Repository
purescript/purescript-quickcheck

This module defines the random generator monad used by the Test.QuickCheck module, as well as helper functions for constructing random generators.

#Size Source

type Size = Int

Tests are parameterized by the Size of the randomly-generated data, the meaning of which depends on the particular generator used.

#GenState Source

type GenState = { newSeed :: Seed, size :: Size }

The state of the random generator monad

#Gen Source

newtype Gen a

The random generator monad

Gen is a state monad which encodes a linear congruential generator.

Instances

#unGen Source

unGen :: forall a. Gen a -> State GenState a

Exposes the underlying State implementation.

#repeatable Source

repeatable :: forall b a. (a -> Gen b) -> Gen (a -> b)

Create a random generator for a function type.

#stateful Source

stateful :: forall a. (GenState -> Gen a) -> Gen a

Create a random generator which uses the generator state explicitly.

#variant Source

variant :: forall a. Seed -> Gen a -> Gen a

Modify a random generator by setting a new random seed.

#suchThat Source

suchThat :: forall a. Gen a -> (a -> Boolean) -> Gen a

Ensure that a generator only produces values that match a predicate. If the predicate always returns false the generator will loop forever.

#sized Source

sized :: forall a. (Size -> Gen a) -> Gen a

Create a random generator which depends on the size parameter.

#resize Source

resize :: forall a. Size -> Gen a -> Gen a

Modify a random generator by setting a new size parameter.

#choose Source

choose :: Number -> Number -> Gen Number

Create a random generator which samples a range of Numbers i with uniform probability.

#chooseInt Source

chooseInt :: Int -> Int -> Gen Int

Create a random generator which chooses uniformly distributed integers from the closed interval [a, b]. Note that very large intervals will cause a loss of uniformity.

#oneOf Source

oneOf :: forall a. NonEmpty Array (Gen a) -> Gen a

Create a random generator which selects and executes a random generator from a non-empty array of random generators with uniform probability.

#frequency Source

frequency :: forall a. NonEmpty List (Tuple Number (Gen a)) -> Gen a

Create a random generator which selects and executes a random generator from a non-empty, weighted list of random generators.

#arrayOf Source

arrayOf :: forall a. Gen a -> Gen (Array a)

Create a random generator which generates an array of random values.

#arrayOf1 Source

arrayOf1 :: forall a. Gen a -> Gen (NonEmpty Array a)

Create a random generator which generates a non-empty array of random values.

#listOf Source

listOf :: forall a. Int -> Gen a -> Gen (List a)

Create a random generator which generates a list of random values of the specified size.

#vectorOf Source

vectorOf :: forall a. Int -> Gen a -> Gen (Array a)

Create a random generator which generates a vector of random values of a specified size.

#elements Source

elements :: forall a. NonEmpty Array a -> Gen a

Create a random generator which selects a value from a non-empty array with uniform probability.

#shuffle Source

shuffle :: forall a. Array a -> Gen (Array a)

Generate a random permutation of the given array

#runGen Source

runGen :: forall a. Gen a -> GenState -> Tuple a GenState

Run a random generator

#evalGen Source

evalGen :: forall a. Gen a -> GenState -> a

Run a random generator, keeping only the randomly-generated result

#sample Source

sample :: forall a. Seed -> Size -> Gen a -> Array a

Sample a random generator

#randomSample' Source

randomSample' :: forall a r. Size -> Gen a -> Eff (random :: RANDOM | r) (Array a)

Sample a random generator, using a randomly generated seed

#randomSample Source

randomSample :: forall a r. Gen a -> Eff (random :: RANDOM | r) (Array a)

Get a random sample of 10 values

#uniform Source

uniform :: Gen Number

A random generator which approximates a uniform random variable on [0, 1]

#perturbGen Source

perturbGen :: forall a. Number -> Gen a -> Gen a

Perturb a random generator by modifying the current seed