Safe Haskell | None |
---|---|
Language | Haskell2010 |
Simple GHC.Generics-based arbitrary
generators.
For more information:
- genericArbitrary :: GArbitrary UnsizedOpts a => Weights a -> Gen a
- genericArbitraryU :: (GArbitrary UnsizedOpts a, GUniformWeight a) => Gen a
- genericArbitrarySingle :: (GArbitrary UnsizedOpts a, Weights_ (Rep a) ~ L c0) => Gen a
- genericArbitraryRec :: GArbitrary SizedOptsDef a => Weights a -> Gen a
- genericArbitrary' :: (GArbitrary SizedOptsDef a, BaseCase a) => Weights a -> Gen a
- genericArbitraryU' :: (GArbitrary SizedOptsDef a, BaseCase a, GUniformWeight a) => Gen a
- genericArbitraryG :: GArbitrary (SetGens genList UnsizedOpts) a => genList -> Weights a -> Gen a
- genericArbitraryUG :: (GArbitrary (SetGens genList UnsizedOpts) a, GUniformWeight a) => genList -> Gen a
- genericArbitrarySingleG :: (GArbitrary (SetGens genList UnsizedOpts) a, Weights_ (Rep a) ~ L c0) => genList -> Gen a
- genericArbitraryRecG :: GArbitrary (SetGens genList SizedOpts) a => genList -> Weights a -> Gen a
- genericArbitraryWith :: GArbitrary opts a => opts -> Weights a -> Gen a
- withBaseCase :: Gen a -> Gen a -> Gen a
- class BaseCase a where
- data Weights a
- data W (c :: Symbol)
- (%) :: WeightBuilder' w => W (First' w) -> Prec' w -> w
- uniform :: UniformWeight_ (Rep a) => Weights a
- data Options (s :: Sizing) (genList :: Type)
- type SizedOpts = Options Sized ()
- sizedOpts :: SizedOpts
- type SizedOptsDef = Options Sized (Gen1 [] :+ ())
- sizedOptsDef :: SizedOptsDef
- type UnsizedOpts = Options Unsized ()
- unsizedOpts :: UnsizedOpts
- data Sizing
- setSized :: Options s g -> Options Sized g
- setUnsized :: Options s g -> Options Unsized g
- data a :+ b = a :+ b
- newtype FieldGen (s :: Symbol) a = FieldGen {
- unFieldGen :: Gen a
- fieldGen :: proxy s -> Gen a -> FieldGen s a
- newtype Gen1 f = Gen1 {}
- newtype Gen1_ f = Gen1_ {}
- setGenerators :: genList -> Options s g0 -> Options s genList
- class (Generic a, GA opts (Rep a)) => GArbitrary opts a
- class UniformWeight_ (Rep a) => GUniformWeight a
- listOf' :: Gen a -> Gen [a]
- listOf1' :: Gen a -> Gen [a]
- vectorOf' :: Int -> Gen a -> Gen [a]
Arbitrary implementations
:: GArbitrary UnsizedOpts a | |
=> Weights a | List of weights for every constructor |
-> Gen a |
Pick a constructor with a given distribution, and fill its fields
with recursive calls to arbitrary
.
Example
genericArbitrary (2 % 3 % 5 % ()) :: Gen a
Picks the first constructor with probability 2/10
,
the second with probability 3/10
, the third with probability 5/10
.
genericArbitraryU :: (GArbitrary UnsizedOpts a, GUniformWeight a) => Gen a Source #
Pick every constructor with equal probability.
Equivalent to
.genericArbitrary
uniform
genericArbitraryU :: Gen a
genericArbitrarySingle :: (GArbitrary UnsizedOpts a, Weights_ (Rep a) ~ L c0) => Gen a Source #
arbitrary
for types with one constructor.
Equivalent to genericArbitraryU
, with a stricter type.
genericArbitrarySingle :: Gen a
:: GArbitrary SizedOptsDef a | |
=> Weights a | List of weights for every constructor |
-> Gen a |
Decrease size at every recursive call, but don't do anything different at size 0.
genericArbitraryRec (7 % 11 % 13 % ()) :: Gen a
N.B.: This replaces fields of type [t]
with
.listOf'
arbitrary
:: (GArbitrary SizedOptsDef a, BaseCase a) | |
=> Weights a | List of weights for every constructor |
-> Gen a |
Decrease size to ensure termination for recursive types, looking for base cases once the size reaches 0.
genericArbitrary' (17 % 19 % 23 % ()) :: Gen a
N.B.: This replaces fields of type [t]
with
.listOf'
arbitrary
genericArbitraryU' :: (GArbitrary SizedOptsDef a, BaseCase a, GUniformWeight a) => Gen a Source #
Equivalent to
.genericArbitrary'
uniform
genericArbitraryU :: Gen a
N.B.: This replaces fields of type [t]
with
.listOf'
arbitrary
genericArbitraryG :: GArbitrary (SetGens genList UnsizedOpts) a => genList -> Weights a -> Gen a Source #
genericArbitrary
with explicit generators.
Example
genericArbitraryG customGens (17 % 19 % ())
where, for example to override generators for String
and Int
fields,
customGens ::GenList
'[String, Int] customGens = (filter (/= '\NUL')<$>
arbitrary):@
(getNonNegative<$>
arbitrary):@
Nil
Note on multiple matches
If the list contains multiple matching types for a field x
of type a
(i.e., either a
or
), the generator for the first
match will be picked.Field
"x" a
genericArbitraryUG :: (GArbitrary (SetGens genList UnsizedOpts) a, GUniformWeight a) => genList -> Gen a Source #
genericArbitraryU
with explicit generators.
See also genericArbitraryG
.
genericArbitrarySingleG :: (GArbitrary (SetGens genList UnsizedOpts) a, Weights_ (Rep a) ~ L c0) => genList -> Gen a Source #
genericArbitrarySingle
with explicit generators.
See also genericArbitraryG
.
:: GArbitrary (SetGens genList SizedOpts) a | |
=> genList | |
-> Weights a | List of weights for every constructor |
-> Gen a |
genericArbitraryRec
with explicit generators.
See also genericArbitraryG
.
genericArbitraryWith :: GArbitrary opts a => opts -> Weights a -> Gen a Source #
General generic generator with custom options.
Base cases for recursive types
withBaseCase :: Gen a -> Gen a -> Gen a Source #
Run the first generator if the size is positive. Run the second if the size is zero.
defaultGen `withBaseCase` baseCaseGen
class BaseCase a where Source #
Custom instances can override the default behavior.
BaseCaseSearching Nat a 0 => BaseCase a Source # | Overlappable |
Specifying finite distributions
Trees of weights assigned to constructors of type a
,
rescaled to obtain a probability distribution.
Two ways of constructing them.
(x1%
x2%
...%
xn%
()) ::Weights
auniform
::Weights
a
Using (
, there must be exactly as many weights as
there are constructors.%
)
uniform
is equivalent to (1
(automatically fills out the right number of 1s).%
... %
1 %
())
WeightBuilder (Weights_ (Rep a)) => WeightBuilder' (Weights a) Source # | |
(%) :: WeightBuilder' w => W (First' w) -> Prec' w -> w infixr 1 Source #
A binary constructor for building up trees of weights.
Full options
sizedOptsDef :: SizedOptsDef Source #
Default options overriding the list generator using listOf'
.
type UnsizedOpts = Options Unsized () Source #
unsizedOpts :: UnsizedOpts Source #
Default options for unsized generators.
Heterogeneous list of generators.
a :+ b infixr 1 |
ArbitraryOr fg g sel a => ArbitraryOr fg ((:+) b g) sel a Source # | |
ArbitraryOr fg ((:+) (Gen a) g) sel a Source # | |
ArbitraryOr fg fg (Nothing Symbol) a => ArbitraryOr fg ((:+) (Gen1 f) g) sel (f a) Source # | |
ArbitraryOr fg ((:+) (Gen1_ k f) g) sel (f a) Source # | |
ArbitraryOr fg ((:+) (FieldGen n a) g) (Just Symbol n) a Source # | |
newtype FieldGen (s :: Symbol) a Source #
A generator which overrides a specific field named s
.
Available only for base >= 4.9
.
FieldGen | |
|
fieldGen :: proxy s -> Gen a -> FieldGen s a Source #
Field
constructor with the field name given via a proxy.
Generators for containers of kind * -> *
, parameterized by
the generator for each element.
ArbitraryOr fg fg (Nothing Symbol) a => ArbitraryOr fg ((:+) (Gen1 f) g) sel (f a) Source # | |
Generators for unary type constructors that are not containers.
ArbitraryOr fg ((:+) (Gen1_ k f) g) sel (f a) Source # | |
setGenerators :: genList -> Options s g0 -> Options s genList Source #
Public classes
class UniformWeight_ (Rep a) => GUniformWeight a Source #
Derived uniform distribution of constructors for a
.
UniformWeight_ (Rep a) => GUniformWeight a Source # | |
Helpful combinators
listOf' :: Gen a -> Gen [a] Source #
An alternative to listOf
that divides the size parameter by the
length of the list.
The length follows a geometric distribution of parameter
1/(sqrt size + 1)
.