QuickCheck-2.7.2: Automatic testing of Haskell programs

Safe HaskellNone

Test.QuickCheck.Modifiers

Contents

Description

Modifiers for test data.

These types do things such as restricting the kind of test data that can be generated. They can be pattern-matched on in properties as a stylistic alternative to using explicit quantification.

Examples:

 -- Functions cannot be shown (but see Test.QuickCheck.Function)
 prop_TakeDropWhile (Blind p) (xs :: [A]) =
   takeWhile p xs ++ dropWhile p xs == xs
 prop_TakeDrop (NonNegative n) (xs :: [A]) =
   take n xs ++ drop n xs == xs
 -- cycle does not work for empty lists
 prop_Cycle (NonNegative n) (NonEmpty (xs :: [A])) =
   take n (cycle xs) == take n (xs ++ cycle xs)
 -- Instead of forAll orderedList
 prop_Sort (Ordered (xs :: [OrdA])) =
   sort xs == xs

Synopsis

Type-level modifiers for changing generator behavior

newtype Blind a Source

Blind x: as x, but x does not have to be in the Show class.

Constructors

Blind 

Fields

getBlind :: a
 

Instances

Functor Blind 
Enum a => Enum (Blind a) 
Eq a => Eq (Blind a) 
Integral a => Integral (Blind a) 
Num a => Num (Blind a) 
Ord a => Ord (Blind a) 
Real a => Real (Blind a) 
Show (Blind a) 
Arbitrary a => Arbitrary (Blind a) 

newtype Fixed a Source

Fixed x: as x, but will not be shrunk.

Constructors

Fixed 

Fields

getFixed :: a
 

Instances

Functor Fixed 
Enum a => Enum (Fixed a) 
Eq a => Eq (Fixed a) 
Integral a => Integral (Fixed a) 
Num a => Num (Fixed a) 
Ord a => Ord (Fixed a) 
Read a => Read (Fixed a) 
Real a => Real (Fixed a) 
Show a => Show (Fixed a) 
Arbitrary a => Arbitrary (Fixed a) 

newtype OrderedList a Source

Ordered xs: guarantees that xs is ordered.

Constructors

Ordered 

Fields

getOrdered :: [a]
 

Instances

newtype NonEmptyList a Source

NonEmpty xs: guarantees that xs is non-empty.

Constructors

NonEmpty 

Fields

getNonEmpty :: [a]
 

newtype Positive a Source

Positive x: guarantees that x > 0.

Constructors

Positive 

Fields

getPositive :: a
 

Instances

Functor Positive 
Enum a => Enum (Positive a) 
Eq a => Eq (Positive a) 
Integral a => Integral (Positive a) 
Num a => Num (Positive a) 
Ord a => Ord (Positive a) 
Read a => Read (Positive a) 
Real a => Real (Positive a) 
Show a => Show (Positive a) 
(Num a, Ord a, Arbitrary a) => Arbitrary (Positive a) 

newtype NonZero a Source

NonZero x: guarantees that x /= 0.

Constructors

NonZero 

Fields

getNonZero :: a
 

Instances

Functor NonZero 
Enum a => Enum (NonZero a) 
Eq a => Eq (NonZero a) 
Integral a => Integral (NonZero a) 
Num a => Num (NonZero a) 
Ord a => Ord (NonZero a) 
Read a => Read (NonZero a) 
Real a => Real (NonZero a) 
Show a => Show (NonZero a) 
(Num a, Ord a, Arbitrary a) => Arbitrary (NonZero a) 

newtype NonNegative a Source

NonNegative x: guarantees that x >= 0.

Constructors

NonNegative 

Fields

getNonNegative :: a
 

Instances

newtype Large a Source

Large x: by default, QuickCheck generates Ints drawn from a small range. Large Int gives you values drawn from the entire range instead.

Constructors

Large 

Fields

getLarge :: a
 

Instances

Functor Large 
Enum a => Enum (Large a) 
Eq a => Eq (Large a) 
Integral a => Integral (Large a) 
Num a => Num (Large a) 
Ord a => Ord (Large a) 
Read a => Read (Large a) 
Real a => Real (Large a) 
Show a => Show (Large a) 
(Integral a, Bounded a) => Arbitrary (Large a) 

newtype Small a Source

Small x: generates values of x drawn from a small range. The opposite of Large.

Constructors

Small 

Fields

getSmall :: a
 

Instances

Functor Small 
Enum a => Enum (Small a) 
Eq a => Eq (Small a) 
Integral a => Integral (Small a) 
Num a => Num (Small a) 
Ord a => Ord (Small a) 
Read a => Read (Small a) 
Real a => Real (Small a) 
Show a => Show (Small a) 
Integral a => Arbitrary (Small a) 

data Smart a Source

Smart _ x: tries a different order when shrinking.

Constructors

Smart Int a 

Instances

newtype Shrink2 a Source

Shrink2 x: allows 2 shrinking steps at the same time when shrinking x

Constructors

Shrink2 

Fields

getShrink2 :: a
 

Instances

Functor Shrink2 
Enum a => Enum (Shrink2 a) 
Eq a => Eq (Shrink2 a) 
Integral a => Integral (Shrink2 a) 
Num a => Num (Shrink2 a) 
Ord a => Ord (Shrink2 a) 
Read a => Read (Shrink2 a) 
Real a => Real (Shrink2 a) 
Show a => Show (Shrink2 a) 
Arbitrary a => Arbitrary (Shrink2 a) 

data Shrinking s a Source

Shrinking _ x: allows for maintaining a state during shrinking.

Constructors

Shrinking s a 

Instances

class ShrinkState s a whereSource

Methods

shrinkInit :: a -> sSource

shrinkState :: a -> s -> [(a, s)]Source