Safe Haskell | None |
---|
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 offorAll
orderedList
prop_Sort (Ordered
(xs :: [OrdA
])) = sort xs == xs
- newtype Blind a = Blind {
- getBlind :: a
- newtype Fixed a = Fixed {
- getFixed :: a
- newtype OrderedList a = Ordered {
- getOrdered :: [a]
- newtype NonEmptyList a = NonEmpty {
- getNonEmpty :: [a]
- newtype Positive a = Positive {
- getPositive :: a
- newtype NonZero a = NonZero {
- getNonZero :: a
- newtype NonNegative a = NonNegative {
- getNonNegative :: 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)]
Type-level modifiers for changing generator behavior
Blind x
: as x, but x does not have to be in the Show
class.
Fixed x
: as x, but will not be shrunk.
newtype OrderedList a Source
Ordered xs
: guarantees that xs is ordered.
Ordered | |
|
Functor OrderedList | |
Eq a => Eq (OrderedList a) | |
Ord a => Ord (OrderedList a) | |
Read a => Read (OrderedList a) | |
Show a => Show (OrderedList a) | |
(Ord a, Arbitrary a) => Arbitrary (OrderedList a) |
newtype NonEmptyList a Source
NonEmpty xs
: guarantees that xs is non-empty.
NonEmpty | |
|
Functor NonEmptyList | |
Eq a => Eq (NonEmptyList a) | |
Ord a => Ord (NonEmptyList a) | |
Read a => Read (NonEmptyList a) | |
Show a => Show (NonEmptyList a) | |
Arbitrary a => Arbitrary (NonEmptyList a) |
Positive x
: guarantees that x > 0
.
Positive | |
|
NonZero x
: guarantees that x /= 0
.
NonZero | |
|
newtype NonNegative a Source
NonNegative x
: guarantees that x >= 0
.
Functor NonNegative | |
Enum a => Enum (NonNegative a) | |
Eq a => Eq (NonNegative a) | |
Integral a => Integral (NonNegative a) | |
Num a => Num (NonNegative a) | |
Ord a => Ord (NonNegative a) | |
Read a => Read (NonNegative a) | |
Real a => Real (NonNegative a) | |
Show a => Show (NonNegative a) | |
(Num a, Ord a, Arbitrary a) => Arbitrary (NonNegative a) |
Large x
: by default, QuickCheck generates Int
s drawn from a small
range. Large Int
gives you values drawn from the entire range instead.
Small x
: generates values of x
drawn from a small range.
The opposite of Large
.
Smart _ x
: tries a different order when shrinking.
Shrink2 x
: allows 2 shrinking steps at the same time when shrinking x
Shrink2 | |
|
Shrinking _ x
: allows for maintaining a state during shrinking.
Shrinking s a |
class ShrinkState s a whereSource
shrinkInit :: a -> sSource
shrinkState :: a -> s -> [(a, s)]Source