Safe Haskell | Safe-Inferred |
---|---|
Language | Haskell2010 |
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
- 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 -> [a]) -> Quantification a
- validQuantification :: Show a => Quantification a -> Property
- class (Eq (Quantifies q), Show (Quantifies q), Typeable (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 with
forAllQ
to generate random values in
DL scenarios. In addition to a QuickCheck generator a Quantification
contains a shrinking
strategy that ensures that shrunk values stay in the range of the generator.
Instances
(Eq a, Show a, Typeable a) => Quantifiable (Quantification a) Source # | |
Defined in Test.QuickCheck.DynamicLogic.Quantify type Quantifies (Quantification a) Source # quantify :: Quantification a -> Quantification (Quantifies (Quantification a)) Source # | |
type Quantifies (Quantification a) Source # | |
Defined in Test.QuickCheck.DynamicLogic.Quantify |
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 -> [a]) -> Quantification a Source #
Wrap a `Gen a` generator in a `Quantification a`. Uses given shrinker.
validQuantification :: Show a => Quantification a -> Property Source #
class (Eq (Quantifies q), Show (Quantifies q), Typeable (Quantifies q)) => Quantifiable q where Source #
Generalization of Quantification
s, which lets you treat lists and tuples of quantifications
as quantifications. For instance,
... (die1, die2) <-forAllQ
(chooseQ
(1, 6),chooseQ
(1, 6)) ...
type Quantifies q Source #
The type of values quantified over.
Quantifies
(Quantification
a) = a
quantify :: q -> Quantification (Quantifies q) Source #
Computing the actual Quantification
.