QuickCheck-2.8.2: Automatic testing of Haskell programs

Safe HaskellTrustworthy
LanguageHaskell98

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

newtype Fixed a Source

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

Constructors

Fixed 

Fields

getFixed :: a
 

Instances

newtype OrderedList a Source

Ordered xs: guarantees that xs is ordered.

Constructors

Ordered 

Fields

getOrdered :: [a]
 

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
 

newtype NonZero a Source

NonZero x: guarantees that x /= 0.

Constructors

NonZero 

Fields

getNonZero :: a
 

Instances

newtype NonNegative a Source

NonNegative x: guarantees that x >= 0.

Constructors

NonNegative 

Fields

getNonNegative :: a
 

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

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

data Smart a Source

Smart _ x: tries a different order when shrinking.

Constructors

Smart Int a 

newtype Shrink2 a Source

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

Constructors

Shrink2 

Fields

getShrink2 :: a
 

data Shrinking s a Source

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

Constructors

Shrinking s a 

class ShrinkState s a where Source

Methods

shrinkInit :: a -> s Source

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