Safe Haskell | Safe-Inferred |
---|---|
Language | Haskell2010 |
Synopsis
- class NFData a
- when ∷ Applicative f ⇒ Bool → f () → f ()
- void ∷ Functor f ⇒ f a → f ()
- unless ∷ Applicative f ⇒ Bool → f () → f ()
- ansiDocToString ∷ Doc AnsiStyle → String
- fdescribe ∷ HasCallStack ⇒ String → SpecWith a → SpecWith a
- fit ∷ (HasCallStack, Example a) ⇒ String → a → SpecWith (Arg a)
- xit ∷ (HasCallStack, Example a) ⇒ String → a → SpecWith (Arg a)
- it ∷ (HasCallStack, Example a) ⇒ String → a → SpecWith (Arg a)
- xdescribe ∷ HasCallStack ⇒ String → SpecWith a → SpecWith a
- describe ∷ HasCallStack ⇒ String → SpecWith a → SpecWith a
- type Spec = SpecWith ()
- type SpecWith a = SpecM a ()
- prop ∷ (HasCallStack, Testable prop) ⇒ String → prop → Spec
- xprop ∷ (HasCallStack, Testable prop) ⇒ String → prop → Spec
- fprop ∷ (HasCallStack, Testable prop) ⇒ String → prop → Spec
- type Selector a = a → Bool
- labelledExamplesWithResult ∷ Testable prop ⇒ Args → prop → IO Result
- labelledExamplesResult ∷ Testable prop ⇒ prop → IO Result
- labelledExamplesWith ∷ Testable prop ⇒ Args → prop → IO ()
- labelledExamples ∷ Testable prop ⇒ prop → IO ()
- verboseCheckAll ∷ Q Exp
- quickCheckAll ∷ Q Exp
- allProperties ∷ Q Exp
- forAllProperties ∷ Q Exp
- monomorphic ∷ Name → ExpQ
- polyVerboseCheck ∷ Name → ExpQ
- polyQuickCheck ∷ Name → ExpQ
- verboseCheckWithResult ∷ Testable prop ⇒ Args → prop → IO Result
- verboseCheckResult ∷ Testable prop ⇒ prop → IO Result
- verboseCheckWith ∷ Testable prop ⇒ Args → prop → IO ()
- verboseCheck ∷ Testable prop ⇒ prop → IO ()
- recheck ∷ Testable prop ⇒ Result → prop → IO ()
- quickCheckWithResult ∷ Testable prop ⇒ Args → prop → IO Result
- quickCheckResult ∷ Testable prop ⇒ prop → IO Result
- quickCheckWith ∷ Testable prop ⇒ Args → prop → IO ()
- quickCheck ∷ Testable prop ⇒ prop → IO ()
- stdArgs ∷ Args
- isSuccess ∷ Result → Bool
- data Args = Args {
- replay ∷ Maybe (QCGen, Int)
- maxSuccess ∷ Int
- maxDiscardRatio ∷ Int
- maxSize ∷ Int
- chatty ∷ Bool
- maxShrinks ∷ Int
- data Result
- = Success { }
- | GaveUp { }
- | Failure {
- numTests ∷ Int
- numDiscarded ∷ Int
- numShrinks ∷ Int
- numShrinkTries ∷ Int
- numShrinkFinal ∷ Int
- usedSeed ∷ QCGen
- usedSize ∷ Int
- reason ∷ String
- theException ∷ Maybe AnException
- output ∷ String
- failingTestCase ∷ [String]
- failingLabels ∷ [String]
- failingClasses ∷ Set String
- witnesses ∷ [Witness]
- | NoExpectedFailure { }
- total ∷ NFData a ⇒ a → Property
- (=/=) ∷ (Eq a, Show a) ⇒ a → a → Property
- (===) ∷ (Eq a, Show a) ⇒ a → a → Property
- disjoin ∷ Testable prop ⇒ [prop] → Property
- (.||.) ∷ (Testable prop1, Testable prop2) ⇒ prop1 → prop2 → Property
- conjoin ∷ Testable prop ⇒ [prop] → Property
- (.&&.) ∷ (Testable prop1, Testable prop2) ⇒ prop1 → prop2 → Property
- (.&.) ∷ (Testable prop1, Testable prop2) ⇒ prop1 → prop2 → Property
- forAllShrinkBlind ∷ Testable prop ⇒ Gen a → (a → [a]) → (a → prop) → Property
- forAllShrinkShow ∷ Testable prop ⇒ Gen a → (a → [a]) → (a → String) → (a → prop) → Property
- forAllShrink ∷ (Show a, Testable prop) ⇒ Gen a → (a → [a]) → (a → prop) → Property
- forAllBlind ∷ Testable prop ⇒ Gen a → (a → prop) → Property
- forAllShow ∷ Testable prop ⇒ Gen a → (a → String) → (a → prop) → Property
- forAll ∷ (Show a, Testable prop) ⇒ Gen a → (a → prop) → Property
- discardAfter ∷ Testable prop ⇒ Int → prop → Property
- within ∷ Testable prop ⇒ Int → prop → Property
- (==>) ∷ Testable prop ⇒ Bool → prop → Property
- coverTable ∷ Testable prop ⇒ String → [(String, Double)] → prop → Property
- tabulate ∷ Testable prop ⇒ String → [String] → prop → Property
- cover ∷ Testable prop ⇒ Double → Bool → String → prop → Property
- classify ∷ Testable prop ⇒ Bool → String → prop → Property
- collect ∷ (Show a, Testable prop) ⇒ a → prop → Property
- label ∷ Testable prop ⇒ String → prop → Property
- stdConfidence ∷ Confidence
- checkCoverageWith ∷ Testable prop ⇒ Confidence → prop → Property
- checkCoverage ∷ Testable prop ⇒ prop → Property
- witness ∷ (Typeable a, Show a, Testable prop) ⇒ a → prop → Property
- withMaxSize ∷ Testable prop ⇒ Int → prop → Property
- withMaxShrinks ∷ Testable prop ⇒ Int → prop → Property
- withDiscardRatio ∷ Testable prop ⇒ Int → prop → Property
- withMaxSuccess ∷ Testable prop ⇒ Int → prop → Property
- again ∷ Testable prop ⇒ prop → Property
- once ∷ Testable prop ⇒ prop → Property
- expectFailure ∷ Testable prop ⇒ prop → Property
- verboseShrinking ∷ Testable prop ⇒ prop → Property
- verbose ∷ Testable prop ⇒ prop → Property
- whenFail' ∷ Testable prop ⇒ IO () → prop → Property
- whenFail ∷ Testable prop ⇒ IO () → prop → Property
- printTestCase ∷ Testable prop ⇒ String → prop → Property
- counterexample ∷ Testable prop ⇒ String → prop → Property
- noShrinking ∷ Testable prop ⇒ prop → Property
- shrinking ∷ Testable prop ⇒ (a → [a]) → a → (a → prop) → Property
- mapSize ∷ Testable prop ⇒ (Int → Int) → prop → Property
- castWitness ∷ Typeable a ⇒ Witness → Maybe a
- coerceWitness ∷ Typeable a ⇒ Witness → a
- idempotentIOProperty ∷ Testable prop ⇒ IO prop → Property
- ioProperty ∷ Testable prop ⇒ IO prop → Property
- data Property
- class Testable prop where
- data Discard = Discard
- data Witness = (Typeable a, Show a) ⇒ Wit a
- data Confidence = Confidence {}
- applyFun3 ∷ Fun (a, b, c) d → a → b → c → d
- applyFun2 ∷ Fun (a, b) c → a → b → c
- applyFun ∷ Fun a b → a → b
- functionMap ∷ Function b ⇒ (a → b) → (b → a) → (a → c) → a :-> c
- functionVoid ∷ (∀ b. void → b) → void :-> c
- functionShow ∷ (Show a, Read a) ⇒ (a → c) → a :-> c
- functionIntegral ∷ Integral a ⇒ (a → b) → a :-> b
- functionRealFrac ∷ RealFrac a ⇒ (a → b) → a :-> b
- functionBoundedEnum ∷ (Eq a, Bounded a, Enum a) ⇒ (a → b) → a :-> b
- pattern Fn ∷ (a → b) → Fun a b
- pattern Fn2 ∷ (a → b → c) → Fun (a, b) c
- pattern Fn3 ∷ (a → b → c → d) → Fun (a, b, c) d
- class Function a where
- data Fun a b = Fun (a :-> b, b, Shrunk) (a → b)
- 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
- newtype Shrink2 a = Shrink2 {
- getShrink2 ∷ a
- data Smart a = Smart Int 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 {}
- infiniteList ∷ Arbitrary a ⇒ Gen [a]
- orderedList ∷ (Ord a, Arbitrary a) ⇒ Gen [a]
- vector ∷ Arbitrary a ⇒ Int → Gen [a]
- coarbitraryEnum ∷ Enum a ⇒ a → Gen b → Gen b
- coarbitraryShow ∷ Show a ⇒ a → Gen b → Gen b
- coarbitraryReal ∷ Real a ⇒ a → Gen b → Gen b
- coarbitraryIntegral ∷ Integral a ⇒ a → Gen b → Gen b
- (><) ∷ (Gen a → Gen a) → (Gen a → Gen a) → Gen a → Gen a
- genericCoarbitrary ∷ (Generic a, GCoArbitrary (Rep a)) ⇒ a → Gen b → Gen b
- shrinkDecimal ∷ RealFrac a ⇒ a → [a]
- shrinkRealFrac ∷ RealFrac a ⇒ a → [a]
- shrinkBoundedEnum ∷ (Bounded a, Enum a, Eq a) ⇒ a → [a]
- shrinkIntegral ∷ Integral a ⇒ a → [a]
- shrinkMapBy ∷ (a → b) → (b → a) → (a → [a]) → b → [b]
- shrinkMap ∷ Arbitrary a ⇒ (a → b) → (b → a) → b → [b]
- shrinkNothing ∷ a → [a]
- arbitraryPrintableChar ∷ Gen Char
- arbitraryASCIIChar ∷ Gen Char
- arbitraryUnicodeChar ∷ Gen Char
- arbitrarySizedBoundedIntegral ∷ (Bounded a, Integral a) ⇒ Gen a
- arbitraryBoundedEnum ∷ (Bounded a, Enum a) ⇒ Gen a
- arbitraryBoundedRandom ∷ (Bounded a, Random a) ⇒ Gen a
- arbitraryBoundedIntegral ∷ (Bounded a, Integral a) ⇒ Gen a
- arbitrarySizedFractional ∷ Fractional a ⇒ Gen a
- arbitrarySizedNatural ∷ Integral a ⇒ Gen a
- arbitrarySizedIntegral ∷ Integral a ⇒ Gen a
- applyArbitrary4 ∷ (Arbitrary a, Arbitrary b, Arbitrary c, Arbitrary d) ⇒ (a → b → c → d → r) → Gen r
- applyArbitrary3 ∷ (Arbitrary a, Arbitrary b, Arbitrary c) ⇒ (a → b → c → r) → Gen r
- applyArbitrary2 ∷ (Arbitrary a, Arbitrary b) ⇒ (a → b → r) → Gen r
- shrinkList ∷ (a → [a]) → [a] → [[a]]
- subterms ∷ (Generic a, GSubterms (Rep a) a) ⇒ a → [a]
- recursivelyShrink ∷ (Generic a, RecursivelyShrink (Rep a)) ⇒ a → [a]
- genericShrink ∷ (Generic a, RecursivelyShrink (Rep a), GSubterms (Rep a) a) ⇒ a → [a]
- shrink2 ∷ (Arbitrary2 f, Arbitrary a, Arbitrary b) ⇒ f a b → [f a b]
- arbitrary2 ∷ (Arbitrary2 f, Arbitrary a, Arbitrary b) ⇒ Gen (f a b)
- shrink1 ∷ (Arbitrary1 f, Arbitrary a) ⇒ f a → [f a]
- arbitrary1 ∷ (Arbitrary1 f, Arbitrary a) ⇒ Gen (f a)
- class Arbitrary a where
- shrink ∷ a → [a]
- class Arbitrary1 (f ∷ Type → Type) where
- liftArbitrary ∷ Gen a → Gen (f a)
- liftShrink ∷ (a → [a]) → f a → [f a]
- class Arbitrary2 (f ∷ Type → Type → Type) where
- liftArbitrary2 ∷ Gen a → Gen b → Gen (f a b)
- liftShrink2 ∷ (a → [a]) → (b → [b]) → f a b → [f a b]
- class CoArbitrary a where
- coarbitrary ∷ a → Gen b → Gen b
- infiniteListOf ∷ Gen a → Gen [a]
- shuffle ∷ [a] → Gen [a]
- sublistOf ∷ [a] → Gen [a]
- suchThatMap ∷ Gen a → (a → Maybe b) → Gen b
- sample ∷ Show a ⇒ Gen a → IO ()
- sample' ∷ Gen a → IO [a]
- generate ∷ Gen a → IO a
- chooseInteger ∷ (Integer, Integer) → Gen Integer
- chooseBoundedIntegral ∷ (Bounded a, Integral a) ⇒ (a, a) → Gen a
- chooseInt ∷ (Int, Int) → Gen Int
- chooseEnum ∷ Enum a ⇒ (a, a) → Gen a
- chooseAny ∷ Random a ⇒ Gen a
- scale ∷ (Int → Int) → Gen a → Gen a
- getSize ∷ Gen Int
- data Gen a
- discard ∷ a
- (>=>) ∷ Monad m ⇒ (a → m b) → (b → m c) → a → m c
- forM_ ∷ (Foldable t, Monad m) ⇒ t a → (a → m b) → m ()
- replicateM_ ∷ Applicative m ⇒ Int → m a → m ()
- replicateM ∷ Applicative m ⇒ Int → m a → m [a]
- type HasCallStack = ?callStack ∷ CallStack
- diffExprCompactString ∷ ToExpr a ⇒ a → a → String
- diffExprCompact ∷ ToExpr a ⇒ a → a → Doc AnsiStyle
- diffExprString ∷ ToExpr a ⇒ a → a → String
- diffExpr ∷ ToExpr a ⇒ a → a → Doc AnsiStyle
- ansiExprString ∷ ToExpr a ⇒ a → String
- ansiExpr ∷ ToExpr a ⇒ a → Doc AnsiStyle
- showExpr ∷ ToExpr a ⇒ a → String
- class ToExpr a where
- toExpr ∷ a → Expr
- listToExpr ∷ [a] → Expr
- anyException ∷ Selector SomeException
- anyErrorCall ∷ Selector ErrorCall
- errorCall ∷ String → Selector ErrorCall
- anyIOException ∷ Selector IOException
- anyArithException ∷ Selector ArithException
- type Expectation = Assertion
- example ∷ Expectation → Expectation
- type ActionWith a = a → IO ()
- class Example e where
- type Arg e
- type family Arg e
- runIO ∷ IO r → SpecM a r
- modifyMaxSuccess ∷ (Int → Int) → SpecWith a → SpecWith a
- modifyMaxDiscardRatio ∷ (Int → Int) → SpecWith a → SpecWith a
- modifyMaxSize ∷ (Int → Int) → SpecWith a → SpecWith a
- modifyMaxShrinks ∷ (Int → Int) → SpecWith a → SpecWith a
- modifyArgs ∷ (Args → Args) → SpecWith a → SpecWith a
- before ∷ IO a → SpecWith a → Spec
- before_ ∷ IO () → SpecWith a → SpecWith a
- beforeWith ∷ (b → IO a) → SpecWith a → SpecWith b
- beforeAll ∷ HasCallStack ⇒ IO a → SpecWith a → Spec
- beforeAll_ ∷ HasCallStack ⇒ IO () → SpecWith a → SpecWith a
- beforeAllWith ∷ HasCallStack ⇒ (b → IO a) → SpecWith a → SpecWith b
- after ∷ ActionWith a → SpecWith a → SpecWith a
- after_ ∷ IO () → SpecWith a → SpecWith a
- around ∷ (ActionWith a → IO ()) → SpecWith a → Spec
- afterAll ∷ HasCallStack ⇒ ActionWith a → SpecWith a → SpecWith a
- afterAll_ ∷ HasCallStack ⇒ IO () → SpecWith a → SpecWith a
- around_ ∷ (IO () → IO ()) → SpecWith a → SpecWith a
- aroundWith ∷ (ActionWith a → ActionWith b) → SpecWith a → SpecWith b
- aroundAll ∷ HasCallStack ⇒ (ActionWith a → IO ()) → SpecWith a → Spec
- aroundAll_ ∷ HasCallStack ⇒ (IO () → IO ()) → SpecWith a → SpecWith a
- aroundAllWith ∷ HasCallStack ⇒ (ActionWith a → ActionWith b) → SpecWith a → SpecWith b
- mapSubject ∷ (b → a) → SpecWith a → SpecWith b
- ignoreSubject ∷ SpecWith () → SpecWith a
- context ∷ HasCallStack ⇒ String → SpecWith a → SpecWith a
- xcontext ∷ HasCallStack ⇒ String → SpecWith a → SpecWith a
- specify ∷ (HasCallStack, Example a) ⇒ String → a → SpecWith (Arg a)
- xspecify ∷ (HasCallStack, Example a) ⇒ String → a → SpecWith (Arg a)
- focus ∷ SpecWith a → SpecWith a
- fspecify ∷ (HasCallStack, Example a) ⇒ String → a → SpecWith (Arg a)
- fcontext ∷ HasCallStack ⇒ String → SpecWith a → SpecWith a
- parallel ∷ SpecWith a → SpecWith a
- sequential ∷ SpecWith a → SpecWith a
- pending ∷ HasCallStack ⇒ Expectation
- pendingWith ∷ HasCallStack ⇒ String → Expectation
- hspec ∷ Spec → IO ()
- ledgerHspecConfig ∷ Config
- ledgerTestMainWith ∷ Config → Spec → IO ()
- ledgerTestMain ∷ Spec → IO ()
- tracedDiscard ∷ String → a
- io ∷ IO a → IO a
- assertBool ∷ (HasCallStack, MonadIO m) ⇒ String → Bool → m ()
- assertFailure ∷ (HasCallStack, MonadIO m) ⇒ String → m a
- assertColorFailure ∷ (HasCallStack, MonadIO m) ⇒ String → m a
- expectationFailure ∷ (HasCallStack, MonadIO m) ⇒ String → m ()
- shouldBe ∷ (HasCallStack, MonadIO m, Show a, Eq a) ⇒ a → a → m ()
- shouldSatisfy ∷ (HasCallStack, MonadIO m, Show a) ⇒ a → (a → Bool) → m ()
- shouldSatisfyExpr ∷ (HasCallStack, MonadIO m, ToExpr a) ⇒ a → (a → Bool) → m ()
- shouldStartWith ∷ (HasCallStack, MonadIO m, Show a, Eq a) ⇒ [a] → [a] → m ()
- shouldEndWith ∷ (HasCallStack, MonadIO m, Show a, Eq a) ⇒ [a] → [a] → m ()
- shouldContain ∷ (HasCallStack, MonadIO m, Show a, Eq a) ⇒ [a] → [a] → m ()
- shouldMatchList ∷ (HasCallStack, MonadIO m, Show a, Eq a) ⇒ [a] → [a] → m ()
- shouldReturn ∷ (HasCallStack, MonadIO m, Show a, Eq a) ⇒ m a → a → m ()
- shouldNotBe ∷ (HasCallStack, MonadIO m, Show a, Eq a) ⇒ a → a → m ()
- shouldNotSatisfy ∷ (HasCallStack, MonadIO m, Show a) ⇒ a → (a → Bool) → m ()
- shouldNotContain ∷ (HasCallStack, MonadIO m, Show a, Eq a) ⇒ [a] → [a] → m ()
- shouldNotReturn ∷ (HasCallStack, MonadIO m, Show a, Eq a) ⇒ m a → a → m ()
- shouldThrow ∷ (HasCallStack, Exception e, MonadUnliftIO m) ⇒ m a → Selector e → m ()
- shouldBeExpr ∷ (HasCallStack, ToExpr a, Eq a, MonadIO m) ⇒ a → a → m ()
- shouldBeRight ∷ (HasCallStack, Show a, Show b, Eq b, MonadIO m) ⇒ Either a b → b → m ()
- shouldBeLeft ∷ (HasCallStack, Show a, Eq a, Show b, MonadIO m) ⇒ Either a b → a → m ()
- shouldBeRightExpr ∷ (HasCallStack, ToExpr a, Eq b, ToExpr b, MonadIO m) ⇒ Either a b → b → m ()
- shouldBeLeftExpr ∷ (HasCallStack, ToExpr a, ToExpr b, Eq a, MonadIO m) ⇒ Either a b → a → m ()
- shouldContainExpr ∷ (HasCallStack, ToExpr a, Eq a, MonadIO m) ⇒ [a] → [a] → m ()
- expectRight ∷ (HasCallStack, Show a, MonadIO m) ⇒ Either a b → m b
- expectRightDeep_ ∷ (HasCallStack, Show a, NFData b, MonadIO m) ⇒ Either a b → m ()
- expectRightDeep ∷ (HasCallStack, Show a, NFData b, MonadIO m) ⇒ Either a b → m b
- expectRightExpr ∷ (HasCallStack, ToExpr a, MonadIO m) ⇒ Either a b → m b
- expectRightDeepExpr ∷ (HasCallStack, ToExpr a, NFData b, MonadIO m) ⇒ Either a b → m b
- expectLeft ∷ (HasCallStack, Show b, MonadIO m) ⇒ Either a b → m a
- expectLeftDeep_ ∷ (HasCallStack, NFData a, Show b, MonadIO m) ⇒ Either a b → m ()
- expectLeftExpr ∷ (HasCallStack, ToExpr b, MonadIO m) ⇒ Either a b → m a
- expectLeftDeep ∷ (HasCallStack, NFData a, Show b, MonadIO m) ⇒ Either a b → m a
- expectLeftDeepExpr ∷ (HasCallStack, ToExpr b, NFData a, MonadIO m) ⇒ Either a b → m a
- expectJust ∷ (HasCallStack, MonadIO m) ⇒ Maybe a → m a
- expectNothingExpr ∷ (HasCallStack, MonadIO m, ToExpr a) ⇒ Maybe a → m ()
- module Test.QuickCheck.GenT
- arbitrary ∷ (Arbitrary a, MonadGen m) ⇒ m a
- class StatefulGen g m ⇒ HasStatefulGen g (m ∷ Type → Type) | m → g where
- askStatefulGen ∷ m g
- class Monad m ⇒ StatefulGen g (m ∷ Type → Type)
- uniformM ∷ (HasStatefulGen g m, Uniform a) ⇒ m a
- uniformRM ∷ (HasStatefulGen g m, UniformRange a) ⇒ (a, a) → m a
- uniformListM ∷ (HasStatefulGen g m, Uniform a) ⇒ Int → m [a]
- uniformListRM ∷ (HasStatefulGen g m, UniformRange a) ⇒ (a, a) → Int → m [a]
- uniformByteStringM ∷ HasStatefulGen a m ⇒ Int → m ByteString
- uniformShortByteStringM ∷ HasStatefulGen a m ⇒ Int → m ShortByteString
- withImpInit ∷ ImpSpec t ⇒ SpecWith (ImpInit t) → Spec
- modifyImpInit ∷ (ImpInit t → ImpInit t) → SpecWith (ImpInit t) → SpecWith (ImpInit t)
Documentation
A class of types that can be fully evaluated.
Since: deepseq-1.1.0.0
Instances
when ∷ Applicative f ⇒ Bool → f () → f () Source #
Conditional execution of Applicative
expressions. For example,
when debug (putStrLn "Debugging")
will output the string Debugging
if the Boolean value debug
is True
, and otherwise do nothing.
void ∷ Functor f ⇒ f a → f () Source #
discards or ignores the result of evaluation, such
as the return value of an void
valueIO
action.
Examples
Replace the contents of a
with unit:Maybe
Int
>>>
void Nothing
Nothing>>>
void (Just 3)
Just ()
Replace the contents of an
with unit, resulting in an Either
Int
Int
:Either
Int
()
>>>
void (Left 8675309)
Left 8675309>>>
void (Right 8675309)
Right ()
Replace every element of a list with unit:
>>>
void [1,2,3]
[(),(),()]
Replace the second element of a pair with unit:
>>>
void (1,2)
(1,())
Discard the result of an IO
action:
>>>
mapM print [1,2]
1 2 [(),()]>>>
void $ mapM print [1,2]
1 2
fdescribe ∷ HasCallStack ⇒ String → SpecWith a → SpecWith a Source #
fdescribe
is an alias for fmap focus . describe
fit ∷ (HasCallStack, Example a) ⇒ String → a → SpecWith (Arg a) Source #
fit
is an alias for fmap focus . it
it ∷ (HasCallStack, Example a) ⇒ String → a → SpecWith (Arg a) Source #
The it
function creates a spec item.
A spec item consists of:
- a textual description of a desired behavior
- an example for that behavior
describe "absolute" $ do it "returns a positive number when given a negative number" $ absolute (-1) == 1
describe ∷ HasCallStack ⇒ String → SpecWith a → SpecWith a Source #
The describe
function combines a list of specs into a larger spec.
type Selector a = a → Bool Source #
A Selector
is a predicate; it can simultaneously constrain the type and
value of an exception.
labelledExamplesWithResult ∷ Testable prop ⇒ Args → prop → IO Result Source #
A variant of labelledExamples
that takes test arguments and returns a result.
labelledExamplesResult ∷ Testable prop ⇒ prop → IO Result Source #
A variant of labelledExamples
that returns a result.
labelledExamplesWith ∷ Testable prop ⇒ Args → prop → IO () Source #
A variant of labelledExamples
that takes test arguments.
labelledExamples ∷ Testable prop ⇒ prop → IO () Source #
Given a property, which must use label
, collect
, classify
or cover
to associate labels with test cases, find an example test case for each possible label.
The example test cases are minimised using shrinking.
For example, suppose we test
and record the number
of times that delete
x xsx
occurs in xs
:
prop_delete :: Int -> [Int] -> Property prop_delete x xs = classify (count x xs == 0) "count x xs == 0" $ classify (count x xs == 1) "count x xs == 1" $ classify (count x xs >= 2) "count x xs >= 2" $ counterexample (show (delete x xs)) $ count x (delete x xs) == max 0 (count x xs-1) where count x xs = length (filter (== x) xs)
labelledExamples
generates three example test cases, one for each label:
>>>
labelledExamples prop_delete
*** Found example of count x xs == 0 0 [] [] *** Found example of count x xs == 1 0 [0] [] *** Found example of count x xs >= 2 5 [5,5] [5] +++ OK, passed 100 tests: 78% count x xs == 0 21% count x xs == 1 1% count x xs >= 2
verboseCheckAll ∷ Q Exp Source #
Test all properties in the current module.
This is just a convenience function that combines quickCheckAll
and verbose
.
verboseCheckAll
has the same issue with scoping as quickCheckAll
:
see the note there about return []
.
quickCheckAll ∷ Q Exp Source #
Test all properties in the current module.
The name of the property must begin with prop_
.
Polymorphic properties will be defaulted to Integer
.
Returns True
if all tests succeeded, False
otherwise.
To use quickCheckAll
, add a definition to your module along
the lines of
return [] runTests = $quickCheckAll
and then execute runTests
.
Note: the bizarre return []
in the example above is needed on
GHC 7.8 and later; without it, quickCheckAll
will not be able to find
any of the properties. For the curious, the return []
is a
Template Haskell splice that makes GHC insert the empty list
of declarations at that point in the program; GHC typechecks
everything before the return []
before it starts on the rest
of the module, which means that the later call to quickCheckAll
can see everything that was defined before the return []
. Yikes!
allProperties ∷ Q Exp Source #
List all properties in the current module.
$
has type allProperties
[(
.String
, Property
)]
allProperties
has the same issue with scoping as quickCheckAll
:
see the note there about return []
.
forAllProperties ∷ Q Exp Source #
Test all properties in the current module, using a custom
quickCheck
function. The same caveats as with quickCheckAll
apply.
$
has type forAllProperties
(
.
An example invocation is Property
-> IO
Result
) -> IO
Bool
$
,
which does the same thing as forAllProperties
quickCheckResult
$
.quickCheckAll
forAllProperties
has the same issue with scoping as quickCheckAll
:
see the note there about return []
.
monomorphic ∷ Name → ExpQ Source #
Monomorphise an arbitrary property by defaulting all type variables to Integer
.
For example, if f
has type
then Ord
a => [a] -> [a]$(
has type monomorphic
'f)[
.Integer
] -> [Integer
]
If you want to use monomorphic
in the same file where you defined the
property, the same scoping problems pop up as in quickCheckAll
:
see the note there about return []
.
polyVerboseCheck ∷ Name → ExpQ Source #
Test a polymorphic property, defaulting all type variables to Integer
.
This is just a convenience function that combines verboseCheck
and monomorphic
.
If you want to use polyVerboseCheck
in the same file where you defined the
property, the same scoping problems pop up as in quickCheckAll
:
see the note there about return []
.
polyQuickCheck ∷ Name → ExpQ Source #
Test a polymorphic property, defaulting all type variables to Integer
.
Invoke as $(
, where polyQuickCheck
'prop)prop
is a property.
Note that just evaluating
in GHCi will seem to
work, but will silently default all type variables to quickCheck
prop()
!
$(
means the same as
polyQuickCheck
'prop)
.
If you want to supply custom arguments to quickCheck
$(monomorphic
'prop)polyQuickCheck
,
you will have to combine quickCheckWith
and monomorphic
yourself.
If you want to use polyQuickCheck
in the same file where you defined the
property, the same scoping problems pop up as in quickCheckAll
:
see the note there about return []
.
verboseCheckWithResult ∷ Testable prop ⇒ Args → prop → IO Result Source #
Tests a property, using test arguments, produces a test result, and prints the results and all test cases generated to stdout
.
This is just a convenience function that combines quickCheckWithResult
and verbose
.
Note: for technical reasons, the test case is printed out after
the property is tested. To debug a property that goes into an
infinite loop, use within
to add a timeout instead.
verboseCheckResult ∷ Testable prop ⇒ prop → IO Result Source #
Tests a property, produces a test result, and prints the results and all test cases generated to stdout
.
This is just a convenience function that combines quickCheckResult
and verbose
.
Note: for technical reasons, the test case is printed out after
the property is tested. To debug a property that goes into an
infinite loop, use within
to add a timeout instead.
verboseCheckWith ∷ Testable prop ⇒ Args → prop → IO () Source #
Tests a property, using test arguments, and prints the results and all test cases generated to stdout
.
This is just a convenience function that combines quickCheckWith
and verbose
.
Note: for technical reasons, the test case is printed out after
the property is tested. To debug a property that goes into an
infinite loop, use within
to add a timeout instead.
verboseCheck ∷ Testable prop ⇒ prop → IO () Source #
Tests a property and prints the results and all test cases generated to stdout
.
This is just a convenience function that means the same as
.quickCheck
. verbose
Note: for technical reasons, the test case is printed out after
the property is tested. To debug a property that goes into an
infinite loop, use within
to add a timeout instead.
recheck ∷ Testable prop ⇒ Result → prop → IO () Source #
Re-run a property with the seed and size that failed in a run of quickCheckResult
.
quickCheckWithResult ∷ Testable prop ⇒ Args → prop → IO Result Source #
Tests a property, using test arguments, produces a test result, and prints the results to stdout
.
quickCheckResult ∷ Testable prop ⇒ prop → IO Result Source #
Tests a property, produces a test result, and prints the results to stdout
.
quickCheckWith ∷ Testable prop ⇒ Args → prop → IO () Source #
Tests a property, using test arguments, and prints the results to stdout
.
quickCheck ∷ Testable prop ⇒ prop → IO () Source #
Tests a property and prints the results to stdout
.
By default up to 100 tests are performed, which may not be enough
to find all bugs. To run more tests, use withMaxSuccess
.
If you want to get the counterexample as a Haskell value, rather than just printing it, try the quickcheck-with-counterexamples package.
Args specifies arguments to the QuickCheck driver
Args | |
|
Result represents the test result
Success | A successful test run |
| |
GaveUp | Given up |
| |
Failure | A failed test run |
| |
NoExpectedFailure | A property that should have failed did not |
|
total ∷ NFData a ⇒ a → Property Source #
Checks that a value is total, i.e., doesn't crash when evaluated.
(=/=) ∷ (Eq a, Show a) ⇒ a → a → Property infix 4 Source #
Like /=
, but prints a counterexample when it fails.
(===) ∷ (Eq a, Show a) ⇒ a → a → Property infix 4 Source #
Like ==
, but prints a counterexample when it fails.
(.||.) ∷ (Testable prop1, Testable prop2) ⇒ prop1 → prop2 → Property infixr 1 Source #
Disjunction: p1
.||.
p2
passes unless p1
and p2
simultaneously fail.
(.&&.) ∷ (Testable prop1, Testable prop2) ⇒ prop1 → prop2 → Property infixr 1 Source #
Conjunction: p1
.&&.
p2
passes if both p1
and p2
pass.
(.&.) ∷ (Testable prop1, Testable prop2) ⇒ prop1 → prop2 → Property infixr 1 Source #
Nondeterministic choice: p1
.&.
p2
picks randomly one of
p1
and p2
to test. If you test the property 100 times it
makes 100 random choices.
forAllShrinkBlind ∷ Testable prop ⇒ Gen a → (a → [a]) → (a → prop) → Property Source #
Like forAllShrink
, but without printing the generated value.
forAllShrinkShow ∷ Testable prop ⇒ Gen a → (a → [a]) → (a → String) → (a → prop) → Property Source #
Like forAllShrink
, but with an explicitly given show function.
forAllShrink ∷ (Show a, Testable prop) ⇒ Gen a → (a → [a]) → (a → prop) → Property Source #
Like forAll
, but tries to shrink the argument for failing test cases.
forAllBlind ∷ Testable prop ⇒ Gen a → (a → prop) → Property Source #
Like forAll
, but without printing the generated value.
forAllShow ∷ Testable prop ⇒ Gen a → (a → String) → (a → prop) → Property Source #
Like forAll
, but with an explicitly given show function.
forAll ∷ (Show a, Testable prop) ⇒ Gen a → (a → prop) → Property Source #
Explicit universal quantification: uses an explicitly given test case generator.
discardAfter ∷ Testable prop ⇒ Int → prop → Property Source #
Discards the test case if it does not complete within the given number of microseconds. This can be useful when testing algorithms that have pathological cases where they run extremely slowly.
within ∷ Testable prop ⇒ Int → prop → Property Source #
Considers a property failed if it does not complete within the given number of microseconds.
Note: if the property times out, variables quantified inside the
within
will not be printed. Therefore, you should use within
only in the body of your property.
Good: prop_foo a b c = within 1000000 ...
Bad: prop_foo = within 1000000 $ \a b c -> ...
Bad: prop_foo a b c = ...; main = quickCheck (within 1000000 prop_foo)
(==>) ∷ Testable prop ⇒ Bool → prop → Property infixr 0 Source #
Implication for properties: The resulting property holds if
the first argument is False
(in which case the test case is discarded),
or if the given property holds. Note that using implication carelessly can
severely skew test case distribution: consider using cover
to make sure
that your test data is still good quality.
coverTable ∷ Testable prop ⇒ String → [(String, Double)] → prop → Property Source #
Checks that the values in a given table
appear a certain proportion of
the time. A call to coverTable
table
[(x1, p1), ..., (xn, pn)]
asserts
that of the values in table
, x1
should appear at least p1
percent of
the time that table
appears, x2
at least p2
percent of the time that
table
appears, and so on.
Note: If the coverage check fails, QuickCheck prints out a warning, but
the property does not fail. To make the property fail, use checkCoverage
.
Continuing the example from the tabular
combinator...
data Command = LogIn | LogOut | SendMessage String deriving (Data, Show) prop_chatroom :: [Command] -> Property prop_chatroom cmds = wellFormed cmds LoggedOut ==> 'tabulate' "Commands" (map (show . 'Data.Data.toConstr') cmds) $ ...
...we can add a coverage requirement as follows, which checks that LogIn
,
LogOut
and SendMessage
each occur at least 25% of the time:
prop_chatroom :: [Command] -> Property prop_chatroom cmds = wellFormed cmds LoggedOut ==> coverTable "Commands" [("LogIn", 25), ("LogOut", 25), ("SendMessage", 25)] $ 'tabulate' "Commands" (map (show . 'Data.Data.toConstr') cmds) $ ... property goes here ...
>>>
quickCheck prop_chatroom
+++ OK, passed 100 tests; 2909 discarded: 56% 0 17% 1 10% 2 6% 3 5% 4 3% 5 3% 7 Commands (111 in total): 51.4% LogIn 30.6% SendMessage 18.0% LogOut Table 'Commands' had only 18.0% LogOut, but expected 25.0%
tabulate ∷ Testable prop ⇒ String → [String] → prop → Property Source #
Collects information about test case distribution into a table.
The arguments to tabulate
are the table's name and a list of values
associated with the current test case. After testing, QuickCheck prints the
frequency of all collected values. The frequencies are expressed as a
percentage of the total number of values collected.
You should prefer tabulate
to label
when each test case is associated
with a varying number of values. Here is a (not terribly useful) example,
where the test data is a list of integers and we record all values that
occur in the list:
prop_sorted_sort :: [Int] -> Property prop_sorted_sort xs = sorted xs ==> tabulate "List elements" (map show xs) $ sort xs === xs
>>>
quickCheck prop_sorted_sort
+++ OK, passed 100 tests; 1684 discarded. List elements (109 in total): 3.7% 0 3.7% 17 3.7% 2 3.7% 6 2.8% -6 2.8% -7
Here is a more useful example. We are testing a chatroom, where the user can log in, log out, or send a message:
data Command = LogIn | LogOut | SendMessage String deriving (Data, Show) instance Arbitrary Command where ...
There are some restrictions on command sequences; for example, the user must
log in before doing anything else. The function valid :: [Command] -> Bool
checks that a command sequence is allowed. Our property then has the form:
prop_chatroom :: [Command] -> Property prop_chatroom cmds = valid cmds ==> ...
The use of ==>
may skew test case distribution. We use collect
to see the
length of the command sequences, and tabulate
to get the frequencies of the
individual commands:
prop_chatroom :: [Command] -> Property prop_chatroom cmds = wellFormed cmds LoggedOut ==> 'collect' (length cmds) $ 'tabulate' "Commands" (map (show . 'Data.Data.toConstr') cmds) $ ...
>>>
quickCheckWith stdArgs{maxDiscardRatio = 1000} prop_chatroom
+++ OK, passed 100 tests; 2775 discarded: 60% 0 20% 1 15% 2 3% 3 1% 4 1% 5 Commands (68 in total): 62% LogIn 22% SendMessage 16% LogOut
∷ Testable prop | |
⇒ Double | The required percentage (0-100) of test cases. |
→ Bool |
|
→ String | Label for the test case class. |
→ prop | |
→ Property |
Checks that at least the given proportion of successful test cases belong to the given class. Discarded tests (i.e. ones with a false precondition) do not affect coverage.
Note: If the coverage check fails, QuickCheck prints out a warning, but
the property does not fail. To make the property fail, use checkCoverage
.
For example:
prop_sorted_sort :: [Int] -> Property prop_sorted_sort xs = sorted xs ==> cover 50 (length xs > 1) "non-trivial" $ sort xs === xs
>>>
quickCheck prop_sorted_sort
+++ OK, passed 100 tests; 135 discarded (26% non-trivial). Only 26% non-trivial, but expected 50%
Reports how many test cases satisfy a given condition.
For example:
prop_sorted_sort :: [Int] -> Property prop_sorted_sort xs = sorted xs ==> classify (length xs > 1) "non-trivial" $ sort xs === xs
>>>
quickCheck prop_sorted_sort
+++ OK, passed 100 tests (22% non-trivial).
collect ∷ (Show a, Testable prop) ⇒ a → prop → Property Source #
Attaches a label to a test case. This is used for reporting test case distribution.
collect x = label (show x)
For example:
prop_reverse_reverse :: [Int] -> Property prop_reverse_reverse xs = collect (length xs) $ reverse (reverse xs) === xs
>>>
quickCheck prop_reverse_reverse
+++ OK, passed 100 tests: 7% 7 6% 3 5% 4 4% 6 ...
Each use of collect
in your property results in a separate
table of test case distribution in the output. If this is
not what you want, use tabulate
.
label ∷ Testable prop ⇒ String → prop → Property Source #
Attaches a label to a test case. This is used for reporting test case distribution.
For example:
prop_reverse_reverse :: [Int] -> Property prop_reverse_reverse xs = label ("length of input is " ++ show (length xs)) $ reverse (reverse xs) === xs
>>>
quickCheck prop_reverse_reverse
+++ OK, passed 100 tests: 7% length of input is 7 6% length of input is 3 5% length of input is 4 4% length of input is 6 ...
Each use of label
in your property results in a separate
table of test case distribution in the output. If this is
not what you want, use tabulate
.
stdConfidence ∷ Confidence Source #
The standard parameters used by checkCoverage
: certainty = 10^9
,
tolerance = 0.9
. See Confidence
for the meaning of the parameters.
checkCoverageWith ∷ Testable prop ⇒ Confidence → prop → Property Source #
Check coverage requirements using a custom confidence level.
See stdConfidence
.
An example of making the statistical test less stringent in order to improve performance:
quickCheck (checkCoverageWith stdConfidence{certainty = 10^6} prop_foo)
checkCoverage ∷ Testable prop ⇒ prop → Property Source #
Check that all coverage requirements defined by cover
and coverTable
are met, using a statistically sound test, and fail if they are not met.
Ordinarily, a failed coverage check does not cause the property to fail.
This is because the coverage requirement is not tested in a statistically
sound way. If you use cover
to express that a certain value must appear 20%
of the time, QuickCheck will warn you if the value only appears in 19 out of
100 test cases - but since the coverage varies randomly, you may have just
been unlucky, and there may not be any real problem with your test
generation.
When you use checkCoverage
, QuickCheck uses a statistical test to account
for the role of luck in coverage failures. It will run as many tests as
needed until it is sure about whether the coverage requirements are met. If a
coverage requirement is not met, the property fails.
Example:
quickCheck (checkCoverage prop_foo)
witness ∷ (Typeable a, Show a, Testable prop) ⇒ a → prop → Property Source #
Return a value in the witnesses
field of the Result
returned by quickCheckResult
. Witnesses
are returned outer-most first.
In ghci, for example:
>>>
[Wit x] <- fmap witnesses . quickCheckResult $ \ x -> witness x $ x == (0 :: Int)
*** Failed! Falsified (after 2 tests): 1>>>
x
1>>>
:t x
x :: Int
withMaxSize ∷ Testable prop ⇒ Int → prop → Property Source #
Configure the maximum size a property will be tested at.
withMaxShrinks ∷ Testable prop ⇒ Int → prop → Property Source #
Configure the maximum number of times a property will be shrunk.
For example,
quickCheck (withMaxShrinks 100 p)
will cause p
to only attempt 100 shrinks on failure.
withDiscardRatio ∷ Testable prop ⇒ Int → prop → Property Source #
Configures how many times a property is allowed to be discarded before failing.
For example,
quickCheck (withDiscardRatio 10 p)
will allow p
to fail up to 10 times per successful test.
withMaxSuccess ∷ Testable prop ⇒ Int → prop → Property Source #
Configures how many times a property will be tested.
For example,
quickCheck (withMaxSuccess 1000 p)
will test p
up to 1000 times.
again ∷ Testable prop ⇒ prop → Property Source #
Modifies a property so that it will be tested repeatedly.
Opposite of once
.
once ∷ Testable prop ⇒ prop → Property Source #
Modifies a property so that it only will be tested once.
Opposite of again
.
expectFailure ∷ Testable prop ⇒ prop → Property Source #
Indicates that a property is supposed to fail. QuickCheck will report an error if it does not fail.
verboseShrinking ∷ Testable prop ⇒ prop → Property Source #
Prints out the generated test case every time the property fails, including during shrinking.
Only variables quantified over inside the verboseShrinking
are printed.
Note: for technical reasons, the test case is printed out after
the property is tested. To debug a property that goes into an
infinite loop, use within
to add a timeout instead.
verbose ∷ Testable prop ⇒ prop → Property Source #
Prints out the generated test case every time the property is tested.
Only variables quantified over inside the verbose
are printed.
Note: for technical reasons, the test case is printed out after
the property is tested. To debug a property that goes into an
infinite loop, use within
to add a timeout instead.
whenFail' ∷ Testable prop ⇒ IO () → prop → Property Source #
Performs an IO
action every time a property fails. Thus,
if shrinking is done, this can be used to keep track of the
failures along the way.
whenFail ∷ Testable prop ⇒ IO () → prop → Property Source #
Performs an IO
action after the last failure of a property.
printTestCase ∷ Testable prop ⇒ String → prop → Property Source #
Adds the given string to the counterexample if the property fails.
counterexample ∷ Testable prop ⇒ String → prop → Property Source #
Adds the given string to the counterexample if the property fails.
noShrinking ∷ Testable prop ⇒ prop → Property Source #
Disables shrinking for a property altogether.
Only quantification inside the call to noShrinking
is affected.
Shrinks the argument to a property if it fails. Shrinking is done automatically for most types. This function is only needed when you want to override the default behavior.
mapSize ∷ Testable prop ⇒ (Int → Int) → prop → Property Source #
Adjust the test case size for a property, by transforming it with the given function.
coerceWitness ∷ Typeable a ⇒ Witness → a Source #
idempotentIOProperty ∷ Testable prop ⇒ IO prop → Property Source #
Do I/O inside a property.
Warning: during shrinking, the I/O may not always be re-executed.
Instead, the I/O may be executed once and then its result retained.
If this is not acceptable, use ioProperty
instead.
ioProperty ∷ Testable prop ⇒ IO prop → Property Source #
Do I/O inside a property.
Warning: any random values generated inside of the argument to ioProperty
will not currently be shrunk. For best results, generate all random values
before calling ioProperty
, or use idempotentIOProperty
if that is safe.
The type of properties.
Instances
Testable Property | |
type Arg Property | |
Defined in Test.Hspec.Core.QuickCheck | |
type Arg (a → Property) | |
Defined in Test.Hspec.Core.QuickCheck |
class Testable prop where Source #
The class of properties, i.e., types which QuickCheck knows how to test.
Typically a property will be a function returning Bool
or Property
.
property ∷ prop → Property Source #
Convert the thing to a property.
propertyForAllShrinkShow ∷ Gen a → (a → [a]) → (a → [String]) → (a → prop) → Property Source #
Optional; used internally in order to improve shrinking.
Tests a property but also quantifies over an extra value
(with a custom shrink and show function).
The Testable
instance for functions defines
propertyForAllShrinkShow
in a way that improves shrinking.
data Confidence Source #
The statistical parameters used by checkCoverage
.
Confidence | |
|
Instances
Show Confidence | |
Defined in Test.QuickCheck.State |
applyFun3 ∷ Fun (a, b, c) d → a → b → c → d Source #
Extracts the value of a ternary function. Fn3
is the
pattern equivalent of this function.
applyFun2 ∷ Fun (a, b) c → a → b → c Source #
Extracts the value of a binary function.
Fn2
is the pattern equivalent of this function.
prop_zipWith :: Fun (Int, Bool) Char -> [Int] -> [Bool] -> Bool prop_zipWith f xs ys = zipWith (applyFun2 f) xs ys == [ applyFun2 f x y | (x, y) <- zip xs ys]
applyFun ∷ Fun a b → a → b Source #
Extracts the value of a function.
Fn
is the pattern equivalent of this function.
prop :: Fun String Integer -> Bool prop f = applyFun f "banana" == applyFun f "monkey" || applyFun f "banana" == applyFun f "elephant"
functionMap ∷ Function b ⇒ (a → b) → (b → a) → (a → c) → a :-> c Source #
functionVoid ∷ (∀ b. void → b) → void :-> c Source #
functionIntegral ∷ Integral a ⇒ (a → b) → a :-> b Source #
functionRealFrac ∷ RealFrac a ⇒ (a → b) → a :-> b Source #
pattern Fn ∷ (a → b) → Fun a b Source #
A modifier for testing functions.
prop :: Fun String Integer -> Bool prop (Fn f) = f "banana" == f "monkey" || f "banana" == f "elephant"
pattern Fn2 ∷ (a → b → c) → Fun (a, b) c Source #
A modifier for testing binary functions.
prop_zipWith :: Fun (Int, Bool) Char -> [Int] -> [Bool] -> Bool prop_zipWith (Fn2 f) xs ys = zipWith f xs ys == [ f x y | (x, y) <- zip xs ys]
class Function a where Source #
The class Function a
is used for random generation of showable
functions of type a -> b
.
There is a default implementation for function
, which you can use
if your type has structural equality. Otherwise, you can normally
use functionMap
or functionShow
.
Nothing
Instances
Generation of random shrinkable, showable functions.
To generate random values of type
,
you must have an instance Fun
a b
.Function
a
Blind x
: as x, but x does not have to be in the Show
class.
Instances
Functor Blind | |
Arbitrary a ⇒ Arbitrary (Blind a) | |
Enum a ⇒ Enum (Blind a) | |
Defined in Test.QuickCheck.Modifiers succ ∷ Blind a → Blind a Source # pred ∷ Blind a → Blind a Source # toEnum ∷ Int → Blind a Source # fromEnum ∷ Blind a → Int Source # enumFrom ∷ Blind a → [Blind a] Source # enumFromThen ∷ Blind a → Blind a → [Blind a] Source # enumFromTo ∷ Blind a → Blind a → [Blind a] Source # enumFromThenTo ∷ Blind a → Blind a → Blind a → [Blind a] Source # | |
Num a ⇒ Num (Blind a) | |
Defined in Test.QuickCheck.Modifiers | |
Integral a ⇒ Integral (Blind a) | |
Defined in Test.QuickCheck.Modifiers | |
Real a ⇒ Real (Blind a) | |
Defined in Test.QuickCheck.Modifiers toRational ∷ Blind a → Rational Source # | |
Show (Blind a) | |
Eq a ⇒ Eq (Blind a) | |
Ord a ⇒ Ord (Blind a) | |
Defined in Test.QuickCheck.Modifiers |
Fixed x
: as x, but will not be shrunk.
Instances
Functor Fixed | |
Arbitrary a ⇒ Arbitrary (Fixed a) | |
Enum a ⇒ Enum (Fixed a) | |
Defined in Test.QuickCheck.Modifiers succ ∷ Fixed a → Fixed a Source # pred ∷ Fixed a → Fixed a Source # toEnum ∷ Int → Fixed a Source # fromEnum ∷ Fixed a → Int Source # enumFrom ∷ Fixed a → [Fixed a] Source # enumFromThen ∷ Fixed a → Fixed a → [Fixed a] Source # enumFromTo ∷ Fixed a → Fixed a → [Fixed a] Source # enumFromThenTo ∷ Fixed a → Fixed a → Fixed a → [Fixed a] Source # | |
Num a ⇒ Num (Fixed a) | |
Defined in Test.QuickCheck.Modifiers | |
Read a ⇒ Read (Fixed a) | |
Integral a ⇒ Integral (Fixed a) | |
Defined in Test.QuickCheck.Modifiers | |
Real a ⇒ Real (Fixed a) | |
Defined in Test.QuickCheck.Modifiers toRational ∷ Fixed a → Rational Source # | |
Show a ⇒ Show (Fixed a) | |
Eq a ⇒ Eq (Fixed a) | |
Ord a ⇒ Ord (Fixed a) | |
Defined in Test.QuickCheck.Modifiers |
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) | |
Defined in Test.QuickCheck.Modifiers arbitrary ∷ Gen (InfiniteList a) Source # shrink ∷ InfiniteList a → [InfiniteList a] Source # | |
Show a ⇒ Show (InfiniteList a) | |
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
Functor Positive | |
(Num a, Ord a, Arbitrary a) ⇒ Arbitrary (Positive a) | |
Enum a ⇒ Enum (Positive a) | |
Defined in Test.QuickCheck.Modifiers succ ∷ Positive a → Positive a Source # pred ∷ Positive a → Positive a Source # toEnum ∷ Int → Positive a Source # fromEnum ∷ Positive a → Int Source # enumFrom ∷ Positive a → [Positive a] Source # enumFromThen ∷ Positive a → Positive a → [Positive a] Source # enumFromTo ∷ Positive a → Positive a → [Positive a] Source # enumFromThenTo ∷ Positive a → Positive a → Positive a → [Positive a] Source # | |
Read a ⇒ Read (Positive a) | |
Show a ⇒ Show (Positive a) | |
Eq a ⇒ Eq (Positive a) | |
Ord a ⇒ Ord (Positive a) | |
Defined in Test.QuickCheck.Modifiers |
Negative x
: guarantees that x < 0
.
Negative | |
|
Instances
Functor Negative | |
(Num a, Ord a, Arbitrary a) ⇒ Arbitrary (Negative a) | |
Enum a ⇒ Enum (Negative a) | |
Defined in Test.QuickCheck.Modifiers succ ∷ Negative a → Negative a Source # pred ∷ Negative a → Negative a Source # toEnum ∷ Int → Negative a Source # fromEnum ∷ Negative a → Int Source # enumFrom ∷ Negative a → [Negative a] Source # enumFromThen ∷ Negative a → Negative a → [Negative a] Source # enumFromTo ∷ Negative a → Negative a → [Negative a] Source # enumFromThenTo ∷ Negative a → Negative a → Negative a → [Negative a] Source # | |
Read a ⇒ Read (Negative a) | |
Show a ⇒ Show (Negative a) | |
Eq a ⇒ Eq (Negative a) | |
Ord a ⇒ Ord (Negative a) | |
Defined in Test.QuickCheck.Modifiers |
NonZero x
: guarantees that x /= 0
.
NonZero | |
|
Instances
Functor NonZero | |
(Num a, Eq a, Arbitrary a) ⇒ Arbitrary (NonZero a) | |
Enum a ⇒ Enum (NonZero a) | |
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) | |
Show a ⇒ Show (NonZero a) | |
Eq a ⇒ Eq (NonZero a) | |
Ord a ⇒ Ord (NonZero a) | |
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
Functor Large | |
(Integral a, Bounded a) ⇒ Arbitrary (Large a) | |
Enum a ⇒ Enum (Large a) | |
Defined in Test.QuickCheck.Modifiers succ ∷ Large a → Large a Source # pred ∷ Large a → Large a Source # toEnum ∷ Int → Large a Source # fromEnum ∷ Large a → Int Source # enumFrom ∷ Large a → [Large a] Source # enumFromThen ∷ Large a → Large a → [Large a] Source # enumFromTo ∷ Large a → Large a → [Large a] Source # enumFromThenTo ∷ Large a → Large a → Large a → [Large a] Source # | |
Ix a ⇒ Ix (Large a) | |
Num a ⇒ Num (Large a) | |
Defined in Test.QuickCheck.Modifiers | |
Read a ⇒ Read (Large a) | |
Integral a ⇒ Integral (Large a) | |
Defined in Test.QuickCheck.Modifiers | |
Real a ⇒ Real (Large a) | |
Defined in Test.QuickCheck.Modifiers toRational ∷ Large a → Rational Source # | |
Show a ⇒ Show (Large a) | |
Eq a ⇒ Eq (Large a) | |
Ord a ⇒ Ord (Large a) | |
Defined in Test.QuickCheck.Modifiers |
Small x
: generates values of x
drawn from a small range.
The opposite of Large
.
Instances
Functor Small | |
Integral a ⇒ Arbitrary (Small a) | |
Enum a ⇒ Enum (Small a) | |
Defined in Test.QuickCheck.Modifiers succ ∷ Small a → Small a Source # pred ∷ Small a → Small a Source # toEnum ∷ Int → Small a Source # fromEnum ∷ Small a → Int Source # enumFrom ∷ Small a → [Small a] Source # enumFromThen ∷ Small a → Small a → [Small a] Source # enumFromTo ∷ Small a → Small a → [Small a] Source # enumFromThenTo ∷ Small a → Small a → Small a → [Small a] Source # | |
Ix a ⇒ Ix (Small a) | |
Num a ⇒ Num (Small a) | |
Defined in Test.QuickCheck.Modifiers | |
Read a ⇒ Read (Small a) | |
Integral a ⇒ Integral (Small a) | |
Defined in Test.QuickCheck.Modifiers | |
Real a ⇒ Real (Small a) | |
Defined in Test.QuickCheck.Modifiers toRational ∷ Small a → Rational Source # | |
Show a ⇒ Show (Small a) | |
Eq a ⇒ Eq (Small a) | |
Ord a ⇒ Ord (Small a) | |
Defined in Test.QuickCheck.Modifiers |
Shrink2 x
: allows 2 shrinking steps at the same time when shrinking x
Shrink2 | |
|
Instances
Smart _ x
: tries a different order when shrinking.
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 | |
Defined in Test.QuickCheck.Modifiers | |
Read ASCIIString | |
Defined in Test.QuickCheck.Modifiers | |
Show ASCIIString | |
Defined in Test.QuickCheck.Modifiers | |
Eq ASCIIString | |
Defined in Test.QuickCheck.Modifiers (==) ∷ ASCIIString → ASCIIString → Bool Source # (/=) ∷ ASCIIString → ASCIIString → Bool Source # | |
Ord ASCIIString | |
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 | |
Defined in Test.QuickCheck.Modifiers | |
Read UnicodeString | |
Defined in Test.QuickCheck.Modifiers | |
Show UnicodeString | |
Defined in Test.QuickCheck.Modifiers | |
Eq UnicodeString | |
Defined in Test.QuickCheck.Modifiers (==) ∷ UnicodeString → UnicodeString → Bool Source # (/=) ∷ UnicodeString → UnicodeString → Bool Source # | |
Ord UnicodeString | |
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 | |
Defined in Test.QuickCheck.Modifiers | |
Read PrintableString | |
Show PrintableString | |
Defined in Test.QuickCheck.Modifiers | |
Eq PrintableString | |
Defined in Test.QuickCheck.Modifiers | |
Ord PrintableString | |
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 # |
infiniteList ∷ Arbitrary a ⇒ Gen [a] Source #
Generates an infinite list.
coarbitraryEnum ∷ Enum a ⇒ a → Gen b → Gen b Source #
A coarbitrary
implementation for enums.
coarbitraryShow ∷ Show a ⇒ a → Gen b → Gen b Source #
coarbitrary
helper for lazy people :-).
coarbitraryReal ∷ Real a ⇒ a → Gen b → Gen b Source #
A coarbitrary
implementation for real numbers.
coarbitraryIntegral ∷ Integral a ⇒ a → Gen b → Gen b Source #
A coarbitrary
implementation for integral numbers.
(><) ∷ (Gen a → Gen a) → (Gen a → Gen a) → Gen a → Gen a Source #
Combine two generator perturbing functions, for example the
results of calls to variant
or coarbitrary
.
genericCoarbitrary ∷ (Generic a, GCoArbitrary (Rep a)) ⇒ a → Gen b → Gen b Source #
Generic CoArbitrary implementation.
shrinkDecimal ∷ RealFrac a ⇒ a → [a] Source #
Shrink a real number, preferring numbers with shorter
decimal representations. See also shrinkRealFrac
.
shrinkRealFrac ∷ RealFrac a ⇒ a → [a] Source #
Shrink a fraction, preferring numbers with smaller
numerators or denominators. See also shrinkDecimal
.
shrinkBoundedEnum ∷ (Bounded a, Enum a, Eq a) ⇒ a → [a] Source #
Shrink an element of a bounded enumeration.
Example
data MyEnum = E0 | E1 | E2 | E3 | E4 | E5 | E6 | E7 | E8 | E9 deriving (Bounded, Enum, Eq, Ord, Show)
>>>
shrinkBoundedEnum E9
[E0,E5,E7,E8]
>>>
shrinkBoundedEnum E5
[E0,E3,E4]
>>>
shrinkBoundedEnum E0
[]
shrinkIntegral ∷ Integral a ⇒ a → [a] Source #
Shrink an integral number.
shrinkMapBy ∷ (a → b) → (b → a) → (a → [a]) → b → [b] Source #
Non-overloaded version of shrinkMap
.
shrinkMap ∷ Arbitrary a ⇒ (a → b) → (b → a) → b → [b] Source #
Map a shrink function to another domain. This is handy if your data type has special invariants, but is almost isomorphic to some other type.
shrinkOrderedList :: (Ord a, Arbitrary a) => [a] -> [[a]] shrinkOrderedList = shrinkMap sort id shrinkSet :: (Ord a, Arbitrary a) => Set a -> [Set a] shrinkSet = shrinkMap fromList toList
shrinkNothing ∷ a → [a] Source #
Returns no shrinking alternatives.
arbitraryPrintableChar ∷ Gen Char Source #
Generates a printable Unicode character.
arbitraryASCIIChar ∷ Gen Char Source #
Generates a random ASCII character (0-127).
arbitraryUnicodeChar ∷ Gen Char Source #
Generates any Unicode character (but not a surrogate)
arbitrarySizedBoundedIntegral ∷ (Bounded a, Integral a) ⇒ Gen a Source #
Generates an integral number from a bounded domain. The number is chosen from the entire range of the type, but small numbers are generated more often than big numbers. Inspired by demands from Phil Wadler.
arbitraryBoundedEnum ∷ (Bounded a, Enum a) ⇒ Gen a Source #
Generates an element of a bounded enumeration.
arbitraryBoundedRandom ∷ (Bounded a, Random a) ⇒ Gen a Source #
Generates an element of a bounded type. The element is chosen from the entire range of the type.
arbitraryBoundedIntegral ∷ (Bounded a, Integral a) ⇒ Gen a Source #
Generates an integral number. The number is chosen uniformly from
the entire range of the type. You may want to use
arbitrarySizedBoundedIntegral
instead.
arbitrarySizedFractional ∷ Fractional a ⇒ Gen a Source #
Uniformly generates a fractional number. The number can be positive or negative and its maximum absolute value depends on the size parameter.
arbitrarySizedNatural ∷ Integral a ⇒ Gen a Source #
Generates a natural number. The number's maximum value depends on the size parameter.
arbitrarySizedIntegral ∷ Integral a ⇒ Gen a Source #
Generates an integral number. The number can be positive or negative and its maximum absolute value depends on the size parameter.
applyArbitrary4 ∷ (Arbitrary a, Arbitrary b, Arbitrary c, Arbitrary d) ⇒ (a → b → c → d → r) → Gen r Source #
Apply a function of arity 4 to random arguments.
applyArbitrary3 ∷ (Arbitrary a, Arbitrary b, Arbitrary c) ⇒ (a → b → c → r) → Gen r Source #
Apply a ternary function to random arguments.
applyArbitrary2 ∷ (Arbitrary a, Arbitrary b) ⇒ (a → b → r) → Gen r Source #
Apply a binary function to random arguments.
shrinkList ∷ (a → [a]) → [a] → [[a]] Source #
Shrink a list of values given a shrinking function for individual values.
recursivelyShrink ∷ (Generic a, RecursivelyShrink (Rep a)) ⇒ a → [a] Source #
Recursively shrink all immediate subterms.
genericShrink ∷ (Generic a, RecursivelyShrink (Rep a), GSubterms (Rep a) a) ⇒ a → [a] Source #
Shrink a term to any of its immediate subterms, and also recursively shrink all subterms.
arbitrary2 ∷ (Arbitrary2 f, Arbitrary a, Arbitrary b) ⇒ Gen (f a b) Source #
shrink1 ∷ (Arbitrary1 f, Arbitrary a) ⇒ f a → [f a] Source #
arbitrary1 ∷ (Arbitrary1 f, Arbitrary a) ⇒ Gen (f a) Source #
class Arbitrary a where Source #
Random generation and shrinking of values.
QuickCheck provides Arbitrary
instances for most types in base
,
except those which incur extra dependencies.
For a wider range of Arbitrary
instances see the
quickcheck-instances
package.
Produces a (possibly) empty list of all the possible immediate shrinks of the given value.
The default implementation returns the empty list, so will not try to
shrink the value. If your data type has no special invariants, you can
enable shrinking by defining shrink =
, but by customising
the behaviour of genericShrink
shrink
you can often get simpler counterexamples.
Most implementations of shrink
should try at least three things:
- Shrink a term to any of its immediate subterms.
You can use
subterms
to do this. - Recursively apply
shrink
to all immediate subterms. You can userecursivelyShrink
to do this. - Type-specific shrinkings such as replacing a constructor by a simpler constructor.
For example, suppose we have the following implementation of binary trees:
data Tree a = Nil | Branch a (Tree a) (Tree a)
We can then define shrink
as follows:
shrink Nil = [] shrink (Branch x l r) = -- shrink Branch to Nil [Nil] ++ -- shrink to subterms [l, r] ++ -- recursively shrink subterms [Branch x' l' r' | (x', l', r') <- shrink (x, l, r)]
There are a couple of subtleties here:
- QuickCheck tries the shrinking candidates in the order they
appear in the list, so we put more aggressive shrinking steps
(such as replacing the whole tree by
Nil
) before smaller ones (such as recursively shrinking the subtrees). - It is tempting to write the last line as
[Branch x' l' r' | x' <- shrink x, l' <- shrink l, r' <- shrink r]
but this is the wrong thing! It will force QuickCheck to shrinkx
,l
andr
in tandem, and shrinking will stop once one of the three is fully shrunk.
There is a fair bit of boilerplate in the code above.
We can avoid it with the help of some generic functions.
The function genericShrink
tries shrinking a term to all of its
subterms and, failing that, recursively shrinks the subterms.
Using it, we can define shrink
as:
shrink x = shrinkToNil x ++ genericShrink x where shrinkToNil Nil = [] shrinkToNil (Branch _ l r) = [Nil]
genericShrink
is a combination of subterms
, which shrinks
a term to any of its subterms, and recursivelyShrink
, which shrinks
all subterms of a term. These may be useful if you need a bit more
control over shrinking than genericShrink
gives you.
A final gotcha: we cannot define shrink
as simply
as this shrinks shrink
x = Nil:genericShrink
xNil
to Nil
, and shrinking will go into an
infinite loop.
If all this leaves you bewildered, you might try
to begin with,
after deriving shrink
= genericShrink
Generic
for your type. However, if your data type has any
special invariants, you will need to check that genericShrink
can't break those invariants.
Instances
class Arbitrary1 (f ∷ Type → Type) where Source #
Lifting of the Arbitrary
class to unary type constructors.
liftArbitrary ∷ Gen a → Gen (f a) Source #
liftShrink ∷ (a → [a]) → f a → [f a] Source #
Instances
class Arbitrary2 (f ∷ Type → Type → Type) where Source #
Lifting of the Arbitrary
class to binary type constructors.
liftArbitrary2 ∷ Gen a → Gen b → Gen (f a b) Source #
liftShrink2 ∷ (a → [a]) → (b → [b]) → f a b → [f a b] Source #
Instances
Arbitrary2 Either | |
Defined in Test.QuickCheck.Arbitrary | |
Arbitrary2 (,) | |
Defined in Test.QuickCheck.Arbitrary liftArbitrary2 ∷ Gen a → Gen b → Gen (a, b) Source # liftShrink2 ∷ (a → [a]) → (b → [b]) → (a, b) → [(a, b)] Source # | |
Arbitrary2 (Const ∷ Type → Type → Type) | |
Defined in Test.QuickCheck.Arbitrary | |
Arbitrary2 (Constant ∷ Type → Type → Type) | |
Defined in Test.QuickCheck.Arbitrary |
class CoArbitrary a where Source #
Used for random generation of functions.
You should consider using Fun
instead, which
can show the generated functions as strings.
If you are using a recent GHC, there is a default definition of
coarbitrary
using genericCoarbitrary
, so if your type has a
Generic
instance it's enough to say
instance CoArbitrary MyType
You should only use genericCoarbitrary
for data types where
equality is structural, i.e. if you can't have two different
representations of the same value. An example where it's not
safe is sets implemented using binary search trees: the same
set can be represented as several different trees.
Here you would have to explicitly define
coarbitrary s = coarbitrary (toList s)
.
Nothing
coarbitrary ∷ a → Gen b → Gen b Source #
Used to generate a function of type a -> b
.
The first argument is a value, the second a generator.
You should use variant
to perturb the random generator;
the goal is that different values for the first argument will
lead to different calls to variant
. An example will help:
instance CoArbitrary a => CoArbitrary [a] where coarbitrary [] =variant
0 coarbitrary (x:xs) =variant
1 . coarbitrary (x,xs)
Instances
infiniteListOf ∷ Gen a → Gen [a] Source #
Generates an infinite list.
suchThatMap ∷ Gen a → (a → Maybe b) → Gen b Source #
Generates a value for which the given function returns a Just
, and then
applies the function.
generate ∷ Gen a → IO a Source #
Run a generator. The size passed to the generator is always 30;
if you want another size then you should explicitly use resize
.
chooseBoundedIntegral ∷ (Bounded a, Integral a) ⇒ (a, a) → Gen a Source #
A fast implementation of choose
for bounded integral types.
scale ∷ (Int → Int) → Gen a → Gen a Source #
Adjust the size parameter, by transforming it with the given function.
Returns the size parameter. Used to construct generators that depend on the size parameter.
For example, listOf
, which uses the size parameter as an upper bound on
length of lists it generates, can be defined like this:
listOf :: Gen a -> Gen [a] listOf gen = do n <- getSize k <- choose (0,n) vectorOf k gen
You can also do this using sized
.
A generator for values of type a
.
The third-party packages
QuickCheck-GenT
and
quickcheck-transformer
provide monad transformer versions of Gen
.
Instances
MonadFix Gen | |
Applicative Gen | |
Functor Gen | |
Monad Gen | |
MonadGen Gen | |
StatefulGen QC Gen | |
Defined in Test.Cardano.Ledger.Binary.Random uniformWord32R ∷ Word32 → QC → Gen Word32 Source # uniformWord64R ∷ Word64 → QC → Gen Word64 Source # uniformWord8 ∷ QC → Gen Word8 Source # uniformWord16 ∷ QC → Gen Word16 Source # uniformWord32 ∷ QC → Gen Word32 Source # uniformWord64 ∷ QC → Gen Word64 Source # uniformShortByteString ∷ Int → QC → Gen ShortByteString Source # | |
Testable prop ⇒ Testable (Gen prop) | |
FindGen ('Match 'INCOHERENT) s (Gen a) gs a | Matching custom generator for |
Defined in Generic.Random.Internal.Generic findGen ∷ (Proxy ('Match 'INCOHERENT), Proxy s, FullGenListOf s) → Gen a → gs → Gen a Source # | |
a ~ a' ⇒ FindGen ('MatchCoh 'True) s (Gen a) gs a' | |
Arbitrary a ⇒ TypeLevelGenList (Gen a ∷ TYPE LiftedRep) | |
Defined in Generic.Random.DerivingVia type TypeLevelGenList' (Gen a) Source # | |
type TypeLevelGenList' (Gen a ∷ TYPE LiftedRep) | |
Defined in Generic.Random.DerivingVia |
(>=>) ∷ Monad m ⇒ (a → m b) → (b → m c) → a → m c infixr 1 Source #
Left-to-right composition of Kleisli arrows.
'(bs
' can be understood as the >=>
cs) ado
expression
do b <- bs a cs b
replicateM_ ∷ Applicative m ⇒ Int → m a → m () Source #
replicateM ∷ Applicative m ⇒ Int → m a → m [a] Source #
performs the action replicateM
n actact
n
times,
and then returns the list of results:
Examples
>>>
import Control.Monad.State
>>>
runState (replicateM 3 $ state $ \s -> (s, s + 1)) 1
([1,2,3],4)
type HasCallStack = ?callStack ∷ CallStack Source #
Request a CallStack.
NOTE: The implicit parameter ?callStack :: CallStack
is an
implementation detail and should not be considered part of the
CallStack
API, we may decide to change the implementation in the
future.
Since: base-4.9.0.0
diffExprCompactString ∷ ToExpr a ⇒ a → a → String Source #
diffExprString ∷ ToExpr a ⇒ a → a → String Source #
ansiExprString ∷ ToExpr a ⇒ a → String Source #
toExpr
converts a Haskell value into
untyped Haskell-like syntax tree, Expr
.
>>>
toExpr ((1, Just 2) :: (Int, Maybe Int))
App "_\215_" [App "1" [],App "Just" [App "2" []]]
Nothing
Instances
type Expectation = Assertion Source #
example ∷ Expectation → Expectation Source #
example
is a type restricted version of id
. It can be used to get better
error messages on type mismatches.
Compare e.g.
it "exposes some behavior" $ example $ do putStrLn
with
it "exposes some behavior" $ do putStrLn
type ActionWith a = a → IO () Source #
An IO
action that expects an argument of type a
A type class for examples
Instances
Instances
type Arg Property | |
Defined in Test.Hspec.Core.QuickCheck | |
type Arg Result | |
Defined in Test.Hspec.Core.Example | |
type Arg Expectation | |
Defined in Test.Hspec.Core.Example | |
type Arg Bool | |
Defined in Test.Hspec.Core.Example | |
type Arg (ImpM t p) | |
Defined in Test.ImpSpec.Internal | |
type Arg (a → ImpM t p) | |
Defined in Test.ImpSpec.Internal | |
type Arg (a → Property) | |
Defined in Test.Hspec.Core.QuickCheck | |
type Arg (a → Result) | |
Defined in Test.Hspec.Core.Example | |
type Arg (a → Expectation) | |
Defined in Test.Hspec.Core.Example | |
type Arg (a → Bool) | |
Defined in Test.Hspec.Core.Example |
runIO ∷ IO r → SpecM a r Source #
Run an IO action while constructing the spec tree.
SpecM
is a monad to construct a spec tree, without executing any spec
items. runIO
allows you to run IO actions during this construction phase.
The IO action is always run when the spec tree is constructed (e.g. even
when --dry-run
is specified).
If you do not need the result of the IO action to construct the spec tree,
beforeAll
may be more suitable for your use case.
modifyMaxSuccess ∷ (Int → Int) → SpecWith a → SpecWith a Source #
Use a modified maxSuccess
for given spec.
modifyMaxDiscardRatio ∷ (Int → Int) → SpecWith a → SpecWith a Source #
Use a modified maxDiscardRatio
for given spec.
modifyMaxSize ∷ (Int → Int) → SpecWith a → SpecWith a Source #
Use a modified maxSize
for given spec.
modifyMaxShrinks ∷ (Int → Int) → SpecWith a → SpecWith a Source #
Use a modified maxShrinks
for given spec.
beforeWith ∷ (b → IO a) → SpecWith a → SpecWith b Source #
Run a custom action before every spec item.
beforeAll ∷ HasCallStack ⇒ IO a → SpecWith a → Spec Source #
Run a custom action before the first spec item.
beforeAll_ ∷ HasCallStack ⇒ IO () → SpecWith a → SpecWith a Source #
Run a custom action before the first spec item.
beforeAllWith ∷ HasCallStack ⇒ (b → IO a) → SpecWith a → SpecWith b Source #
Run a custom action with an argument before the first spec item.
around ∷ (ActionWith a → IO ()) → SpecWith a → Spec Source #
Run a custom action before and/or after every spec item.
afterAll ∷ HasCallStack ⇒ ActionWith a → SpecWith a → SpecWith a Source #
Run a custom action after the last spec item.
afterAll_ ∷ HasCallStack ⇒ IO () → SpecWith a → SpecWith a Source #
Run a custom action after the last spec item.
around_ ∷ (IO () → IO ()) → SpecWith a → SpecWith a Source #
Run a custom action before and/or after every spec item.
aroundWith ∷ (ActionWith a → ActionWith b) → SpecWith a → SpecWith b Source #
Run a custom action before and/or after every spec item.
aroundAll ∷ HasCallStack ⇒ (ActionWith a → IO ()) → SpecWith a → Spec Source #
Wrap an action around the given spec.
aroundAll_ ∷ HasCallStack ⇒ (IO () → IO ()) → SpecWith a → SpecWith a Source #
Wrap an action around the given spec.
aroundAllWith ∷ HasCallStack ⇒ (ActionWith a → ActionWith b) → SpecWith a → SpecWith b Source #
Wrap an action around the given spec. Changes the arg type inside.
mapSubject ∷ (b → a) → SpecWith a → SpecWith b Source #
Modify the subject under test.
Note that this resembles a contravariant functor on the first type parameter
of SpecM
. This is because the subject is passed inwards, as an argument
to the spec item.
ignoreSubject ∷ SpecWith () → SpecWith a Source #
Ignore the subject under test for a given spec.
xcontext ∷ HasCallStack ⇒ String → SpecWith a → SpecWith a Source #
xcontext
is an alias for xdescribe
.
specify ∷ (HasCallStack, Example a) ⇒ String → a → SpecWith (Arg a) Source #
specify
is an alias for it
.
xspecify ∷ (HasCallStack, Example a) ⇒ String → a → SpecWith (Arg a) Source #
xspecify
is an alias for xit
.
fspecify ∷ (HasCallStack, Example a) ⇒ String → a → SpecWith (Arg a) Source #
fspecify
is an alias for fit
.
fcontext ∷ HasCallStack ⇒ String → SpecWith a → SpecWith a Source #
fcontext
is an alias for fdescribe
.
parallel ∷ SpecWith a → SpecWith a Source #
parallel
marks all spec items of the given spec to be safe for parallel
evaluation.
sequential ∷ SpecWith a → SpecWith a Source #
sequential
marks all spec items of the given spec to be evaluated sequentially.
pending ∷ HasCallStack ⇒ Expectation Source #
pending
can be used to mark a spec item as pending.
If you want to textually specify a behavior but do not have an example yet, use this:
describe "fancyFormatter" $ do it "can format text in a way that everyone likes" $ pending
pendingWith ∷ HasCallStack ⇒ String → Expectation Source #
pendingWith
is similar to pending
, but it takes an additional string
argument that can be used to specify the reason for why the spec item is pending.
Run a given spec and write a report to stdout
.
Exit with exitFailure
if at least one spec item fails.
Note: hspec
handles command-line options and reads config files. This
is not always desirable. Use evalSpec
and runSpecForest
if you need
more control over these aspects.
ledgerTestMain ∷ Spec → IO () Source #
tracedDiscard ∷ String → a Source #
Same as discard
but outputs a debug trace message
Enforce the type of expectation
Useful with polymorphic expectations that are defined below.
Example
Because shouldBeExpr
is polymorphic in m
, compiler will choke with a unification
error. This is due to the fact that hspec's it
expects a polymorphic Example
.
it "MyTest" $ do "foo" `shouldBeExpr` "bar"
However, this is easily solved by io
:
it "MyTest" $ io $ do "foo" `shouldBeExpr` "bar"
Expectations
Lifted expectations
assertBool ∷ (HasCallStack, MonadIO m) ⇒ String → Bool → m () Source #
Lifted version of assertBool
assertFailure ∷ (HasCallStack, MonadIO m) ⇒ String → m a Source #
Just like expectationFailure
, but does not force the return type to unit. Lifted
version of assertFailure
assertColorFailure ∷ (HasCallStack, MonadIO m) ⇒ String → m a Source #
expectationFailure ∷ (HasCallStack, MonadIO m) ⇒ String → m () Source #
shouldBe ∷ (HasCallStack, MonadIO m, Show a, Eq a) ⇒ a → a → m () infix 1 Source #
actual `shouldBe` expected
sets the expectation that actual
is equal
to expected
.
shouldSatisfy ∷ (HasCallStack, MonadIO m, Show a) ⇒ a → (a → Bool) → m () infix 1 Source #
v `shouldSatisfy` p
sets the expectation that p v
is True
.
shouldSatisfyExpr ∷ (HasCallStack, MonadIO m, ToExpr a) ⇒ a → (a → Bool) → m () Source #
shouldStartWith ∷ (HasCallStack, MonadIO m, Show a, Eq a) ⇒ [a] → [a] → m () infix 1 Source #
list `shouldStartWith` prefix
sets the expectation that list
starts with prefix
,
shouldEndWith ∷ (HasCallStack, MonadIO m, Show a, Eq a) ⇒ [a] → [a] → m () infix 1 Source #
list `shouldEndWith` suffix
sets the expectation that list
ends with suffix
,
shouldContain ∷ (HasCallStack, MonadIO m, Show a, Eq a) ⇒ [a] → [a] → m () infix 1 Source #
list `shouldContain` sublist
sets the expectation that sublist
is contained,
wholly and intact, anywhere in list
.
shouldMatchList ∷ (HasCallStack, MonadIO m, Show a, Eq a) ⇒ [a] → [a] → m () infix 1 Source #
xs `shouldMatchList` ys
sets the expectation that xs
has the same
elements that ys
has, possibly in another order
shouldReturn ∷ (HasCallStack, MonadIO m, Show a, Eq a) ⇒ m a → a → m () infix 1 Source #
action `shouldReturn` expected
sets the expectation that action
returns expected
.
shouldNotBe ∷ (HasCallStack, MonadIO m, Show a, Eq a) ⇒ a → a → m () infix 1 Source #
actual `shouldNotBe` notExpected
sets the expectation that actual
is not
equal to notExpected
shouldNotSatisfy ∷ (HasCallStack, MonadIO m, Show a) ⇒ a → (a → Bool) → m () infix 1 Source #
v `shouldNotSatisfy` p
sets the expectation that p v
is False
.
shouldNotContain ∷ (HasCallStack, MonadIO m, Show a, Eq a) ⇒ [a] → [a] → m () infix 1 Source #
list `shouldNotContain` sublist
sets the expectation that sublist
is not
contained anywhere in list
.
shouldNotReturn ∷ (HasCallStack, MonadIO m, Show a, Eq a) ⇒ m a → a → m () infix 1 Source #
action `shouldNotReturn` notExpected
sets the expectation that action
does not return notExpected
.
shouldThrow ∷ (HasCallStack, Exception e, MonadUnliftIO m) ⇒ m a → Selector e → m () infix 1 Source #
Lifted version of shouldThrow
.
Non-standard expectations
shouldBeExpr ∷ (HasCallStack, ToExpr a, Eq a, MonadIO m) ⇒ a → a → m () infix 1 Source #
shouldBeRight ∷ (HasCallStack, Show a, Show b, Eq b, MonadIO m) ⇒ Either a b → b → m () infix 1 Source #
shouldBeLeft ∷ (HasCallStack, Show a, Eq a, Show b, MonadIO m) ⇒ Either a b → a → m () infix 1 Source #
shouldBeRightExpr ∷ (HasCallStack, ToExpr a, Eq b, ToExpr b, MonadIO m) ⇒ Either a b → b → m () infix 1 Source #
Same as shouldBeExpr
, except it checks that the value is Right
shouldBeLeftExpr ∷ (HasCallStack, ToExpr a, ToExpr b, Eq a, MonadIO m) ⇒ Either a b → a → m () infix 1 Source #
Same as shouldBeExpr
, except it checks that the value is Left
shouldContainExpr ∷ (HasCallStack, ToExpr a, Eq a, MonadIO m) ⇒ [a] → [a] → m () Source #
expectRight ∷ (HasCallStack, Show a, MonadIO m) ⇒ Either a b → m b Source #
Return value on the Right
and fail otherwise. Lifted version of expectRight
.
expectRightDeep_ ∷ (HasCallStack, Show a, NFData b, MonadIO m) ⇒ Either a b → m () Source #
Same as expectRightDeep
, but discards the result
expectRightDeep ∷ (HasCallStack, Show a, NFData b, MonadIO m) ⇒ Either a b → m b Source #
Same as expectRight
, but also evaluate the returned value to NF
expectRightExpr ∷ (HasCallStack, ToExpr a, MonadIO m) ⇒ Either a b → m b Source #
Same as expectRight
, but use ToExpr
instead of Show
expectRightDeepExpr ∷ (HasCallStack, ToExpr a, NFData b, MonadIO m) ⇒ Either a b → m b Source #
Same as expectRightDeep
, but use ToExpr
instead of Show
expectLeft ∷ (HasCallStack, Show b, MonadIO m) ⇒ Either a b → m a Source #
Return value on the Left
and fail otherwise
expectLeftDeep_ ∷ (HasCallStack, NFData a, Show b, MonadIO m) ⇒ Either a b → m () Source #
Same as expectLeftDeep
, but discards the result
expectLeftExpr ∷ (HasCallStack, ToExpr b, MonadIO m) ⇒ Either a b → m a Source #
Same as expectLeft
, but use ToExpr
instead of Show
expectLeftDeep ∷ (HasCallStack, NFData a, Show b, MonadIO m) ⇒ Either a b → m a Source #
Same as expectLeft
, but also evaluate the returned value to NF
expectLeftDeepExpr ∷ (HasCallStack, ToExpr b, NFData a, MonadIO m) ⇒ Either a b → m a Source #
Same as expectLeftDeep
, but use ToExpr
instead of Show
expectJust ∷ (HasCallStack, MonadIO m) ⇒ Maybe a → m a Source #
expectNothingExpr ∷ (HasCallStack, MonadIO m, ToExpr a) ⇒ Maybe a → m () Source #
MonadGen
module Test.QuickCheck.GenT
Random interface
class StatefulGen g m ⇒ HasStatefulGen g (m ∷ Type → Type) | m → g where Source #
Nothing
askStatefulGen ∷ m g Source #
Instances
(HasGenEnv env g, StatefulGen g (ReaderT env m), Monad m) ⇒ HasStatefulGen g (ReaderT env m) | |
Defined in Test.ImpSpec.Random askStatefulGen ∷ ReaderT env m g Source # | |
HasStatefulGen (IOGenM QCGen) (ImpM t) | |
Defined in Test.ImpSpec.Internal askStatefulGen ∷ ImpM t (IOGenM QCGen) Source # |
class Monad m ⇒ StatefulGen g (m ∷ Type → Type) Source #
StatefulGen
is an interface to monadic pseudo-random number generators.
Since: random-1.2.0
Instances
uniformM ∷ (HasStatefulGen g m, Uniform a) ⇒ m a Source #
uniformRM ∷ (HasStatefulGen g m, UniformRange a) ⇒ (a, a) → m a Source #
uniformListM ∷ (HasStatefulGen g m, Uniform a) ⇒ Int → m [a] Source #
uniformListRM ∷ (HasStatefulGen g m, UniformRange a) ⇒ (a, a) → Int → m [a] Source #
uniformByteStringM ∷ HasStatefulGen a m ⇒ Int → m ByteString Source #
uniformShortByteStringM ∷ HasStatefulGen a m ⇒ Int → m ShortByteString Source #
Re-exports from ImpSpec
Orphan instances
MonadUnliftIO m ⇒ MonadUnliftIO (GenT m) Source # | |