Safe Haskell | None |
---|---|
Language | Haskell2010 |
Test.QuickCheck.HigherOrder
Contents
Description
QuickCheck extension for properties of higher-order values.
See the README for an introduction.
Synopsis
- class (Arbitrary (Repr a), Show (Repr a)) => Constructible a where
- quickCheck' :: Testable' prop => prop -> IO ()
- quickCheckWith' :: Testable' prop => Args -> prop -> IO ()
- class Testable' prop where
- data Equation a = (:=:) a a
- data Implication a b = (:==>) a b
- type EqImpl a b = Implication (Equation a) (Equation b)
- class Decidable a where
- class TestEq a where
- decEq :: (Eq a, Show a) => a -> a -> Property
- ok :: Testable' prop => String -> prop -> (String, Property)
- ko :: Testable' prop => String -> prop -> (String, Property)
- quickChecks :: [(String, Property)] -> IO Bool
- forAll_ :: forall a prop. (Constructible a, Testable' prop) => (a -> prop) -> Property
- data Constructed a
- pattern Construct :: a -> Constructed a
- data a :-> r
- applyFun :: (a :-> r) -> a -> r
- class Applicative gen => CoArbitrary (gen :: Type -> Type) a where
- coarbitrary :: Co gen a r
- cogenEmbed :: Functor gen => FunName -> (a -> b) -> Co gen b r -> Co gen a r
- cogenIntegral :: (Applicative gen, Integral a) => TypeName -> Co gen a r
- coarbitraryGeneric :: (Generic a, GCoArbitrary gen a) => Co gen a r
Constructible values
class (Arbitrary (Repr a), Show (Repr a)) => Constructible a where Source #
A Constructible
type is associated with a type of "finite descriptions"
that can be generated, shown (e.g., as counterexamples in QuickCheck), and
interpreted as values.
This enhances Arbitrary
and Show
used by vanilla QuickCheck.
The main motivating example is the type of functions, which can be
finitely represented by the type (
(see also Test.Fun).:->
)
It turns out we can define Constructible
for just about anything
except IO
(for now...).
Instances
Constructible Bool Source # | |
Constructible Char Source # | |
Constructible Double Source # | |
Constructible Int Source # | |
Constructible Integer Source # | |
Constructible Ordering Source # | |
Constructible Word Source # | |
Constructible () Source # | |
Constructible a => Constructible [a] Source # | |
Constructible a => Constructible (Maybe a) Source # | |
Constructible a => Constructible (Identity a) Source # | |
Constructible a => Constructible (Sum a) Source # | |
(CoArbitrary Gen a, Constructible b) => Constructible (a -> b) Source # | |
(Constructible a, Constructible b) => Constructible (Either a b) Source # | |
(Constructible a, Constructible b) => Constructible (a, b) Source # | |
(CoArbitrary a, Function a, Show a, Constructible b) => Constructible (Fun a b) Source # | |
Runners
quickCheck' :: Testable' prop => prop -> IO () Source #
Variant of quickCheck
using the alternative Testable'
.
quickCheckWith' :: Testable' prop => Args -> prop -> IO () Source #
Variant of quickCheckWith
using the alternative Testable'
.
Testable properties
class Testable' prop where Source #
Types that represent testable properties.
This is a clone of the Testable
class with an improved function instance.
Instances
Testable' Bool Source # | |
Testable' Property Source # | A property' @Property = property @Property = id |
Testable' a => Testable' (Gen a) Source # | A generator represents a universally quantified property. |
TestEq a => Testable' (Equation a) Source # | |
(Constructible a, Testable' b) => Testable' (a -> b) Source # | A function represents a universally quantified property. |
(Decidable a, Testable' b) => Testable' (Implication a b) Source # | Just use |
Defined in Test.QuickCheck.HigherOrder.Internal.Testable Methods property' :: Implication a b -> Property Source # |
Types of testable properties
Equation: an equals sign between two values.
Constructors
(:=:) a a infix 5 |
Instances
Eq a => Eq (Equation a) Source # | |
Ord a => Ord (Equation a) Source # | |
Show a => Show (Equation a) Source # | |
TestEq a => Testable (Equation a) Source # | |
TestEq a => Testable' (Equation a) Source # | |
Eq a => Decidable (Equation a) Source # | |
data Implication a b Source #
Expressions denoting a logical implication.
Constructors
(:==>) a b infixr 2 |
Instances
(Decidable a, Testable b) => Testable (Implication a b) Source # | Just use |
Defined in Test.QuickCheck.HigherOrder.Internal.Testable Methods property :: Implication a b -> Property # propertyForAllShrinkShow :: Gen a0 -> (a0 -> [a0]) -> (a0 -> [String]) -> (a0 -> Implication a b) -> Property # | |
(Decidable a, Testable' b) => Testable' (Implication a b) Source # | Just use |
Defined in Test.QuickCheck.HigherOrder.Internal.Testable Methods property' :: Implication a b -> Property Source # |
Decidable properties
class Decidable a where Source #
Decidable property.
Methods
The definition of decidability: we can compute whether a property is true.
Testable equality
Testable equality
Methods
Instances
TestEq Bool Source # | |
TestEq Char Source # | |
TestEq Double Source # | |
TestEq Int Source # | |
TestEq Integer Source # | |
TestEq Ordering Source # | |
TestEq Word Source # | |
TestEq () Source # | |
Defined in Test.QuickCheck.HigherOrder.Internal.TestEq | |
TestEq a => TestEq [a] Source # | |
Defined in Test.QuickCheck.HigherOrder.Internal.TestEq | |
TestEq a => TestEq (Maybe a) Source # | |
TestEq a => TestEq (Identity a) Source # | |
TestEq a => TestEq (Sum a) Source # | |
(Constructible a, TestEq b) => TestEq (a -> b) Source # | |
Defined in Test.QuickCheck.HigherOrder.Internal.TestEq | |
(TestEq a, TestEq b) => TestEq (Either a b) Source # | |
(TestEq a, TestEq b) => TestEq (a, b) Source # | |
Defined in Test.QuickCheck.HigherOrder.Internal.TestEq |
Helpers
ok :: Testable' prop => String -> prop -> (String, Property) Source #
A named property that should pass.
Use ok
and ko
to construct lists of named properties
[(
, which can be run using String
, Property
)]quickChecks
,
or testProperties
from tasty-quickcheck.
ko :: Testable' prop => String -> prop -> (String, Property) Source #
A named property that should fail.
See also ok
.
Constructible
wrappers
data Constructed a Source #
Constructible
wrapper with Show
and Arbitrary
instances
that operate on the representation of the argument type.
Deconstruct with the Construct
pattern.
This is only useful for property combinators from vanilla QuickCheck, that
use the original Testable
class instead of
Testable'
from this library.
Instances
Constructible a => Show (Constructed a) Source # | |
Defined in Test.QuickCheck.HigherOrder.Internal.Constructible Methods showsPrec :: Int -> Constructed a -> ShowS # show :: Constructed a -> String # showList :: [Constructed a] -> ShowS # | |
Constructible a => Arbitrary (Constructed a) Source # | |
pattern Construct :: a -> Constructed a Source #
A unidirectional pattern to deconstruct Constructed
values.
CoArbitrary
See also the documentation of Test.Fun.
Testable representation of functions (a -> r)
.
This representation supports random generation, shrinking, and printing, for property testing with QuickCheck or Hedgehog.
Higher-order functions can be represented.
Instances
Functor ((:->) a) | |
Foldable ((:->) a) | |
Defined in Test.Fun.Internal.Types Methods fold :: Monoid m => (a :-> m) -> m # foldMap :: Monoid m => (a0 -> m) -> (a :-> a0) -> m # foldr :: (a0 -> b -> b) -> b -> (a :-> a0) -> b # foldr' :: (a0 -> b -> b) -> b -> (a :-> a0) -> b # foldl :: (b -> a0 -> b) -> b -> (a :-> a0) -> b # foldl' :: (b -> a0 -> b) -> b -> (a :-> a0) -> b # foldr1 :: (a0 -> a0 -> a0) -> (a :-> a0) -> a0 # foldl1 :: (a0 -> a0 -> a0) -> (a :-> a0) -> a0 # toList :: (a :-> a0) -> [a0] # elem :: Eq a0 => a0 -> (a :-> a0) -> Bool # maximum :: Ord a0 => (a :-> a0) -> a0 # minimum :: Ord a0 => (a :-> a0) -> a0 # | |
Traversable ((:->) a) | |
(CoArbitrary Gen a, Arbitrary r) => Arbitrary (a :-> r) Source # | |
class Applicative gen => CoArbitrary (gen :: Type -> Type) a where #
Implicit, default cogenerator.
Methods
coarbitrary :: Co gen a r #
Instances
cogenEmbed :: Functor gen => FunName -> (a -> b) -> Co gen b r -> Co gen a r #
Cogenerator for a type a
from a cogenerator for b
,
given an embedding function (a -> b)
,
and a name for that function (used for pretty-printing).
Example
The common usage is to construct cogenerators for newtypes.
-- Given some cogenerator of Fruit cogenFruit ::Co
Gen Fruit r -- Wrap Fruit in a newtype newtype Apple = Apple { unApple :: Fruit } cogenApple ::Co
Gen Apple r cogenApple =cogenEmbed
"unApple" cogenFruit
If cogenFruit
generates a function that looks like:
\y -> case y :: Fruit of { ... }
then cogenApple
will look like this,
where y
is replaced with unApple x
:
\x -> case unApple x :: Fruit of { ... }
cogenIntegral :: (Applicative gen, Integral a) => TypeName -> Co gen a r #
Cogenerator for an integral type. The name of the type is used for pretty-printing.
Example
cogenInteger ::Co
GenInteger
r cogenInteger =cogenIntegral
"Integer" cogenInt ::Co
GenInt
r cogenInt =cogenIntegral
"Int" cogenWord ::Co
GenWord
r cogenWord =cogenIntegral
"Word"
coarbitraryGeneric :: (Generic a, GCoArbitrary gen a) => Co gen a r #
Generic implementation of coarbitrary
.
-- Assuming MyData is a data type whose fields are all instances of CoArbitrary. instance CoArbitrary MyData where coarbitrary = coarbitraryGeneric