| Safe Haskell | Safe-Inferred |
|---|---|
| Language | Haskell2010 |
Test.QuickCheck.DynamicLogic.Quantify
Description
This module defines Quantifications, which are used together with
forAllQ in DynamicLogic. A `Quantification t` can be used to generate
a t, shrink a t, and recognise a generated t.
Synopsis
- data Quantification a
- type QuantifyConstraints a = (Eq a, Show a, Typeable a, HasVariables a)
- isEmptyQ :: Quantification a -> Bool
- generateQ :: Quantification a -> Gen a
- shrinkQ :: Quantification a -> a -> [a]
- arbitraryQ :: Arbitrary a => Quantification a
- exactlyQ :: Eq a => a -> Quantification a
- elementsQ :: Eq a => [a] -> Quantification a
- oneofQ :: [Quantification a] -> Quantification a
- frequencyQ :: [(Int, Quantification a)] -> Quantification a
- mapQ :: (a -> b, b -> a) -> Quantification a -> Quantification b
- whereQ :: Quantification a -> (a -> Bool) -> Quantification a
- chooseQ :: (Arbitrary a, Random a, Ord a) => (a, a) -> Quantification a
- withGenQ :: Gen a -> (a -> Bool) -> (a -> [a]) -> Quantification a
- hasNoVariablesQ :: Quantification a -> Quantification (HasNoVariables a)
- validQuantification :: Show a => Quantification a -> Property
- class QuantifyConstraints (Quantifies q) => Quantifiable q where
- type Quantifies q
- quantify :: q -> Quantification (Quantifies q)
Documentation
data Quantification a Source #
A Quantification over a type a is a generator that can be used to generate random values in
DL scenarios.
A Quantification is similar to a Arbitrary, it groups together:
- A standard QuickCheck _generator_ in the
Genmonad, which can be "empty", - A _shrinking_ strategy for generated values in the case of a failures ensuring they stay within the domain,
- A _predicate_ allowing finer grained control on generation and shrinking process, e.g in the case the range of the generator depends on trace context.
NOTE: Leaving the possibility of generating Nothing is useful to simplify the generation
process for elements or frequency which may normally crash when the list to select
elements from is empty. This makes writing DL formulas cleaner, removing the need to
handle non-existence cases explicitly.
Instances
| QuantifyConstraints a => Quantifiable (Quantification a) Source # | |
Defined in Test.QuickCheck.DynamicLogic.Quantify Associated Types type Quantifies (Quantification a) Source # Methods quantify :: Quantification a -> Quantification (Quantifies (Quantification a)) Source # | |
| type Quantifies (Quantification a) Source # | |
Defined in Test.QuickCheck.DynamicLogic.Quantify | |
type QuantifyConstraints a = (Eq a, Show a, Typeable a, HasVariables a) Source #
isEmptyQ :: Quantification a -> Bool Source #
generateQ :: Quantification a -> Gen a Source #
shrinkQ :: Quantification a -> a -> [a] Source #
arbitraryQ :: Arbitrary a => Quantification a Source #
Pack up an Arbitrary instance as a Quantification. Treats all values as being in range.
exactlyQ :: Eq a => a -> Quantification a Source #
Generates exactly the given value. Does not shrink.
elementsQ :: Eq a => [a] -> Quantification a Source #
oneofQ :: [Quantification a] -> Quantification a Source #
Choose from a list of quantifications. Same as frequencyQ with all weights the same (and >
0).
frequencyQ :: [(Int, Quantification a)] -> Quantification a Source #
Choose from a weighted list of quantifications. Treated as an empty
choice if no quantification has weight > 0.
mapQ :: (a -> b, b -> a) -> Quantification a -> Quantification b Source #
Quantification is not a Functor, since it also keeps track of the range of the generators.
However, if you have two functions
to :: a -> b
from :: b -> a
satisfying from . to = id you can go from a quantification over a to one over b. Note
that the from function need only be defined on the image of to.
whereQ :: Quantification a -> (a -> Bool) -> Quantification a Source #
Restrict the range of a quantification.
chooseQ :: (Arbitrary a, Random a, Ord a) => (a, a) -> Quantification a Source #
Generate a random value in a given range (inclusive).
withGenQ :: Gen a -> (a -> Bool) -> (a -> [a]) -> Quantification a Source #
Construct a `Quantification a` from its constituents. Note the predicate provided is used to restrict both the range of values generated and the list of possible shrinked values.
hasNoVariablesQ :: Quantification a -> Quantification (HasNoVariables a) Source #
Wrap a Quantification in HasNoVariables to indicate that you know
what you're doing and there are no symbolic variables in the thing you
are quantifying over. WARNING: use this function carefully as there is
no guarantee that you won't get bitten by very strange failures if you
were in fact not honest about the lack of variables.
validQuantification :: Show a => Quantification a -> Property Source #
Turns a Quantification into a Property to enable QuickChecking its
validity.
class QuantifyConstraints (Quantifies q) => Quantifiable q where Source #
Generalization of Quantifications, which lets you treat lists and tuples of quantifications
as quantifications. For instance,
... (die1, die2) <-forAllQ(chooseQ(1, 6),chooseQ(1, 6)) ...
Associated Types
type Quantifies q Source #
The type of values quantified over.
Quantifies(Quantificationa) = a