quickcheck-dynamic-3.4.0: A library for stateful property-based testing
Safe HaskellSafe-Inferred
LanguageHaskell2010

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

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 Gen monad, 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.

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 #

Pick a random value from a list. Treated as an empty choice if the list is empty:

forAllQ (elementsQ []) == empty

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 (Quantification a) = a

Methods

quantify :: q -> Quantification (Quantifies q) Source #

Computing the actual Quantification.

Instances

Instances details
QuantifyConstraints a => Quantifiable (Quantification a) Source # 
Instance details

Defined in Test.QuickCheck.DynamicLogic.Quantify

Associated Types

type Quantifies (Quantification a) Source #

Quantifiable a => Quantifiable [a] Source # 
Instance details

Defined in Test.QuickCheck.DynamicLogic.Quantify

Associated Types

type Quantifies [a] Source #

Methods

quantify :: [a] -> Quantification (Quantifies [a]) Source #

(Quantifiable a, Quantifiable b) => Quantifiable (a, b) Source # 
Instance details

Defined in Test.QuickCheck.DynamicLogic.Quantify

Associated Types

type Quantifies (a, b) Source #

Methods

quantify :: (a, b) -> Quantification (Quantifies (a, b)) Source #

(Quantifiable a, Quantifiable b, Quantifiable c) => Quantifiable (a, b, c) Source # 
Instance details

Defined in Test.QuickCheck.DynamicLogic.Quantify

Associated Types

type Quantifies (a, b, c) Source #

Methods

quantify :: (a, b, c) -> Quantification (Quantifies (a, b, c)) Source #

(Quantifiable a, Quantifiable b, Quantifiable c, Quantifiable d) => Quantifiable (a, b, c, d) Source # 
Instance details

Defined in Test.QuickCheck.DynamicLogic.Quantify

Associated Types

type Quantifies (a, b, c, d) Source #

Methods

quantify :: (a, b, c, d) -> Quantification (Quantifies (a, b, c, d)) Source #

(Quantifiable a, Quantifiable b, Quantifiable c, Quantifiable d, Quantifiable e) => Quantifiable (a, b, c, d, e) Source # 
Instance details

Defined in Test.QuickCheck.DynamicLogic.Quantify

Associated Types

type Quantifies (a, b, c, d, e) Source #

Methods

quantify :: (a, b, c, d, e) -> Quantification (Quantifies (a, b, c, d, e)) Source #