Safe Haskell | Trustworthy |
---|---|
Language | Haskell2010 |
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.
Note: the contents of this module are re-exported by Test.QuickCheck. You do not need to import it directly.
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 offorAll
orderedList
prop_Sort (Ordered
(xs :: [OrdA
])) = sort xs == xs
Synopsis
- newtype Blind a = Blind {
- getBlind :: a
- newtype Fixed a = Fixed {
- getFixed :: a
- newtype OrderedList a = Ordered {
- getOrdered :: [a]
- newtype NonEmptyList a = NonEmpty {
- getNonEmpty :: [a]
- data InfiniteList a = InfiniteList {
- getInfiniteList :: [a]
- infiniteListInternalData :: InfiniteListInternalData a
- newtype SortedList a = Sorted {
- getSorted :: [a]
- newtype Positive a = Positive {
- getPositive :: a
- newtype Negative a = Negative {
- getNegative :: a
- newtype NonZero a = NonZero {
- getNonZero :: a
- newtype NonNegative a = NonNegative {
- getNonNegative :: a
- newtype NonPositive a = NonPositive {
- getNonPositive :: a
- newtype Large a = Large {
- getLarge :: a
- newtype Small a = Small {
- getSmall :: a
- data Smart a = Smart Int a
- newtype Shrink2 a = Shrink2 {
- getShrink2 :: a
- data Shrinking s a = Shrinking s a
- class ShrinkState s a where
- shrinkInit :: a -> s
- shrinkState :: a -> s -> [(a, s)]
- newtype ASCIIString = ASCIIString {}
- newtype UnicodeString = UnicodeString {}
- newtype PrintableString = PrintableString {}
Type-level modifiers for changing generator behavior
Blind x
: as x, but x does not have to be in the Show
class.
Instances
Fixed x
: as x, but will not be shrunk.
Instances
newtype OrderedList a Source #
Ordered xs
: guarantees that xs is ordered.
Ordered | |
|
Instances
newtype NonEmptyList a Source #
NonEmpty xs
: guarantees that xs is non-empty.
NonEmpty | |
|
Instances
data InfiniteList a Source #
InfiniteList xs _
: guarantees that xs is an infinite list.
When a counterexample is found, only prints the prefix of xs
that was used by the program.
Here is a contrived example property:
prop_take_10 :: InfiniteList Char -> Bool prop_take_10 (InfiniteList xs _) = or [ x == 'a' | x <- take 10 xs ]
In the following counterexample, the list must start with "bbbbbbbbbb"
but
the remaining (infinite) part can contain anything:
>>>
quickCheck prop_take_10
*** Failed! Falsified (after 1 test and 14 shrinks): "bbbbbbbbbb" ++ ...
InfiniteList | |
|
Instances
Arbitrary a => Arbitrary (InfiniteList a) Source # | |
Defined in Test.QuickCheck.Modifiers arbitrary :: Gen (InfiniteList a) Source # shrink :: InfiniteList a -> [InfiniteList a] Source # | |
Show a => Show (InfiniteList a) Source # | |
Defined in Test.QuickCheck.Modifiers |
newtype SortedList a Source #
Sorted xs
: guarantees that xs is sorted.
Instances
Positive x
: guarantees that x > 0
.
Positive | |
|
Instances
Negative x
: guarantees that x < 0
.
Negative | |
|
Instances
NonZero x
: guarantees that x /= 0
.
NonZero | |
|
Instances
Functor NonZero Source # | |
(Num a, Eq a, Arbitrary a) => Arbitrary (NonZero a) Source # | |
Enum a => Enum (NonZero a) Source # | |
Defined in Test.QuickCheck.Modifiers succ :: NonZero a -> NonZero a Source # pred :: NonZero a -> NonZero a Source # toEnum :: Int -> NonZero a Source # fromEnum :: NonZero a -> Int Source # enumFrom :: NonZero a -> [NonZero a] Source # enumFromThen :: NonZero a -> NonZero a -> [NonZero a] Source # enumFromTo :: NonZero a -> NonZero a -> [NonZero a] Source # enumFromThenTo :: NonZero a -> NonZero a -> NonZero a -> [NonZero a] Source # | |
Read a => Read (NonZero a) Source # | |
Show a => Show (NonZero a) Source # | |
Eq a => Eq (NonZero a) Source # | |
Ord a => Ord (NonZero a) Source # | |
Defined in Test.QuickCheck.Modifiers |
newtype NonNegative a Source #
NonNegative x
: guarantees that x >= 0
.
Instances
newtype NonPositive a Source #
NonPositive x
: guarantees that x <= 0
.
Instances
Large x
: by default, QuickCheck generates Int
s drawn from a small
range. Large Int
gives you values drawn from the entire range instead.
Instances
Small x
: generates values of x
drawn from a small range.
The opposite of Large
.
Instances
Smart _ x
: tries a different order when shrinking.
Shrink2 x
: allows 2 shrinking steps at the same time when shrinking x
Shrink2 | |
|
Instances
Shrinking _ x
: allows for maintaining a state during shrinking.
Shrinking s a |
class ShrinkState s a where Source #
shrinkInit :: a -> s Source #
shrinkState :: a -> s -> [(a, s)] Source #
newtype ASCIIString Source #
ASCIIString
: generates an ASCII string.
Instances
Arbitrary ASCIIString Source # | |
Defined in Test.QuickCheck.Modifiers arbitrary :: Gen ASCIIString Source # shrink :: ASCIIString -> [ASCIIString] Source # | |
Read ASCIIString Source # | |
Defined in Test.QuickCheck.Modifiers | |
Show ASCIIString Source # | |
Defined in Test.QuickCheck.Modifiers | |
Eq ASCIIString Source # | |
Defined in Test.QuickCheck.Modifiers (==) :: ASCIIString -> ASCIIString -> Bool Source # (/=) :: ASCIIString -> ASCIIString -> Bool Source # | |
Ord ASCIIString Source # | |
Defined in Test.QuickCheck.Modifiers compare :: ASCIIString -> ASCIIString -> Ordering Source # (<) :: ASCIIString -> ASCIIString -> Bool Source # (<=) :: ASCIIString -> ASCIIString -> Bool Source # (>) :: ASCIIString -> ASCIIString -> Bool Source # (>=) :: ASCIIString -> ASCIIString -> Bool Source # max :: ASCIIString -> ASCIIString -> ASCIIString Source # min :: ASCIIString -> ASCIIString -> ASCIIString Source # |
newtype UnicodeString Source #
UnicodeString
: generates a unicode String.
The string will not contain surrogate pairs.
Instances
Arbitrary UnicodeString Source # | |
Defined in Test.QuickCheck.Modifiers arbitrary :: Gen UnicodeString Source # shrink :: UnicodeString -> [UnicodeString] Source # | |
Read UnicodeString Source # | |
Defined in Test.QuickCheck.Modifiers | |
Show UnicodeString Source # | |
Defined in Test.QuickCheck.Modifiers | |
Eq UnicodeString Source # | |
Defined in Test.QuickCheck.Modifiers (==) :: UnicodeString -> UnicodeString -> Bool Source # (/=) :: UnicodeString -> UnicodeString -> Bool Source # | |
Ord UnicodeString Source # | |
Defined in Test.QuickCheck.Modifiers compare :: UnicodeString -> UnicodeString -> Ordering Source # (<) :: UnicodeString -> UnicodeString -> Bool Source # (<=) :: UnicodeString -> UnicodeString -> Bool Source # (>) :: UnicodeString -> UnicodeString -> Bool Source # (>=) :: UnicodeString -> UnicodeString -> Bool Source # max :: UnicodeString -> UnicodeString -> UnicodeString Source # min :: UnicodeString -> UnicodeString -> UnicodeString Source # |
newtype PrintableString Source #
PrintableString
: generates a printable unicode String.
The string will not contain surrogate pairs.
Instances
Arbitrary PrintableString Source # | |
Defined in Test.QuickCheck.Modifiers | |
Read PrintableString Source # | |
Defined in Test.QuickCheck.Modifiers | |
Show PrintableString Source # | |
Defined in Test.QuickCheck.Modifiers | |
Eq PrintableString Source # | |
Defined in Test.QuickCheck.Modifiers (==) :: PrintableString -> PrintableString -> Bool Source # (/=) :: PrintableString -> PrintableString -> Bool Source # | |
Ord PrintableString Source # | |
Defined in Test.QuickCheck.Modifiers compare :: PrintableString -> PrintableString -> Ordering Source # (<) :: PrintableString -> PrintableString -> Bool Source # (<=) :: PrintableString -> PrintableString -> Bool Source # (>) :: PrintableString -> PrintableString -> Bool Source # (>=) :: PrintableString -> PrintableString -> Bool Source # max :: PrintableString -> PrintableString -> PrintableString Source # min :: PrintableString -> PrintableString -> PrintableString Source # |