Safe Haskell | Safe-Inferred |
---|---|
Language | Haskell2010 |
Test.Massiv.Utils
Contents
Synopsis
- showsType :: forall t. Typeable t => ShowS
- showsArrayType :: forall r ix e. (Typeable r, Typeable ix, Typeable e) => ShowS
- assertDeepException :: (NFData a, Exception exc) => (exc -> Bool) -> a -> Property
- assertDeepExceptionIO :: (NFData a, Exception exc) => (exc -> Bool) -> IO a -> Property
- assertSomeException :: NFData a => a -> Property
- assertSomeExceptionIO :: NFData a => IO a -> Property
- toStringException :: Either SomeException a -> Either String a
- selectErrorCall :: ErrorCall -> Bool
- data ExpectedException = ExpectedException
- applyFun2Compat :: Fun (a, b) c -> a -> b -> c
- expectProp :: Expectation -> Property
- propIO :: Testable a => IO a -> Property
- specLaws :: HasCallStack => Laws -> Spec
- epsilonExpect :: (HasCallStack, Show a, RealFloat a) => a -> a -> a -> Expectation
- epsilonFoldableExpect :: (HasCallStack, Foldable f, Show (f e), Show e, RealFloat e) => e -> f e -> f e -> Expectation
- epsilonMaybeEq :: (Show a, RealFloat a) => a -> a -> a -> Maybe String
- epsilonEq :: (Show a, RealFloat a) => a -> a -> a -> Property
- epsilonEqDouble :: Double -> Double -> Property
- epsilonEqFloat :: Float -> Float -> Property
- 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 { }
- class Testable prop where
- data RealWorld
- data TyCon
- class Functor (f :: Type -> Type) where
- class Applicative m => Monad (m :: Type -> Type) where
- data Fun a b = Fun (a :-> b, b, Shrunk) (a -> b)
- data Gen a
- class CoArbitrary a where
- coarbitrary :: a -> Gen b -> Gen b
- 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 Arbitrary1 (f :: Type -> Type) where
- liftArbitrary :: Gen a -> Gen (f a)
- liftShrink :: (a -> [a]) -> f a -> [f a]
- class Arbitrary a where
- newtype PrintableString = PrintableString {}
- newtype UnicodeString = UnicodeString {}
- newtype ASCIIString = ASCIIString {}
- class ShrinkState s a where
- shrinkInit :: a -> s
- shrinkState :: a -> s -> [(a, s)]
- data Shrinking s a = Shrinking s a
- data Smart a = Smart Int a
- newtype Shrink2 a = Shrink2 {
- getShrink2 :: a
- newtype Small a = Small {
- getSmall :: a
- newtype Large a = Large {
- getLarge :: a
- newtype NonPositive a = NonPositive {
- getNonPositive :: a
- newtype NonNegative a = NonNegative {
- getNonNegative :: a
- newtype NonZero a = NonZero {
- getNonZero :: a
- newtype Negative a = Negative {
- getNegative :: a
- newtype Positive a = Positive {
- getPositive :: a
- newtype SortedList a = Sorted {
- getSorted :: [a]
- data InfiniteList a = InfiniteList {
- getInfiniteList :: [a]
- infiniteListInternalData :: InfiniteListInternalData a
- newtype NonEmptyList a = NonEmpty {
- getNonEmpty :: [a]
- newtype OrderedList a = Ordered {
- getOrdered :: [a]
- newtype Fixed a = Fixed {
- getFixed :: a
- newtype Blind a = Blind {
- getBlind :: a
- class Function a where
- data a :-> c
- data Confidence = Confidence {}
- data Witness = (Typeable a, Show a) => Wit a
- data Discard = Discard
- data Property
- data Args = Args {
- replay :: Maybe (QCGen, Int)
- maxSuccess :: Int
- maxDiscardRatio :: Int
- maxSize :: Int
- chatty :: Bool
- maxShrinks :: Int
- newtype PropertyM (m :: Type -> Type) a = MkPropertyM {
- unPropertyM :: (a -> Gen (m Property)) -> Gen (m Property)
- data ST s a
- type Selector a = a -> Bool
- class (Alternative m, Monad m) => MonadPlus (m :: Type -> Type) where
- class Typeable (a :: k)
- class Monad m => MonadFail (m :: Type -> Type) where
- type TypeRep = SomeTypeRep
- type HasCallStack = ?callStack :: CallStack
- data (a :: k1) :~~: (b :: k2) where
- data (a :: k) :~: (b :: k) where
- data Proxy (t :: k) = Proxy
- class Example e where
- type Arg e
- type family Arg e
- class NFData a
- type ActionWith a = a -> IO ()
- type SpecWith a = SpecM a ()
- type Spec = SpecWith ()
- type Expectation = Assertion
- data Laws = Laws {
- lawsTypeclass :: String
- lawsProperties :: [(String, Property)]
- data Proxy2 (f :: Type -> Type -> Type) = Proxy2
- data Proxy1 (f :: Type -> Type) = Proxy1
- pattern Fn3 :: (a -> b -> c -> d) -> Fun (a, b, c) d
- pattern Fn2 :: (a -> b -> c) -> Fun (a, b) c
- pattern Fn :: (a -> b) -> Fun a b
- deepseq :: NFData a => a -> b -> b
- hspec :: Spec -> IO ()
- vector :: Arbitrary a => Int -> Gen [a]
- assert :: forall (m :: Type -> Type). Monad m => Bool -> PropertyM m ()
- (==>) :: Testable prop => Bool -> prop -> Property
- join :: Monad m => m (m a) -> m a
- discard :: a
- variant :: Integral n => n -> Gen a -> Gen a
- sized :: (Int -> Gen a) -> Gen a
- getSize :: Gen Int
- resize :: HasCallStack => Int -> Gen a -> Gen a
- scale :: (Int -> Int) -> Gen a -> Gen a
- choose :: Random a => (a, a) -> Gen a
- chooseAny :: Random a => Gen a
- chooseEnum :: Enum a => (a, a) -> Gen a
- chooseInt :: (Int, Int) -> Gen Int
- chooseBoundedIntegral :: (Bounded a, Integral a) => (a, a) -> Gen a
- chooseInteger :: (Integer, Integer) -> Gen Integer
- generate :: Gen a -> IO a
- sample' :: Gen a -> IO [a]
- sample :: Show a => Gen a -> IO ()
- suchThat :: Gen a -> (a -> Bool) -> Gen a
- suchThatMap :: Gen a -> (a -> Maybe b) -> Gen b
- suchThatMaybe :: Gen a -> (a -> Bool) -> Gen (Maybe a)
- oneof :: HasCallStack => [Gen a] -> Gen a
- frequency :: HasCallStack => [(Int, Gen a)] -> Gen a
- elements :: HasCallStack => [a] -> Gen a
- sublistOf :: [a] -> Gen [a]
- shuffle :: [a] -> Gen [a]
- growingElements :: HasCallStack => [a] -> Gen a
- listOf :: Gen a -> Gen [a]
- listOf1 :: Gen a -> Gen [a]
- vectorOf :: Int -> Gen a -> Gen [a]
- infiniteListOf :: Gen a -> Gen [a]
- arbitrary1 :: (Arbitrary1 f, Arbitrary a) => Gen (f a)
- shrink1 :: (Arbitrary1 f, Arbitrary a) => f a -> [f a]
- arbitrary2 :: (Arbitrary2 f, Arbitrary a, Arbitrary b) => Gen (f a b)
- shrink2 :: (Arbitrary2 f, Arbitrary a, Arbitrary b) => f a b -> [f a b]
- genericShrink :: (Generic a, RecursivelyShrink (Rep a), GSubterms (Rep a) a) => a -> [a]
- recursivelyShrink :: (Generic a, RecursivelyShrink (Rep a)) => a -> [a]
- subterms :: (Generic a, GSubterms (Rep a) a) => a -> [a]
- shrinkList :: (a -> [a]) -> [a] -> [[a]]
- applyArbitrary2 :: (Arbitrary a, Arbitrary b) => (a -> b -> r) -> Gen r
- applyArbitrary3 :: (Arbitrary a, Arbitrary b, Arbitrary c) => (a -> b -> c -> r) -> Gen r
- applyArbitrary4 :: (Arbitrary a, Arbitrary b, Arbitrary c, Arbitrary d) => (a -> b -> c -> d -> r) -> Gen r
- arbitrarySizedIntegral :: Integral a => Gen a
- arbitrarySizedNatural :: Integral a => Gen a
- arbitrarySizedFractional :: Fractional a => Gen a
- arbitraryBoundedIntegral :: (Bounded a, Integral a) => Gen a
- arbitraryBoundedRandom :: (Bounded a, Random a) => Gen a
- arbitraryBoundedEnum :: (Bounded a, Enum a) => Gen a
- arbitrarySizedBoundedIntegral :: (Bounded a, Integral a) => Gen a
- arbitraryUnicodeChar :: Gen Char
- arbitraryASCIIChar :: Gen Char
- arbitraryPrintableChar :: Gen Char
- shrinkNothing :: a -> [a]
- shrinkMap :: Arbitrary a => (a -> b) -> (b -> a) -> b -> [b]
- shrinkMapBy :: (a -> b) -> (b -> a) -> (a -> [a]) -> b -> [b]
- shrinkIntegral :: Integral a => a -> [a]
- shrinkBoundedEnum :: (Bounded a, Enum a, Eq a) => a -> [a]
- shrinkRealFrac :: RealFrac a => a -> [a]
- shrinkDecimal :: RealFrac a => a -> [a]
- genericCoarbitrary :: (Generic a, GCoArbitrary (Rep a)) => a -> Gen b -> Gen b
- (><) :: (Gen a -> Gen a) -> (Gen a -> Gen a) -> Gen a -> Gen a
- coarbitraryIntegral :: Integral a => a -> Gen b -> Gen b
- coarbitraryReal :: Real a => a -> Gen b -> Gen b
- coarbitraryShow :: Show a => a -> Gen b -> Gen b
- coarbitraryEnum :: Enum a => a -> Gen b -> Gen b
- orderedList :: (Ord a, Arbitrary a) => Gen [a]
- infiniteList :: Arbitrary a => Gen [a]
- functionBoundedEnum :: (Eq a, Bounded a, Enum a) => (a -> b) -> a :-> b
- functionElements :: Eq a => [a] -> (a -> b) -> a :-> b
- functionRealFrac :: RealFrac a => (a -> b) -> a :-> b
- functionIntegral :: Integral a => (a -> b) -> a :-> b
- functionShow :: (Show a, Read a) => (a -> c) -> a :-> c
- functionVoid :: (forall b. void -> b) -> void :-> c
- functionMap :: Function b => (a -> b) -> (b -> a) -> (a -> c) -> a :-> c
- functionMapWith :: ((b -> c) -> b :-> c) -> (a -> b) -> (b -> a) -> (a -> c) -> a :-> c
- functionPairWith :: ((a -> b -> c) -> a :-> (b -> c)) -> ((b -> c) -> b :-> c) -> ((a, b) -> c) -> (a, b) :-> c
- functionEitherWith :: ((a -> c) -> a :-> c) -> ((b -> c) -> b :-> c) -> (Either a b -> c) -> Either a b :-> c
- apply :: Fun a b -> a -> b
- applyFun :: Fun a b -> a -> b
- applyFun2 :: Fun (a, b) c -> a -> b -> c
- applyFun3 :: Fun (a, b, c) d -> a -> b -> c -> d
- ioProperty :: Testable prop => IO prop -> Property
- idempotentIOProperty :: Testable prop => IO prop -> Property
- coerceWitness :: Typeable a => Witness -> a
- castWitness :: Typeable a => Witness -> Maybe a
- mapSize :: Testable prop => (Int -> Int) -> prop -> Property
- shrinking :: Testable prop => (a -> [a]) -> a -> (a -> prop) -> Property
- noShrinking :: Testable prop => prop -> Property
- counterexample :: Testable prop => String -> prop -> Property
- printTestCase :: Testable prop => String -> prop -> Property
- whenFail :: Testable prop => IO () -> prop -> Property
- whenFail' :: Testable prop => IO () -> prop -> Property
- verbose :: Testable prop => prop -> Property
- verboseShrinking :: Testable prop => prop -> Property
- expectFailure :: Testable prop => prop -> Property
- once :: Testable prop => prop -> Property
- again :: Testable prop => prop -> Property
- withMaxSuccess :: Testable prop => Int -> prop -> Property
- withDiscardRatio :: Testable prop => Int -> prop -> Property
- withMaxShrinks :: Testable prop => Int -> prop -> Property
- withMaxSize :: Testable prop => Int -> prop -> Property
- witness :: (Typeable a, Show a, Testable prop) => a -> prop -> Property
- checkCoverage :: Testable prop => prop -> Property
- checkCoverageWith :: Testable prop => Confidence -> prop -> Property
- stdConfidence :: Confidence
- label :: Testable prop => String -> prop -> Property
- collect :: (Show a, Testable prop) => a -> prop -> Property
- classify :: Testable prop => Bool -> String -> prop -> Property
- cover :: Testable prop => Double -> Bool -> String -> prop -> Property
- tabulate :: Testable prop => String -> [String] -> prop -> Property
- coverTable :: Testable prop => String -> [(String, Double)] -> prop -> Property
- within :: Testable prop => Int -> prop -> Property
- discardAfter :: Testable prop => Int -> prop -> Property
- forAll :: (Show a, Testable prop) => Gen a -> (a -> prop) -> Property
- forAllShow :: Testable prop => Gen a -> (a -> String) -> (a -> prop) -> Property
- forAllBlind :: Testable prop => Gen a -> (a -> prop) -> Property
- forAllShrink :: (Show a, Testable prop) => Gen a -> (a -> [a]) -> (a -> prop) -> Property
- forAllShrinkShow :: Testable prop => Gen a -> (a -> [a]) -> (a -> String) -> (a -> prop) -> Property
- forAllShrinkBlind :: Testable prop => Gen a -> (a -> [a]) -> (a -> prop) -> Property
- (.&&.) :: (Testable prop1, Testable prop2) => prop1 -> prop2 -> Property
- conjoin :: Testable prop => [prop] -> Property
- (.||.) :: (Testable prop1, Testable prop2) => prop1 -> prop2 -> Property
- disjoin :: Testable prop => [prop] -> Property
- (===) :: (Eq a, Show a) => a -> a -> Property
- (=/=) :: (Eq a, Show a) => a -> a -> Property
- total :: NFData a => a -> Property
- isSuccess :: Result -> Bool
- stdArgs :: Args
- quickCheck :: Testable prop => prop -> IO ()
- quickCheckWith :: Testable prop => Args -> prop -> IO ()
- quickCheckResult :: Testable prop => prop -> IO Result
- quickCheckWithResult :: Testable prop => Args -> prop -> IO Result
- recheck :: Testable prop => Result -> prop -> IO ()
- verboseCheck :: Testable prop => prop -> IO ()
- verboseCheckWith :: Testable prop => Args -> prop -> IO ()
- verboseCheckResult :: Testable prop => prop -> IO Result
- verboseCheckWithResult :: Testable prop => Args -> prop -> IO Result
- stop :: forall prop (m :: Type -> Type) a. (Testable prop, Monad m) => prop -> PropertyM m a
- assertWith :: forall (m :: Type -> Type). Monad m => Bool -> String -> PropertyM m ()
- pre :: forall (m :: Type -> Type). Monad m => Bool -> PropertyM m ()
- run :: Monad m => m a -> PropertyM m a
- pick :: forall (m :: Type -> Type) a. (Monad m, Show a) => Gen a -> PropertyM m a
- wp :: Monad m => m a -> (a -> PropertyM m b) -> PropertyM m b
- forAllM :: forall (m :: Type -> Type) a b. (Monad m, Show a) => Gen a -> (a -> PropertyM m b) -> PropertyM m b
- monitor :: forall (m :: Type -> Type). Monad m => (Property -> Property) -> PropertyM m ()
- monadic :: (Testable a, Monad m) => (m Property -> Property) -> PropertyM m a -> Property
- monadic' :: (Testable a, Monad m) => PropertyM m a -> Gen (m Property)
- monadicIO :: Testable a => PropertyM IO a -> Property
- monadicST :: Testable a => (forall s. PropertyM (ST s) a) -> Property
- runSTGen :: (forall s. Gen (ST s a)) -> Gen a
- assertException :: Exception exc => (exc -> Bool) -> a -> Property
- assertExceptionIO :: Exception exc => (exc -> Bool) -> IO a -> Property
- polyQuickCheck :: Name -> ExpQ
- polyVerboseCheck :: Name -> ExpQ
- monomorphic :: Name -> ExpQ
- forAllProperties :: Q Exp
- allProperties :: Q Exp
- quickCheckAll :: Q Exp
- verboseCheckAll :: Q Exp
- labelledExamples :: Testable prop => prop -> IO ()
- labelledExamplesWith :: Testable prop => Args -> prop -> IO ()
- labelledExamplesResult :: Testable prop => prop -> IO Result
- labelledExamplesWithResult :: Testable prop => Args -> prop -> IO Result
- mapM_ :: (Foldable t, Monad m) => (a -> m b) -> t a -> m ()
- forM_ :: (Foldable t, Monad m) => t a -> (a -> m b) -> m ()
- stToIO :: ST RealWorld a -> IO a
- mapM :: (Traversable t, Monad m) => (a -> m b) -> t a -> m (t b)
- sequence :: (Traversable t, Monad m) => t (m a) -> m (t a)
- forM :: (Traversable t, Monad m) => t a -> (a -> m b) -> m (t b)
- forever :: Applicative f => f a -> f b
- liftM :: Monad m => (a1 -> r) -> m a1 -> m r
- guard :: Alternative f => Bool -> f ()
- (=<<) :: Monad m => (a -> m b) -> m a -> m b
- when :: Applicative f => Bool -> f () -> f ()
- liftM2 :: Monad m => (a1 -> a2 -> r) -> m a1 -> m a2 -> m r
- liftM3 :: Monad m => (a1 -> a2 -> a3 -> r) -> m a1 -> m a2 -> m a3 -> m r
- liftM4 :: Monad m => (a1 -> a2 -> a3 -> a4 -> r) -> m a1 -> m a2 -> m a3 -> m a4 -> m r
- liftM5 :: Monad m => (a1 -> a2 -> a3 -> a4 -> a5 -> r) -> m a1 -> m a2 -> m a3 -> m a4 -> m a5 -> m r
- ap :: Monad m => m (a -> b) -> m a -> m b
- isJust :: Maybe a -> Bool
- isNothing :: Maybe a -> Bool
- fromMaybe :: a -> Maybe a -> a
- runST :: (forall s. ST s a) -> a
- void :: Functor f => f a -> f ()
- sequence_ :: (Foldable t, Monad m) => t (m a) -> m ()
- msum :: (Foldable t, MonadPlus m) => t (m a) -> m a
- tyConPackage :: TyCon -> String
- tyConModule :: TyCon -> String
- tyConName :: TyCon -> String
- tyConFingerprint :: TyCon -> Fingerprint
- rnfTyCon :: TyCon -> ()
- typeRepFingerprint :: TypeRep -> Fingerprint
- trLiftedRep :: TypeRep LiftedRep
- typeRepTyCon :: TypeRep -> TyCon
- typeRep :: forall {k} proxy (a :: k). Typeable a => proxy a -> TypeRep
- typeOf :: Typeable a => a -> TypeRep
- rnfTypeRep :: TypeRep -> ()
- showsTypeRep :: TypeRep -> ShowS
- cast :: (Typeable a, Typeable b) => a -> Maybe b
- eqT :: forall {k} (a :: k) (b :: k). (Typeable a, Typeable b) => Maybe (a :~: b)
- heqT :: forall {k1} {k2} (a :: k1) (b :: k2). (Typeable a, Typeable b) => Maybe (a :~~: b)
- gcast :: forall {k} (a :: k) (b :: k) c. (Typeable a, Typeable b) => c a -> Maybe (c b)
- gcast1 :: forall {k1} {k2} c (t :: k2 -> k1) (t' :: k2 -> k1) (a :: k2). (Typeable t, Typeable t') => c (t a) -> Maybe (c (t' a))
- gcast2 :: forall {k1} {k2} {k3} c (t :: k2 -> k3 -> k1) (t' :: k2 -> k3 -> k1) (a :: k2) (b :: k3). (Typeable t, Typeable t') => c (t a b) -> Maybe (c (t' a b))
- funResultTy :: TypeRep -> TypeRep -> Maybe TypeRep
- mkFunTy :: TypeRep -> TypeRep -> TypeRep
- splitTyConApp :: TypeRep -> (TyCon, [TypeRep])
- typeRepArgs :: TypeRep -> [TypeRep]
- typeOf1 :: Typeable t => t a -> TypeRep
- typeOf2 :: Typeable t => t a b -> TypeRep
- typeOf3 :: Typeable t => t a b c -> TypeRep
- typeOf4 :: Typeable t => t a b c d -> TypeRep
- typeOf5 :: Typeable t => t a b c d e -> TypeRep
- typeOf6 :: Typeable t => t a b c d e f -> TypeRep
- typeOf7 :: Typeable t => t a b c d e f g -> TypeRep
- fixST :: (a -> ST s a) -> ST s a
- filterM :: Applicative m => (a -> m Bool) -> [a] -> m [a]
- (>=>) :: Monad m => (a -> m b) -> (b -> m c) -> a -> m c
- (<=<) :: Monad m => (b -> m c) -> (a -> m b) -> a -> m c
- mapAndUnzipM :: Applicative m => (a -> m (b, c)) -> [a] -> m ([b], [c])
- zipWithM :: Applicative m => (a -> b -> m c) -> [a] -> [b] -> m [c]
- zipWithM_ :: Applicative m => (a -> b -> m c) -> [a] -> [b] -> m ()
- foldM :: (Foldable t, Monad m) => (b -> a -> m b) -> b -> t a -> m b
- foldM_ :: (Foldable t, Monad m) => (b -> a -> m b) -> b -> t a -> m ()
- replicateM :: Applicative m => Int -> m a -> m [a]
- replicateM_ :: Applicative m => Int -> m a -> m ()
- unless :: Applicative f => Bool -> f () -> f ()
- (<$!>) :: Monad m => (a -> b) -> m a -> m b
- mfilter :: MonadPlus m => (a -> Bool) -> m a -> m a
- 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
- describe :: HasCallStack => String -> SpecWith a -> SpecWith a
- context :: HasCallStack => String -> SpecWith a -> SpecWith a
- xdescribe :: HasCallStack => String -> SpecWith a -> SpecWith a
- xcontext :: HasCallStack => String -> SpecWith a -> SpecWith a
- it :: (HasCallStack, Example a) => String -> a -> SpecWith (Arg a)
- specify :: (HasCallStack, Example a) => String -> a -> SpecWith (Arg a)
- xit :: (HasCallStack, Example a) => String -> a -> SpecWith (Arg a)
- xspecify :: (HasCallStack, Example a) => String -> a -> SpecWith (Arg a)
- focus :: SpecWith a -> SpecWith a
- fit :: (HasCallStack, Example a) => String -> a -> SpecWith (Arg a)
- fspecify :: (HasCallStack, Example a) => String -> a -> SpecWith (Arg a)
- fdescribe :: HasCallStack => String -> SpecWith a -> SpecWith 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
- example :: Expectation -> Expectation
- prop :: (HasCallStack, Testable prop) => String -> prop -> Spec
- xprop :: (HasCallStack, Testable prop) => String -> prop -> Spec
- fprop :: (HasCallStack, Testable prop) => String -> prop -> Spec
- expectationFailure :: HasCallStack => String -> Expectation
- shouldBe :: (HasCallStack, Show a, Eq a) => a -> a -> Expectation
- shouldSatisfy :: (HasCallStack, Show a) => a -> (a -> Bool) -> Expectation
- shouldStartWith :: (HasCallStack, Show a, Eq a) => [a] -> [a] -> Expectation
- shouldEndWith :: (HasCallStack, Show a, Eq a) => [a] -> [a] -> Expectation
- shouldContain :: (HasCallStack, Show a, Eq a) => [a] -> [a] -> Expectation
- shouldMatchList :: (HasCallStack, Show a, Eq a) => [a] -> [a] -> Expectation
- shouldReturn :: (HasCallStack, Show a, Eq a) => IO a -> a -> Expectation
- shouldNotBe :: (HasCallStack, Show a, Eq a) => a -> a -> Expectation
- shouldNotSatisfy :: (HasCallStack, Show a) => a -> (a -> Bool) -> Expectation
- shouldNotContain :: (HasCallStack, Show a, Eq a) => [a] -> [a] -> Expectation
- shouldNotReturn :: (HasCallStack, Show a, Eq a) => IO a -> a -> Expectation
- shouldThrow :: (HasCallStack, Exception e) => IO a -> Selector e -> Expectation
- anyException :: Selector SomeException
- anyErrorCall :: Selector ErrorCall
- errorCall :: String -> Selector ErrorCall
- anyIOException :: Selector IOException
- anyArithException :: Selector ArithException
- integralLaws :: (Integral a, Arbitrary a, Show a) => Proxy a -> Laws
- genericLaws :: (Generic a, Eq a, Arbitrary a, Show a, Show (Rep a ()), Arbitrary (Rep a ()), Eq (Rep a ())) => Proxy a -> Laws
- generic1Laws :: forall (f :: Type -> Type) proxy. (Generic1 f, Eq1 f, Arbitrary1 f, Show1 f, Eq1 (Rep1 f), Show1 (Rep1 f), Arbitrary1 (Rep1 f)) => proxy f -> Laws
- functorLaws :: forall (f :: Type -> Type) proxy. (Functor f, forall a. Eq a => Eq (f a), forall a. Show a => Show (f a), forall a. Arbitrary a => Arbitrary (f a)) => proxy f -> Laws
- foldableLaws :: forall proxy (f :: Type -> Type). (Foldable f, forall a. Eq a => Eq (f a), forall a. Show a => Show (f a), forall a. Arbitrary a => Arbitrary (f a)) => proxy f -> Laws
- eqLaws :: (Eq a, Arbitrary a, Show a) => Proxy a -> Laws
- substitutiveEqLaws :: (Eq a, Arbitrary a, CoArbitrary a, Function a, Show a) => Proxy a -> Laws
- enumLaws :: (Enum a, Eq a, Arbitrary a, Show a) => Proxy a -> Laws
- boundedEnumLaws :: (Enum a, Bounded a, Eq a, Arbitrary a, Show a) => Proxy a -> Laws
- contravariantLaws :: forall (f :: Type -> Type) proxy. (Contravariant f, forall a. Eq a => Eq (f a), forall a. Show a => Show (f a), forall a. Arbitrary a => Arbitrary (f a)) => proxy f -> Laws
- categoryLaws :: forall proxy (c :: Type -> Type -> Type). (Category c, forall a b. (Eq a, Eq b) => Eq (c a b), forall a b. (Show a, Show b) => Show (c a b), forall a b. (Arbitrary a, Arbitrary b) => Arbitrary (c a b)) => proxy c -> Laws
- commutativeCategoryLaws :: forall proxy (c :: Type -> Type -> Type). (Category c, forall a b. (Eq a, Eq b) => Eq (c a b), forall a b. (Show a, Show b) => Show (c a b), forall a b. (Arbitrary a, Arbitrary b) => Arbitrary (c a b)) => proxy c -> Laws
- bitsLaws :: (FiniteBits a, Arbitrary a, Show a) => Proxy a -> Laws
- bitraversableLaws :: forall proxy (f :: Type -> Type -> Type). (Bitraversable f, forall a b. (Eq a, Eq b) => Eq (f a b), forall a b. (Show a, Show b) => Show (f a b), forall a b. (Arbitrary a, Arbitrary b) => Arbitrary (f a b)) => proxy f -> Laws
- bifunctorLaws :: forall proxy (f :: Type -> Type -> Type). (Bifunctor f, forall a b. (Eq a, Eq b) => Eq (f a b), forall a b. (Show a, Show b) => Show (f a b), forall a b. (Arbitrary a, Arbitrary b) => Arbitrary (f a b)) => proxy f -> Laws
- bifoldableLaws :: forall proxy (f :: Type -> Type -> Type). (Bifoldable f, forall a b. (Eq a, Eq b) => Eq (f a b), forall a b. (Show a, Show b) => Show (f a b), forall a b. (Arbitrary a, Arbitrary b) => Arbitrary (f a b)) => proxy f -> Laws
- isListLaws :: (IsList a, Show a, Show (Item a), Arbitrary a, Arbitrary (Item a), Eq a) => Proxy a -> Laws
- applicativeLaws :: forall (f :: Type -> Type) proxy. (Applicative f, forall a. Eq a => Eq (f a), forall a. Show a => Show (f a), forall a. Arbitrary a => Arbitrary (f a)) => proxy f -> Laws
- alternativeLaws :: forall (f :: Type -> Type) proxy. (Alternative f, forall a. Eq a => Eq (f a), forall a. Show a => Show (f a), forall a. Arbitrary a => Arbitrary (f a)) => proxy f -> Laws
- ixLaws :: (Ix a, Arbitrary a, Show a) => Proxy a -> Laws
- monadLaws :: forall (f :: Type -> Type) proxy. (Monad f, Applicative f, forall a. Eq a => Eq (f a), forall a. Show a => Show (f a), forall a. Arbitrary a => Arbitrary (f a)) => proxy f -> Laws
- monadPlusLaws :: forall (f :: Type -> Type) proxy. (MonadPlus f, forall a. Eq a => Eq (f a), forall a. Show a => Show (f a), forall a. Arbitrary a => Arbitrary (f a)) => proxy f -> Laws
- monadZipLaws :: forall (f :: Type -> Type) proxy. (MonadZip f, forall a. Eq a => Eq (f a), forall a. Show a => Show (f a), forall a. Arbitrary a => Arbitrary (f a)) => proxy f -> Laws
- monoidLaws :: (Monoid a, Eq a, Arbitrary a, Show a) => Proxy a -> Laws
- commutativeMonoidLaws :: (Monoid a, Eq a, Arbitrary a, Show a) => Proxy a -> Laws
- semigroupMonoidLaws :: (Semigroup a, Monoid a, Eq a, Arbitrary a, Show a) => Proxy a -> Laws
- numLaws :: (Num a, Eq a, Arbitrary a, Show a) => Proxy a -> Laws
- ordLaws :: (Ord a, Arbitrary a, Show a) => Proxy a -> Laws
- semigroupLaws :: (Semigroup a, Eq a, Arbitrary a, Show a) => Proxy a -> Laws
- commutativeSemigroupLaws :: (Semigroup a, Eq a, Arbitrary a, Show a) => Proxy a -> Laws
- idempotentSemigroupLaws :: (Semigroup a, Eq a, Arbitrary a, Show a) => Proxy a -> Laws
- rectangularBandSemigroupLaws :: (Semigroup a, Eq a, Arbitrary a, Show a) => Proxy a -> Laws
- exponentialSemigroupLaws :: (Semigroup a, Eq a, Arbitrary a, Show a) => Proxy a -> Laws
- showLaws :: (Show a, Arbitrary a) => Proxy a -> Laws
- showReadLaws :: (Show a, Read a, Eq a, Arbitrary a) => Proxy a -> Laws
- storableLaws :: (Storable a, Eq a, Arbitrary a, Show a) => Proxy a -> Laws
- traversableLaws :: forall (f :: Type -> Type) proxy. (Traversable f, forall a. Eq a => Eq (f a), forall a. Show a => Show (f a), forall a. Arbitrary a => Arbitrary (f a)) => proxy f -> Laws
- lawsCheck :: Laws -> IO ()
- lawsCheckOne :: Proxy a -> [Proxy a -> Laws] -> IO ()
- lawsCheckMany :: [(String, [Laws])] -> IO ()
Documentation
showsArrayType :: forall r ix e. (Typeable r, Typeable ix, Typeable e) => ShowS Source #
Use Typeable to show the array type
Arguments
:: (NFData a, Exception exc) | |
=> (exc -> Bool) | Return True if that is the exception that was expected |
-> a | Value that should result in an exception, when fully evaluated to NF |
-> Property |
Same as assertException
, but evaluate the value to Normal Form (NF) and fail if it
does not result in an expected exception being thrown.
Arguments
:: (NFData a, Exception exc) | |
=> (exc -> Bool) | Return True if that is the exception that was expected |
-> IO a | An action that should throw the expected exception |
-> Property |
Make sure that a specific exception is thrown during an IO action. The result is evaluated to NF.
assertSomeException :: NFData a => a -> Property Source #
toStringException :: Either SomeException a -> Either String a Source #
selectErrorCall :: ErrorCall -> Bool Source #
data ExpectedException Source #
Constructors
ExpectedException |
Instances
Exception ExpectedException Source # | |
Defined in Test.Massiv.Utils Methods toException :: ExpectedException -> SomeException # | |
Show ExpectedException Source # | |
Defined in Test.Massiv.Utils Methods showsPrec :: Int -> ExpectedException -> ShowS # show :: ExpectedException -> String # showList :: [ExpectedException] -> ShowS # | |
Eq ExpectedException Source # | |
Defined in Test.Massiv.Utils Methods (==) :: ExpectedException -> ExpectedException -> Bool # (/=) :: ExpectedException -> ExpectedException -> Bool # |
applyFun2Compat :: Fun (a, b) c -> a -> b -> c Source #
expectProp :: Expectation -> Property Source #
Convert an hspec Expectation to a quickcheck Property.
Since: 1.5.0
propIO :: Testable a => IO a -> Property Source #
Convert a Testable to a quickcheck Property. Works well with hspec expectations as well
Since: 1.7.0
Epsilon comparison
Arguments
:: (HasCallStack, Show a, RealFloat a) | |
=> a | Epsilon, a maximum tolerated error. Sign is ignored. |
-> a | Expected result. |
-> a | Tested value. |
-> Expectation |
epsilonFoldableExpect :: (HasCallStack, Foldable f, Show (f e), Show e, RealFloat e) => e -> f e -> f e -> Expectation Source #
Result represents the test result
Constructors
Success | A successful test run |
Fields
| |
GaveUp | Given up |
Fields
| |
Failure | A failed test run |
Fields
| |
NoExpectedFailure | A property that should have failed did not |
Fields
|
The class of properties, i.e., types which QuickCheck knows how to test.
Typically a property will be a function returning Bool
or Property
.
Minimal complete definition
Methods
property :: prop -> Property #
Convert the thing to a property.
propertyForAllShrinkShow :: Gen a -> (a -> [a]) -> (a -> [String]) -> (a -> prop) -> Property #
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.
Instances
Testable Discard | |
Testable Prop | |
Defined in Test.QuickCheck.Property | |
Testable Property | |
Testable Result | |
Defined in Test.QuickCheck.Property | |
Testable () | |
Defined in Test.QuickCheck.Property | |
Testable Bool | |
Testable prop => Testable (Gen prop) | |
Testable prop => Testable (Maybe prop) | |
(Arbitrary a, Show a, Testable prop) => Testable (a -> prop) | |
Defined in Test.QuickCheck.Property |
class Functor (f :: Type -> Type) where #
A type f
is a Functor if it provides a function fmap
which, given any types a
and b
lets you apply any function from (a -> b)
to turn an f a
into an f b
, preserving the
structure of f
. Furthermore f
needs to adhere to the following:
Note, that the second law follows from the free theorem of the type fmap
and
the first law, so you need only check that the former condition holds.
See https://www.schoolofhaskell.com/user/edwardk/snippets/fmap or
https://github.com/quchen/articles/blob/master/second_functor_law.md
for an explanation.
Minimal complete definition
Methods
fmap :: (a -> b) -> f a -> f b #
fmap
is used to apply a function of type (a -> b)
to a value of type f a
,
where f is a functor, to produce a value of type f b
.
Note that for any type constructor with more than one parameter (e.g., Either
),
only the last type parameter can be modified with fmap
(e.g., b
in `Either a b`).
Some type constructors with two parameters or more have a
instance that allows
both the last and the penultimate parameters to be mapped over.Bifunctor
Examples
Convert from a
to a Maybe
IntMaybe String
using show
:
>>>
fmap show Nothing
Nothing>>>
fmap show (Just 3)
Just "3"
Convert from an
to an
Either
Int IntEither Int String
using show
:
>>>
fmap show (Left 17)
Left 17>>>
fmap show (Right 17)
Right "17"
Double each element of a list:
>>>
fmap (*2) [1,2,3]
[2,4,6]
Apply even
to the second element of a pair:
>>>
fmap even (2,2)
(2,True)
It may seem surprising that the function is only applied to the last element of the tuple
compared to the list example above which applies it to every element in the list.
To understand, remember that tuples are type constructors with multiple type parameters:
a tuple of 3 elements (a,b,c)
can also be written (,,) a b c
and its Functor
instance
is defined for Functor ((,,) a b)
(i.e., only the third parameter is free to be mapped over
with fmap
).
It explains why fmap
can be used with tuples containing values of different types as in the
following example:
>>>
fmap even ("hello", 1.0, 4)
("hello",1.0,True)
Instances
class Applicative m => Monad (m :: Type -> Type) where #
The Monad
class defines the basic operations over a monad,
a concept from a branch of mathematics known as category theory.
From the perspective of a Haskell programmer, however, it is best to
think of a monad as an abstract datatype of actions.
Haskell's do
expressions provide a convenient syntax for writing
monadic expressions.
Instances of Monad
should satisfy the following:
- Left identity
return
a>>=
k = k a- Right identity
m
>>=
return
= m- Associativity
m
>>=
(\x -> k x>>=
h) = (m>>=
k)>>=
h
Furthermore, the Monad
and Applicative
operations should relate as follows:
The above laws imply:
and that pure
and (<*>
) satisfy the applicative functor laws.
The instances of Monad
for lists, Maybe
and IO
defined in the Prelude satisfy these laws.
Minimal complete definition
Methods
(>>=) :: m a -> (a -> m b) -> m b infixl 1 #
Sequentially compose two actions, passing any value produced by the first as an argument to the second.
'as
' can be understood as the >>=
bsdo
expression
do a <- as bs a
(>>) :: m a -> m b -> m b infixl 1 #
Sequentially compose two actions, discarding any value produced by the first, like sequencing operators (such as the semicolon) in imperative languages.
'as
' can be understood as the >>
bsdo
expression
do as bs
Inject a value into the monadic type.
Instances
Monad Gen | |
Monad Rose | |
Monad Identity | Since: base-4.8.0.0 |
Monad NonEmpty | Since: base-4.9.0.0 |
Monad Par1 | Since: base-4.9.0.0 |
Monad P | Since: base-2.1 |
Monad ReadP | Since: base-2.1 |
Monad Seq | |
Monad Tree | |
Monad IO | Since: base-2.1 |
Monad Array | |
Monad SmallArray | |
Defined in Data.Primitive.SmallArray Methods (>>=) :: SmallArray a -> (a -> SmallArray b) -> SmallArray b # (>>) :: SmallArray a -> SmallArray b -> SmallArray b # return :: a -> SmallArray a # | |
Monad Q | |
Monad Vector | |
Monad Id | |
Monad Vector | |
Monad Box | |
Monad Maybe | Since: base-2.1 |
Monad Solo | Since: base-4.15 |
Monad List | Since: base-2.1 |
Monad m => Monad (PropertyM m) | |
Monad (Either e) | Since: base-4.4.0.0 |
Monad (Proxy :: Type -> Type) | Since: base-4.7.0.0 |
Monad (U1 :: Type -> Type) | Since: base-4.9.0.0 |
Monad (ST s) | Since: base-2.1 |
Monad (SpecM a) | |
Monoid a => Monad ((,) a) | Since: base-4.9.0.0 |
Monad f => Monad (Rec1 f) | Since: base-4.9.0.0 |
(Applicative f, Monad f) => Monad (WhenMissing f x) | Equivalent to Since: containers-0.5.9 |
Defined in Data.IntMap.Internal Methods (>>=) :: WhenMissing f x a -> (a -> WhenMissing f x b) -> WhenMissing f x b # (>>) :: WhenMissing f x a -> WhenMissing f x b -> WhenMissing f x b # return :: a -> WhenMissing f x a # | |
Monad (Array DS Ix1) | |
(Monoid w, Functor m, Monad m) => Monad (AccumT w m) | |
Monad m => Monad (SelectT r m) | |
Monad m => Monad (WriterT w m) | |
(Monoid a, Monoid b) => Monad ((,,) a b) | Since: base-4.14.0.0 |
(Monad f, Monad g) => Monad (f :*: g) | Since: base-4.9.0.0 |
(Monad f, Applicative f) => Monad (WhenMatched f x y) | Equivalent to Since: containers-0.5.9 |
Defined in Data.IntMap.Internal Methods (>>=) :: WhenMatched f x y a -> (a -> WhenMatched f x y b) -> WhenMatched f x y b # (>>) :: WhenMatched f x y a -> WhenMatched f x y b -> WhenMatched f x y b # return :: a -> WhenMatched f x y a # | |
(Applicative f, Monad f) => Monad (WhenMissing f k x) | Equivalent to Since: containers-0.5.9 |
Defined in Data.Map.Internal Methods (>>=) :: WhenMissing f k x a -> (a -> WhenMissing f k x b) -> WhenMissing f k x b # (>>) :: WhenMissing f k x a -> WhenMissing f k x b -> WhenMissing f k x b # return :: a -> WhenMissing f k x a # | |
(Monoid a, Monoid b, Monoid c) => Monad ((,,,) a b c) | Since: base-4.14.0.0 |
Monad ((->) r) | Since: base-2.1 |
Monad f => Monad (M1 i c f) | Since: base-4.9.0.0 |
(Monad f, Applicative f) => Monad (WhenMatched f k x y) | Equivalent to Since: containers-0.5.9 |
Defined in Data.Map.Internal Methods (>>=) :: WhenMatched f k x y a -> (a -> WhenMatched f k x y b) -> WhenMatched f k x y b # (>>) :: WhenMatched f k x y a -> WhenMatched f k x y b -> WhenMatched f k x y b # return :: a -> WhenMatched f k x y a # | |
Monad m => Monad (RWST r w s m) | |
Generation of random shrinkable, showable functions.
To generate random values of type
,
you must have an instance Fun
a b
.Function
a
A generator for values of type a
.
The third-party packages
QuickCheck-GenT
and
quickcheck-transformer
provide monad transformer versions of Gen
.
class CoArbitrary a where #
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)
.
Minimal complete definition
Nothing
Methods
coarbitrary :: a -> Gen b -> Gen b #
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
class Arbitrary2 (f :: Type -> Type -> Type) where #
Lifting of the Arbitrary
class to binary type constructors.
Minimal complete definition
Methods
liftArbitrary2 :: Gen a -> Gen b -> Gen (f a b) #
liftShrink2 :: (a -> [a]) -> (b -> [b]) -> f a b -> [f a b] #
Instances
Arbitrary2 Either | |
Defined in Test.QuickCheck.Arbitrary Methods liftArbitrary2 :: Gen a -> Gen b -> Gen (Either a b) # liftShrink2 :: (a -> [a]) -> (b -> [b]) -> Either a b -> [Either a b] # | |
Arbitrary2 (,) | |
Defined in Test.QuickCheck.Arbitrary Methods liftArbitrary2 :: Gen a -> Gen b -> Gen (a, b) # liftShrink2 :: (a -> [a]) -> (b -> [b]) -> (a, b) -> [(a, b)] # | |
Arbitrary2 (Const :: Type -> Type -> Type) | |
Defined in Test.QuickCheck.Arbitrary Methods liftArbitrary2 :: Gen a -> Gen b -> Gen (Const a b) # liftShrink2 :: (a -> [a]) -> (b -> [b]) -> Const a b -> [Const a b] # | |
Arbitrary2 (Constant :: Type -> Type -> Type) | |
Defined in Test.QuickCheck.Arbitrary Methods liftArbitrary2 :: Gen a -> Gen b -> Gen (Constant a b) # liftShrink2 :: (a -> [a]) -> (b -> [b]) -> Constant a b -> [Constant a b] # |
class Arbitrary1 (f :: Type -> Type) where #
Lifting of the Arbitrary
class to unary type constructors.
Minimal complete definition
Instances
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.
Minimal complete definition
Methods
A generator for values of the given type.
It is worth spending time thinking about what sort of test data
you want - good generators are often the difference between
finding bugs and not finding them. You can use sample
,
label
and classify
to check the quality of your test data.
There is no generic arbitrary
implementation included because we don't
know how to make a high-quality one. If you want one, consider using the
testing-feat or
generic-random packages.
The QuickCheck manual goes into detail on how to write good generators. Make sure to look at it, especially if your type is recursive!
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
newtype PrintableString #
PrintableString
: generates a printable unicode String.
The string will not contain surrogate pairs.
Constructors
PrintableString | |
Fields |
Instances
newtype UnicodeString #
UnicodeString
: generates a unicode String.
The string will not contain surrogate pairs.
Constructors
UnicodeString | |
Fields |
Instances
Arbitrary UnicodeString | |
Defined in Test.QuickCheck.Modifiers | |
Read UnicodeString | |
Defined in Test.QuickCheck.Modifiers Methods readsPrec :: Int -> ReadS UnicodeString # readList :: ReadS [UnicodeString] # | |
Show UnicodeString | |
Defined in Test.QuickCheck.Modifiers Methods showsPrec :: Int -> UnicodeString -> ShowS # show :: UnicodeString -> String # showList :: [UnicodeString] -> ShowS # | |
Eq UnicodeString | |
Defined in Test.QuickCheck.Modifiers Methods (==) :: UnicodeString -> UnicodeString -> Bool # (/=) :: UnicodeString -> UnicodeString -> Bool # | |
Ord UnicodeString | |
Defined in Test.QuickCheck.Modifiers Methods compare :: UnicodeString -> UnicodeString -> Ordering # (<) :: UnicodeString -> UnicodeString -> Bool # (<=) :: UnicodeString -> UnicodeString -> Bool # (>) :: UnicodeString -> UnicodeString -> Bool # (>=) :: UnicodeString -> UnicodeString -> Bool # max :: UnicodeString -> UnicodeString -> UnicodeString # min :: UnicodeString -> UnicodeString -> UnicodeString # |
newtype ASCIIString #
ASCIIString
: generates an ASCII string.
Constructors
ASCIIString | |
Fields |
Instances
Arbitrary ASCIIString | |
Defined in Test.QuickCheck.Modifiers | |
Read ASCIIString | |
Defined in Test.QuickCheck.Modifiers Methods readsPrec :: Int -> ReadS ASCIIString # readList :: ReadS [ASCIIString] # readPrec :: ReadPrec ASCIIString # readListPrec :: ReadPrec [ASCIIString] # | |
Show ASCIIString | |
Defined in Test.QuickCheck.Modifiers Methods showsPrec :: Int -> ASCIIString -> ShowS # show :: ASCIIString -> String # showList :: [ASCIIString] -> ShowS # | |
Eq ASCIIString | |
Defined in Test.QuickCheck.Modifiers | |
Ord ASCIIString | |
Defined in Test.QuickCheck.Modifiers Methods compare :: ASCIIString -> ASCIIString -> Ordering # (<) :: ASCIIString -> ASCIIString -> Bool # (<=) :: ASCIIString -> ASCIIString -> Bool # (>) :: ASCIIString -> ASCIIString -> Bool # (>=) :: ASCIIString -> ASCIIString -> Bool # max :: ASCIIString -> ASCIIString -> ASCIIString # min :: ASCIIString -> ASCIIString -> ASCIIString # |
class ShrinkState s a where #
Shrinking _ x
: allows for maintaining a state during shrinking.
Constructors
Shrinking s a |
Smart _ x
: tries a different order when shrinking.
Shrink2 x
: allows 2 shrinking steps at the same time when shrinking x
Constructors
Shrink2 | |
Fields
|
Instances
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) | |
Ix a => Ix (Small a) | |
Defined in Test.QuickCheck.Modifiers | |
Num a => Num (Small a) | |
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 Methods toRational :: Small a -> Rational # | |
Show a => Show (Small a) | |
Eq a => Eq (Small a) | |
Ord a => Ord (Small a) | |
Defined in Test.QuickCheck.Modifiers |
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) | |
Ix a => Ix (Large a) | |
Defined in Test.QuickCheck.Modifiers | |
Num a => Num (Large a) | |
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 Methods toRational :: Large a -> Rational # | |
Show a => Show (Large a) | |
Eq a => Eq (Large a) | |
Ord a => Ord (Large a) | |
Defined in Test.QuickCheck.Modifiers |
newtype NonPositive a #
NonPositive x
: guarantees that x <= 0
.
Constructors
NonPositive | |
Fields
|
Instances
newtype NonNegative a #
NonNegative x
: guarantees that x >= 0
.
Constructors
NonNegative | |
Fields
|
Instances
NonZero x
: guarantees that x /= 0
.
Constructors
NonZero | |
Fields
|
Instances
Functor NonZero | |
(Num a, Eq a, Arbitrary a) => Arbitrary (NonZero a) | |
Enum a => Enum (NonZero a) | |
Defined in Test.QuickCheck.Modifiers Methods succ :: NonZero a -> NonZero a # pred :: NonZero a -> NonZero a # fromEnum :: NonZero a -> Int # enumFrom :: NonZero a -> [NonZero a] # enumFromThen :: NonZero a -> NonZero a -> [NonZero a] # enumFromTo :: NonZero a -> NonZero a -> [NonZero a] # enumFromThenTo :: NonZero a -> NonZero a -> NonZero a -> [NonZero a] # | |
Read a => Read (NonZero a) | |
Show a => Show (NonZero a) | |
Eq a => Eq (NonZero a) | |
Ord a => Ord (NonZero a) | |
Negative x
: guarantees that x < 0
.
Constructors
Negative | |
Fields
|
Instances
Functor Negative | |
(Num a, Ord a, Arbitrary a) => Arbitrary (Negative a) | |
Enum a => Enum (Negative a) | |
Defined in Test.QuickCheck.Modifiers Methods succ :: Negative a -> Negative a # pred :: Negative a -> Negative a # fromEnum :: Negative a -> Int # enumFrom :: Negative a -> [Negative a] # enumFromThen :: Negative a -> Negative a -> [Negative a] # enumFromTo :: Negative a -> Negative a -> [Negative a] # enumFromThenTo :: Negative a -> Negative a -> Negative a -> [Negative a] # | |
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 |
Positive x
: guarantees that x > 0
.
Constructors
Positive | |
Fields
|
Instances
Functor Positive | |
(Num a, Ord a, Arbitrary a) => Arbitrary (Positive a) | |
Enum a => Enum (Positive a) | |
Defined in Test.QuickCheck.Modifiers Methods succ :: Positive a -> Positive a # pred :: Positive a -> Positive a # fromEnum :: Positive a -> Int # enumFrom :: Positive a -> [Positive a] # enumFromThen :: Positive a -> Positive a -> [Positive a] # enumFromTo :: Positive a -> Positive a -> [Positive a] # enumFromThenTo :: Positive a -> Positive a -> Positive a -> [Positive a] # | |
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 |
newtype SortedList a #
Sorted xs
: guarantees that xs is sorted.
Instances
data InfiniteList a #
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" ++ ...
Constructors
InfiniteList | |
Fields
|
Instances
Arbitrary a => Arbitrary (InfiniteList a) | |
Defined in Test.QuickCheck.Modifiers | |
Show a => Show (InfiniteList a) | |
Defined in Test.QuickCheck.Modifiers Methods showsPrec :: Int -> InfiniteList a -> ShowS # show :: InfiniteList a -> String # showList :: [InfiniteList a] -> ShowS # |
newtype NonEmptyList a #
NonEmpty xs
: guarantees that xs is non-empty.
Constructors
NonEmpty | |
Fields
|
Instances
newtype OrderedList a #
Ordered xs
: guarantees that xs is ordered.
Constructors
Ordered | |
Fields
|
Instances
Fixed x
: as x, but will not be shrunk.
Instances
Functor Fixed | |
Arbitrary a => Arbitrary (Fixed a) | |
Enum a => Enum (Fixed a) | |
Num a => Num (Fixed a) | |
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 Methods toRational :: Fixed a -> Rational # | |
Show a => Show (Fixed a) | |
Eq a => Eq (Fixed a) | |
Ord a => Ord (Fixed a) | |
Defined in Test.QuickCheck.Modifiers |
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) | |
Num a => Num (Blind a) | |
Integral a => Integral (Blind a) | |
Defined in Test.QuickCheck.Modifiers | |
Real a => Real (Blind a) | |
Defined in Test.QuickCheck.Modifiers Methods toRational :: Blind a -> Rational # | |
Show (Blind a) | |
Eq a => Eq (Blind a) | |
Ord a => Ord (Blind a) | |
Defined in Test.QuickCheck.Modifiers |
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
.
Minimal complete definition
Nothing
Instances
The type of possibly partial concrete functions
data Confidence #
The statistical parameters used by checkCoverage
.
Constructors
Confidence | |
Fields
|
Instances
Show Confidence | |
Defined in Test.QuickCheck.State Methods showsPrec :: Int -> Confidence -> ShowS # show :: Confidence -> String # showList :: [Confidence] -> ShowS # |
If a property returns Discard
, the current test case is discarded,
the same as if a precondition was false.
An example is the definition of ==>
:
(==>) :: Testable prop => Bool -> prop -> Property False ==> _ = property Discard True ==> p = property p
Constructors
Discard |
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 |
Args specifies arguments to the QuickCheck driver
Constructors
Args | |
Fields
|
newtype PropertyM (m :: Type -> Type) a #
The property monad is really a monad transformer that can contain
monadic computations in the monad m
it is parameterized by:
m
- them
-computations that may be performed withinPropertyM
Elements of PropertyM m a
may mix property operations and m
-computations.
Constructors
MkPropertyM | |
Fields
|
Instances
MonadTrans PropertyM | |
Defined in Test.QuickCheck.Monadic | |
Monad m => MonadFail (PropertyM m) | |
Defined in Test.QuickCheck.Monadic | |
MonadIO m => MonadIO (PropertyM m) | |
Defined in Test.QuickCheck.Monadic | |
Applicative (PropertyM m) | |
Defined in Test.QuickCheck.Monadic | |
Functor (PropertyM m) | |
Monad m => Monad (PropertyM m) | |
The strict ST
monad.
The ST
monad allows for destructive updates, but is escapable (unlike IO).
A computation of type
returns a value of type ST
s aa
, and
execute in "thread" s
. The s
parameter is either
- an uninstantiated type variable (inside invocations of
runST
), or RealWorld
(inside invocations ofstToIO
).
It serves to keep the internal states of different invocations
of runST
separate from each other and from invocations of
stToIO
.
The >>=
and >>
operations are strict in the state (though not in
values stored in the state). For example,
runST
(writeSTRef _|_ v >>= f) = _|_
Instances
A Selector
is a predicate; it can simultaneously constrain the type and
value of an exception.
class (Alternative m, Monad m) => MonadPlus (m :: Type -> Type) where #
Monads that also support choice and failure.
Minimal complete definition
Nothing
Methods
The identity of mplus
. It should also satisfy the equations
mzero >>= f = mzero v >> mzero = mzero
The default definition is
mzero = empty
An associative operation. The default definition is
mplus = (<|>
)
Instances
MonadPlus P | Since: base-2.1 |
Defined in Text.ParserCombinators.ReadP | |
MonadPlus ReadP | Since: base-2.1 |
MonadPlus Seq | |
MonadPlus IO | Takes the first non-throwing Since: base-4.9.0.0 |
MonadPlus Array | |
MonadPlus SmallArray | |
Defined in Data.Primitive.SmallArray | |
MonadPlus Vector | |
Defined in Data.Vector | |
MonadPlus Vector | |
Defined in Data.Vector.Strict | |
MonadPlus Maybe | Picks the leftmost Since: base-2.1 |
MonadPlus List | Combines lists by concatenation, starting from the empty list. Since: base-2.1 |
MonadPlus (Proxy :: Type -> Type) | Since: base-4.9.0.0 |
MonadPlus (U1 :: Type -> Type) | Since: base-4.9.0.0 |
MonadPlus f => MonadPlus (Rec1 f) | Since: base-4.9.0.0 |
(Monoid w, Functor m, MonadPlus m) => MonadPlus (AccumT w m) | |
MonadPlus m => MonadPlus (SelectT r m) | |
(Functor m, MonadPlus m) => MonadPlus (WriterT w m) | |
(MonadPlus f, MonadPlus g) => MonadPlus (f :*: g) | Since: base-4.9.0.0 |
MonadPlus f => MonadPlus (M1 i c f) | Since: base-4.9.0.0 |
(Functor m, MonadPlus m) => MonadPlus (RWST r w s m) | |
The class Typeable
allows a concrete representation of a type to
be calculated.
Minimal complete definition
typeRep#
class Monad m => MonadFail (m :: Type -> Type) where #
When a value is bound in do
-notation, the pattern on the left
hand side of <-
might not match. In this case, this class
provides a function to recover.
A Monad
without a MonadFail
instance may only be used in conjunction
with pattern that always match, such as newtypes, tuples, data types with
only a single data constructor, and irrefutable patterns (~pat
).
Instances of MonadFail
should satisfy the following law: fail s
should
be a left zero for >>=
,
fail s >>= f = fail s
If your Monad
is also MonadPlus
, a popular definition is
fail _ = mzero
fail s
should be an action that runs in the monad itself, not an
exception (except in instances of MonadIO
). In particular,
fail
should not be implemented in terms of error
.
Since: base-4.9.0.0
Instances
type TypeRep = SomeTypeRep #
A quantified type representation.
type HasCallStack = ?callStack :: CallStack #
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
data (a :: k1) :~~: (b :: k2) where infix 4 #
Kind heterogeneous propositional equality. Like :~:
, a :~~: b
is
inhabited by a terminating value if and only if a
is the same type as b
.
Since: base-4.10.0.0
Instances
Category ((:~~:) :: k -> k -> Type) | Since: base-4.10.0.0 |
TestEquality ((:~~:) a :: k -> Type) | Since: base-4.10.0.0 |
Defined in Data.Type.Equality | |
NFData2 ((:~~:) :: Type -> Type -> Type) | Since: deepseq-1.4.3.0 |
Defined in Control.DeepSeq | |
NFData1 ((:~~:) a :: Type -> Type) | Since: deepseq-1.4.3.0 |
Defined in Control.DeepSeq | |
a ~~ b => Bounded (a :~~: b) | Since: base-4.10.0.0 |
a ~~ b => Enum (a :~~: b) | Since: base-4.10.0.0 |
Defined in Data.Type.Equality Methods succ :: (a :~~: b) -> a :~~: b # pred :: (a :~~: b) -> a :~~: b # fromEnum :: (a :~~: b) -> Int # enumFrom :: (a :~~: b) -> [a :~~: b] # enumFromThen :: (a :~~: b) -> (a :~~: b) -> [a :~~: b] # enumFromTo :: (a :~~: b) -> (a :~~: b) -> [a :~~: b] # enumFromThenTo :: (a :~~: b) -> (a :~~: b) -> (a :~~: b) -> [a :~~: b] # | |
a ~~ b => Read (a :~~: b) | Since: base-4.10.0.0 |
Show (a :~~: b) | Since: base-4.10.0.0 |
NFData (a :~~: b) | Since: deepseq-1.4.3.0 |
Defined in Control.DeepSeq | |
Eq (a :~~: b) | Since: base-4.10.0.0 |
Ord (a :~~: b) | Since: base-4.10.0.0 |
data (a :: k) :~: (b :: k) where infix 4 #
Propositional equality. If a :~: b
is inhabited by some terminating
value, then the type a
is the same as the type b
. To use this equality
in practice, pattern-match on the a :~: b
to get out the Refl
constructor;
in the body of the pattern-match, the compiler knows that a ~ b
.
Since: base-4.7.0.0
Instances
Category ((:~:) :: k -> k -> Type) | Since: base-4.7.0.0 |
TestEquality ((:~:) a :: k -> Type) | Since: base-4.7.0.0 |
Defined in Data.Type.Equality | |
NFData2 ((:~:) :: Type -> Type -> Type) | Since: deepseq-1.4.3.0 |
Defined in Control.DeepSeq | |
NFData1 ((:~:) a) | Since: deepseq-1.4.3.0 |
Defined in Control.DeepSeq | |
a ~ b => Bounded (a :~: b) | Since: base-4.7.0.0 |
a ~ b => Enum (a :~: b) | Since: base-4.7.0.0 |
Defined in Data.Type.Equality Methods succ :: (a :~: b) -> a :~: b # pred :: (a :~: b) -> a :~: b # fromEnum :: (a :~: b) -> Int # enumFrom :: (a :~: b) -> [a :~: b] # enumFromThen :: (a :~: b) -> (a :~: b) -> [a :~: b] # enumFromTo :: (a :~: b) -> (a :~: b) -> [a :~: b] # enumFromThenTo :: (a :~: b) -> (a :~: b) -> (a :~: b) -> [a :~: b] # | |
a ~ b => Read (a :~: b) | Since: base-4.7.0.0 |
Show (a :~: b) | Since: base-4.7.0.0 |
NFData (a :~: b) | Since: deepseq-1.4.3.0 |
Defined in Control.DeepSeq | |
Eq (a :~: b) | Since: base-4.7.0.0 |
Ord (a :~: b) | Since: base-4.7.0.0 |
Defined in Data.Type.Equality |
Proxy
is a type that holds no data, but has a phantom parameter of
arbitrary type (or even kind). Its use is to provide type information, even
though there is no value available of that type (or it may be too costly to
create one).
Historically,
is a safer alternative to the
Proxy
:: Proxy
a
idiom.undefined
:: a
>>>
Proxy :: Proxy (Void, Int -> Int)
Proxy
Proxy can even hold types of higher kinds,
>>>
Proxy :: Proxy Either
Proxy
>>>
Proxy :: Proxy Functor
Proxy
>>>
Proxy :: Proxy complicatedStructure
Proxy
Constructors
Proxy |
Instances
Generic1 (Proxy :: k -> Type) | |
MonadZip (Proxy :: Type -> Type) | Since: base-4.9.0.0 |
Foldable (Proxy :: Type -> Type) | Since: base-4.7.0.0 |
Defined in Data.Foldable Methods fold :: Monoid m => Proxy m -> m # foldMap :: Monoid m => (a -> m) -> Proxy a -> m # foldMap' :: Monoid m => (a -> m) -> Proxy a -> m # foldr :: (a -> b -> b) -> b -> Proxy a -> b # foldr' :: (a -> b -> b) -> b -> Proxy a -> b # foldl :: (b -> a -> b) -> b -> Proxy a -> b # foldl' :: (b -> a -> b) -> b -> Proxy a -> b # foldr1 :: (a -> a -> a) -> Proxy a -> a # foldl1 :: (a -> a -> a) -> Proxy a -> a # elem :: Eq a => a -> Proxy a -> Bool # maximum :: Ord a => Proxy a -> a # minimum :: Ord a => Proxy a -> a # | |
Eq1 (Proxy :: Type -> Type) | Since: base-4.9.0.0 |
Ord1 (Proxy :: Type -> Type) | Since: base-4.9.0.0 |
Defined in Data.Functor.Classes | |
Read1 (Proxy :: Type -> Type) | Since: base-4.9.0.0 |
Defined in Data.Functor.Classes | |
Show1 (Proxy :: Type -> Type) | Since: base-4.9.0.0 |
Contravariant (Proxy :: Type -> Type) | |
Traversable (Proxy :: Type -> Type) | Since: base-4.7.0.0 |
Alternative (Proxy :: Type -> Type) | Since: base-4.9.0.0 |
Applicative (Proxy :: Type -> Type) | Since: base-4.7.0.0 |
Functor (Proxy :: Type -> Type) | Since: base-4.7.0.0 |
Monad (Proxy :: Type -> Type) | Since: base-4.7.0.0 |
MonadPlus (Proxy :: Type -> Type) | Since: base-4.9.0.0 |
NFData1 (Proxy :: Type -> Type) | Since: deepseq-1.4.3.0 |
Defined in Control.DeepSeq | |
Hashable1 (Proxy :: Type -> Type) | |
Defined in Data.Hashable.Class | |
Monoid (Proxy s) | Since: base-4.7.0.0 |
Semigroup (Proxy s) | Since: base-4.9.0.0 |
Bounded (Proxy t) | Since: base-4.7.0.0 |
Enum (Proxy s) | Since: base-4.7.0.0 |
Generic (Proxy t) | |
Ix (Proxy s) | Since: base-4.7.0.0 |
Defined in Data.Proxy | |
Read (Proxy t) | Since: base-4.7.0.0 |
Show (Proxy s) | Since: base-4.7.0.0 |
NFData (Proxy a) | Since: deepseq-1.4.0.0 |
Defined in Control.DeepSeq | |
Eq (Proxy s) | Since: base-4.7.0.0 |
Ord (Proxy s) | Since: base-4.7.0.0 |
Hashable (Proxy a) | |
Defined in Data.Hashable.Class | |
type Rep1 (Proxy :: k -> Type) | Since: base-4.6.0.0 |
type Rep (Proxy t) | Since: base-4.6.0.0 |
A type class for examples
Minimal complete definition
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 (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 |
A class of types that can be fully evaluated.
Since: deepseq-1.1.0.0
Instances
type ActionWith a = a -> IO () #
An IO
action that expects an argument of type a
type Expectation = Assertion #
A set of laws associated with a typeclass.
Note: Most of the top-level functions provided
by this library have the shape
`forall a. (Ctx a) => Proxy a -> Laws`. You can just
as easily provide your own Laws
in libraries/test suites
using regular QuickCheck machinery.
Constructors
Laws | |
Fields
|
data Proxy2 (f :: Type -> Type -> Type) #
In older versions of GHC, Proxy is not poly-kinded, so we provide Proxy2.
Constructors
Proxy2 |
data Proxy1 (f :: Type -> Type) #
In older versions of GHC, Proxy is not poly-kinded, so we provide Proxy1.
Constructors
Proxy1 |
pattern Fn2 :: (a -> b -> c) -> Fun (a, b) c #
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]
pattern Fn :: (a -> b) -> Fun a b #
A modifier for testing functions.
prop :: Fun String Integer -> Bool prop (Fn f) = f "banana" == f "monkey" || f "banana" == f "elephant"
deepseq :: NFData a => a -> b -> b infixr 0 #
deepseq
: fully evaluates the first argument, before returning the
second.
The name deepseq
is used to illustrate the relationship to seq
:
where seq
is shallow in the sense that it only evaluates the top
level of its argument, deepseq
traverses the entire data structure
evaluating it completely.
deepseq
can be useful for forcing pending exceptions,
eradicating space leaks, or forcing lazy I/O to happen. It is
also useful in conjunction with parallel Strategies (see the
parallel
package).
There is no guarantee about the ordering of evaluation. The
implementation may evaluate the components of the structure in
any order or in parallel. To impose an actual order on
evaluation, use pseq
from Control.Parallel in the
parallel
package.
Since: deepseq-1.1.0.0
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.
assert :: forall (m :: Type -> Type). Monad m => Bool -> PropertyM m () #
Allows embedding non-monadic properties into monadic ones.
(==>) :: Testable prop => Bool -> prop -> Property infixr 0 #
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.
join :: Monad m => m (m a) -> m a #
The join
function is the conventional monad join operator. It
is used to remove one level of monadic structure, projecting its
bound argument into the outer level.
'
' can be understood as the join
bssdo
expression
do bs <- bss bs
Examples
A common use of join
is to run an IO
computation returned from
an STM
transaction, since STM
transactions
can't perform IO
directly. Recall that
atomically
:: STM a -> IO a
is used to run STM
transactions atomically. So, by
specializing the types of atomically
and join
to
atomically
:: STM (IO b) -> IO (IO b)join
:: IO (IO b) -> IO b
we can compose them as
join
.atomically
:: STM (IO b) -> IO b
sized :: (Int -> Gen a) -> Gen a #
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 = sized $ \n -> do k <- choose (0,n) vectorOf k gen
You can also do this using getSize
.
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
.
resize :: HasCallStack => Int -> Gen a -> Gen a #
Overrides the size parameter. Returns a generator which uses the given size instead of the runtime-size parameter.
scale :: (Int -> Int) -> Gen a -> Gen a #
Adjust the size parameter, by transforming it with the given function.
choose :: Random a => (a, a) -> Gen a #
Generates a random element in the given inclusive range.
For integral and enumerated types, the specialised variants of
choose
below run much quicker.
chooseEnum :: Enum a => (a, a) -> Gen a #
A fast implementation of choose
for enumerated types.
chooseBoundedIntegral :: (Bounded a, Integral a) => (a, a) -> Gen a #
A fast implementation of choose
for bounded integral types.
Run a generator. The size passed to the generator is always 30;
if you want another size then you should explicitly use resize
.
suchThatMap :: Gen a -> (a -> Maybe b) -> Gen b #
Generates a value for which the given function returns a Just
, and then
applies the function.
suchThatMaybe :: Gen a -> (a -> Bool) -> Gen (Maybe a) #
Tries to generate a value that satisfies a predicate.
If it fails to do so after enough attempts, returns Nothing
.
oneof :: HasCallStack => [Gen a] -> Gen a #
Randomly uses one of the given generators. The input list must be non-empty.
frequency :: HasCallStack => [(Int, Gen a)] -> Gen a #
Chooses one of the given generators, with a weighted random distribution. The input list must be non-empty.
elements :: HasCallStack => [a] -> Gen a #
Generates one of the given values. The input list must be non-empty.
growingElements :: HasCallStack => [a] -> Gen a #
Takes a list of elements of increasing size, and chooses among an initial segment of the list. The size of this initial segment increases with the size parameter. The input list must be non-empty.
Generates a list of random length. The maximum length depends on the size parameter.
Generates a non-empty list of random length. The maximum length depends on the size parameter.
infiniteListOf :: Gen a -> Gen [a] #
Generates an infinite list.
arbitrary1 :: (Arbitrary1 f, Arbitrary a) => Gen (f a) #
shrink1 :: (Arbitrary1 f, Arbitrary a) => f a -> [f a] #
arbitrary2 :: (Arbitrary2 f, Arbitrary a, Arbitrary b) => Gen (f a b) #
shrink2 :: (Arbitrary2 f, Arbitrary a, Arbitrary b) => f a b -> [f a b] #
genericShrink :: (Generic a, RecursivelyShrink (Rep a), GSubterms (Rep a) a) => a -> [a] #
Shrink a term to any of its immediate subterms, and also recursively shrink all subterms.
recursivelyShrink :: (Generic a, RecursivelyShrink (Rep a)) => a -> [a] #
Recursively shrink all immediate subterms.
shrinkList :: (a -> [a]) -> [a] -> [[a]] #
Shrink a list of values given a shrinking function for individual values.
applyArbitrary2 :: (Arbitrary a, Arbitrary b) => (a -> b -> r) -> Gen r #
Apply a binary function to random arguments.
applyArbitrary3 :: (Arbitrary a, Arbitrary b, Arbitrary c) => (a -> b -> c -> r) -> Gen r #
Apply a ternary function to random arguments.
applyArbitrary4 :: (Arbitrary a, Arbitrary b, Arbitrary c, Arbitrary d) => (a -> b -> c -> d -> r) -> Gen r #
Apply a function of arity 4 to random arguments.
arbitrarySizedIntegral :: Integral a => Gen a #
Generates an integral number. The number can be positive or negative and its maximum absolute value depends on the size parameter.
arbitrarySizedNatural :: Integral a => Gen a #
Generates a natural number. The number's maximum value depends on the size parameter.
arbitrarySizedFractional :: Fractional a => Gen a #
Uniformly generates a fractional number. The number can be positive or negative and its maximum absolute value depends on the size parameter.
arbitraryBoundedIntegral :: (Bounded a, Integral a) => Gen a #
Generates an integral number. The number is chosen uniformly from
the entire range of the type. You may want to use
arbitrarySizedBoundedIntegral
instead.
arbitraryBoundedRandom :: (Bounded a, Random a) => Gen a #
Generates an element of a bounded type. The element is chosen from the entire range of the type.
arbitraryBoundedEnum :: (Bounded a, Enum a) => Gen a #
Generates an element of a bounded enumeration.
arbitrarySizedBoundedIntegral :: (Bounded a, Integral a) => Gen a #
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.
arbitraryUnicodeChar :: Gen Char #
Generates any Unicode character (but not a surrogate)
arbitraryASCIIChar :: Gen Char #
Generates a random ASCII character (0-127).
arbitraryPrintableChar :: Gen Char #
Generates a printable Unicode character.
shrinkNothing :: a -> [a] #
Returns no shrinking alternatives.
shrinkMap :: Arbitrary a => (a -> b) -> (b -> a) -> b -> [b] #
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
shrinkMapBy :: (a -> b) -> (b -> a) -> (a -> [a]) -> b -> [b] #
Non-overloaded version of shrinkMap
.
shrinkIntegral :: Integral a => a -> [a] #
Shrink an integral number.
shrinkBoundedEnum :: (Bounded a, Enum a, Eq a) => a -> [a] #
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
[]
shrinkRealFrac :: RealFrac a => a -> [a] #
Shrink a fraction, preferring numbers with smaller
numerators or denominators. See also shrinkDecimal
.
shrinkDecimal :: RealFrac a => a -> [a] #
Shrink a real number, preferring numbers with shorter
decimal representations. See also shrinkRealFrac
.
genericCoarbitrary :: (Generic a, GCoArbitrary (Rep a)) => a -> Gen b -> Gen b #
Generic CoArbitrary implementation.
(><) :: (Gen a -> Gen a) -> (Gen a -> Gen a) -> Gen a -> Gen a #
Combine two generator perturbing functions, for example the
results of calls to variant
or coarbitrary
.
coarbitraryIntegral :: Integral a => a -> Gen b -> Gen b #
A coarbitrary
implementation for integral numbers.
coarbitraryReal :: Real a => a -> Gen b -> Gen b #
A coarbitrary
implementation for real numbers.
coarbitraryShow :: Show a => a -> Gen b -> Gen b #
coarbitrary
helper for lazy people :-).
coarbitraryEnum :: Enum a => a -> Gen b -> Gen b #
A coarbitrary
implementation for enums.
orderedList :: (Ord a, Arbitrary a) => Gen [a] #
Generates an ordered list.
infiniteList :: Arbitrary a => Gen [a] #
Generates an infinite list.
functionElements :: Eq a => [a] -> (a -> b) -> a :-> b #
Provides a Function
instance for small finite types.
functionRealFrac :: RealFrac a => (a -> b) -> a :-> b #
functionIntegral :: Integral a => (a -> b) -> a :-> b #
functionShow :: (Show a, Read a) => (a -> c) -> a :-> c #
functionVoid :: (forall b. void -> b) -> void :-> c #
functionMap :: Function b => (a -> b) -> (b -> a) -> (a -> c) -> a :-> c #
functionMapWith :: ((b -> c) -> b :-> c) -> (a -> b) -> (b -> a) -> (a -> c) -> a :-> c #
Since: QuickCheck-2.13.3
functionPairWith :: ((a -> b -> c) -> a :-> (b -> c)) -> ((b -> c) -> b :-> c) -> ((a, b) -> c) -> (a, b) :-> c #
Since: QuickCheck-2.13.3
functionEitherWith :: ((a -> c) -> a :-> c) -> ((b -> c) -> b :-> c) -> (Either a b -> c) -> Either a b :-> c #
Since: QuickCheck-2.13.3
applyFun :: Fun a b -> a -> b #
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"
applyFun2 :: Fun (a, b) c -> a -> b -> c #
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]
applyFun3 :: Fun (a, b, c) d -> a -> b -> c -> d #
Extracts the value of a ternary function. Fn3
is the
pattern equivalent of this function.
ioProperty :: Testable prop => IO prop -> Property #
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.
idempotentIOProperty :: Testable prop => IO prop -> Property #
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.
coerceWitness :: Typeable a => Witness -> a #
castWitness :: Typeable a => Witness -> Maybe a #
mapSize :: Testable prop => (Int -> Int) -> prop -> Property #
Adjust the test case size for a property, by transforming it with the given function.
Arguments
:: Testable prop | |
=> (a -> [a]) |
|
-> a | The original argument |
-> (a -> prop) | |
-> Property |
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.
noShrinking :: Testable prop => prop -> Property #
Disables shrinking for a property altogether.
Only quantification inside the call to noShrinking
is affected.
counterexample :: Testable prop => String -> prop -> Property #
Adds the given string to the counterexample if the property fails.
printTestCase :: Testable prop => String -> prop -> Property #
Adds the given string to the counterexample if the property fails.
whenFail :: Testable prop => IO () -> prop -> Property #
Performs an IO
action after the last failure of a property.
whenFail' :: Testable prop => IO () -> prop -> Property #
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.
verbose :: Testable prop => prop -> Property #
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.
verboseShrinking :: Testable prop => prop -> Property #
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.
expectFailure :: Testable prop => prop -> Property #
Indicates that a property is supposed to fail. QuickCheck will report an error if it does not fail.
once :: Testable prop => prop -> Property #
Modifies a property so that it only will be tested once.
Opposite of again
.
again :: Testable prop => prop -> Property #
Modifies a property so that it will be tested repeatedly.
Opposite of once
.
withMaxSuccess :: Testable prop => Int -> prop -> Property #
Configures how many times a property will be tested.
For example,
quickCheck (withMaxSuccess 1000 p)
will test p
up to 1000 times.
withDiscardRatio :: Testable prop => Int -> prop -> Property #
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.
withMaxShrinks :: Testable prop => Int -> prop -> Property #
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.
withMaxSize :: Testable prop => Int -> prop -> Property #
Configure the maximum size a property will be tested at.
witness :: (Typeable a, Show a, Testable prop) => a -> prop -> Property #
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
checkCoverage :: Testable prop => prop -> Property #
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)
checkCoverageWith :: Testable prop => Confidence -> prop -> Property #
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)
The standard parameters used by checkCoverage
: certainty = 10^9
,
tolerance = 0.9
. See Confidence
for the meaning of the parameters.
label :: Testable prop => String -> prop -> Property #
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
.
collect :: (Show a, Testable prop) => a -> prop -> Property #
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
.
Arguments
:: Testable prop | |
=> Bool |
|
-> String | Label. |
-> prop | |
-> Property |
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).
Arguments
:: 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%
tabulate :: Testable prop => String -> [String] -> prop -> Property #
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
coverTable :: Testable prop => String -> [(String, Double)] -> prop -> Property #
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%
within :: Testable prop => Int -> prop -> Property #
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)
discardAfter :: Testable prop => Int -> prop -> Property #
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.
forAll :: (Show a, Testable prop) => Gen a -> (a -> prop) -> Property #
Explicit universal quantification: uses an explicitly given test case generator.
forAllShow :: Testable prop => Gen a -> (a -> String) -> (a -> prop) -> Property #
Like forAll
, but with an explicitly given show function.
forAllBlind :: Testable prop => Gen a -> (a -> prop) -> Property #
Like forAll
, but without printing the generated value.
forAllShrink :: (Show a, Testable prop) => Gen a -> (a -> [a]) -> (a -> prop) -> Property #
Like forAll
, but tries to shrink the argument for failing test cases.
forAllShrinkShow :: Testable prop => Gen a -> (a -> [a]) -> (a -> String) -> (a -> prop) -> Property #
Like forAllShrink
, but with an explicitly given show function.
forAllShrinkBlind :: Testable prop => Gen a -> (a -> [a]) -> (a -> prop) -> Property #
Like forAllShrink
, but without printing the generated value.
(.&&.) :: (Testable prop1, Testable prop2) => prop1 -> prop2 -> Property infixr 1 #
Conjunction: p1
.&&.
p2
passes if both p1
and p2
pass.
(.||.) :: (Testable prop1, Testable prop2) => prop1 -> prop2 -> Property infixr 1 #
Disjunction: p1
.||.
p2
passes unless p1
and p2
simultaneously fail.
(===) :: (Eq a, Show a) => a -> a -> Property infix 4 #
Like ==
, but prints a counterexample when it fails.
(=/=) :: (Eq a, Show a) => a -> a -> Property infix 4 #
Like /=
, but prints a counterexample when it fails.
total :: NFData a => a -> Property #
Checks that a value is total, i.e., doesn't crash when evaluated.
quickCheck :: Testable prop => prop -> IO () #
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.
quickCheckWith :: Testable prop => Args -> prop -> IO () #
Tests a property, using test arguments, and prints the results to stdout
.
quickCheckResult :: Testable prop => prop -> IO Result #
Tests a property, produces a test result, and prints the results to stdout
.
quickCheckWithResult :: Testable prop => Args -> prop -> IO Result #
Tests a property, using test arguments, produces a test result, and prints the results to stdout
.
recheck :: Testable prop => Result -> prop -> IO () #
Re-run a property with the seed and size that failed in a run of quickCheckResult
.
verboseCheck :: Testable prop => prop -> IO () #
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.
verboseCheckWith :: Testable prop => Args -> prop -> IO () #
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.
verboseCheckResult :: Testable prop => prop -> IO Result #
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.
verboseCheckWithResult :: Testable prop => Args -> prop -> IO Result #
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.
assertWith :: forall (m :: Type -> Type). Monad m => Bool -> String -> PropertyM m () #
Like assert
but allows caller to specify an explicit message to show on failure.
Example:
do assertWith True "My first predicate." assertWith False "My other predicate." ...
Assertion failed (after 2 tests): Passed: My first predicate Failed: My other predicate
pre :: forall (m :: Type -> Type). Monad m => Bool -> PropertyM m () #
Tests preconditions. Unlike assert
this does not cause the
property to fail, rather it discards them just like using the
implication combinator ==>
.
This allows representing the Hoare triple
{p} x ← e{q}
as
pre p x <- run e assert q
run :: Monad m => m a -> PropertyM m a #
The lifting operation of the property monad. Allows embedding
monadic/IO
-actions in properties:
log :: Int -> IO () prop_foo n = monadicIO $ do run (log n) -- ...
forAllM :: forall (m :: Type -> Type) a b. (Monad m, Show a) => Gen a -> (a -> PropertyM m b) -> PropertyM m b #
monitor :: forall (m :: Type -> Type). Monad m => (Property -> Property) -> PropertyM m () #
Allows making observations about the test data:
monitor (collect
e)
collects the distribution of value of e
.
monitor (counterexample
"Failure!")
Adds "Failure!"
to the counterexamples.
monadicIO :: Testable a => PropertyM IO a -> Property #
Runs the property monad for IO
-computations.
prop_cat msg = monadicIO $ do (exitCode, stdout, _) <- run (readProcessWithExitCode
"cat" [] msg) pre (ExitSuccess
== exitCode) assert (stdout == msg)
>>>
quickCheck prop_cat
+++ OK, passed 100 tests.
monadicST :: Testable a => (forall s. PropertyM (ST s) a) -> Property #
Runs the property monad for ST
-computations.
-- Your mutable sorting algorithm here sortST :: Ord a => [a] ->ST
s (MVector s a) sortST =thaw
.fromList
.sort
prop_sortST xs = monadicST $ do sorted <- run (freeze
=<< sortST xs) assert (toList
sorted == sort xs)
>>>
quickCheck prop_sortST
+++ OK, passed 100 tests.
Arguments
:: Exception exc | |
=> (exc -> Bool) | Return |
-> a | Value that should result in an exception, when evaluated to WHNF |
-> Property |
Evaluate the value to Weak Head Normal Form (WHNF) and fail if it does not result in an expected exception being thrown.
Arguments
:: Exception exc | |
=> (exc -> Bool) | Return |
-> IO a | An action that should throw the expected exception |
-> Property |
Make sure that a specific exception is thrown during an IO action. The result is evaluated to WHNF.
polyQuickCheck :: Name -> ExpQ #
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 []
.
polyVerboseCheck :: Name -> ExpQ #
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 []
.
monomorphic :: Name -> ExpQ #
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 []
.
forAllProperties :: Q Exp #
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 []
.
allProperties :: Q Exp #
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 []
.
quickCheckAll :: Q Exp #
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!
verboseCheckAll :: Q Exp #
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 []
.
labelledExamples :: Testable prop => prop -> IO () #
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
labelledExamplesWith :: Testable prop => Args -> prop -> IO () #
A variant of labelledExamples
that takes test arguments.
labelledExamplesResult :: Testable prop => prop -> IO Result #
A variant of labelledExamples
that returns a result.
labelledExamplesWithResult :: Testable prop => Args -> prop -> IO Result #
A variant of labelledExamples
that takes test arguments and returns a result.
mapM :: (Traversable t, Monad m) => (a -> m b) -> t a -> m (t b) #
Map each element of a structure to a monadic action, evaluate
these actions from left to right, and collect the results. For
a version that ignores the results see mapM_
.
Examples
sequence :: (Traversable t, Monad m) => t (m a) -> m (t a) #
Evaluate each monadic action in the structure from left to
right, and collect the results. For a version that ignores the
results see sequence_
.
Examples
Basic usage:
The first two examples are instances where the input and
and output of sequence
are isomorphic.
>>>
sequence $ Right [1,2,3,4]
[Right 1,Right 2,Right 3,Right 4]
>>>
sequence $ [Right 1,Right 2,Right 3,Right 4]
Right [1,2,3,4]
The following examples demonstrate short circuit behavior
for sequence
.
>>>
sequence $ Left [1,2,3,4]
Left [1,2,3,4]
>>>
sequence $ [Left 0, Right 1,Right 2,Right 3,Right 4]
Left 0
forM :: (Traversable t, Monad m) => t a -> (a -> m b) -> m (t b) #
forever :: Applicative f => f a -> f b #
Repeat an action indefinitely.
Examples
A common use of forever
is to process input from network sockets,
Handle
s, and channels
(e.g. MVar
and
Chan
).
For example, here is how we might implement an echo
server, using
forever
both to listen for client connections on a network socket
and to echo client input on client connection handles:
echoServer :: Socket -> IO () echoServer socket =forever
$ do client <- accept socketforkFinally
(echo client) (\_ -> hClose client) where echo :: Handle -> IO () echo client =forever
$ hGetLine client >>= hPutStrLn client
Note that "forever" isn't necessarily non-terminating.
If the action is in a
and short-circuits after some number of iterations.
then MonadPlus
actually returns forever
mzero
, effectively short-circuiting its caller.
guard :: Alternative f => Bool -> f () #
Conditional failure of Alternative
computations. Defined by
guard True =pure
() guard False =empty
Examples
Common uses of guard
include conditionally signaling an error in
an error monad and conditionally rejecting the current choice in an
Alternative
-based parser.
As an example of signaling an error in the error monad Maybe
,
consider a safe division function safeDiv x y
that returns
Nothing
when the denominator y
is zero and
otherwise. For example:Just
(x `div`
y)
>>>
safeDiv 4 0
Nothing
>>>
safeDiv 4 2
Just 2
A definition of safeDiv
using guards, but not guard
:
safeDiv :: Int -> Int -> Maybe Int safeDiv x y | y /= 0 = Just (x `div` y) | otherwise = Nothing
A definition of safeDiv
using guard
and Monad
do
-notation:
safeDiv :: Int -> Int -> Maybe Int safeDiv x y = do guard (y /= 0) return (x `div` y)
(=<<) :: Monad m => (a -> m b) -> m a -> m b infixr 1 #
Same as >>=
, but with the arguments interchanged.
when :: Applicative f => Bool -> f () -> f () #
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.
liftM2 :: Monad m => (a1 -> a2 -> r) -> m a1 -> m a2 -> m r #
Promote a function to a monad, scanning the monadic arguments from left to right. For example,
liftM2 (+) [0,1] [0,2] = [0,2,1,3] liftM2 (+) (Just 1) Nothing = Nothing
liftM3 :: Monad m => (a1 -> a2 -> a3 -> r) -> m a1 -> m a2 -> m a3 -> m r #
Promote a function to a monad, scanning the monadic arguments from
left to right (cf. liftM2
).
liftM4 :: Monad m => (a1 -> a2 -> a3 -> a4 -> r) -> m a1 -> m a2 -> m a3 -> m a4 -> m r #
Promote a function to a monad, scanning the monadic arguments from
left to right (cf. liftM2
).
liftM5 :: Monad m => (a1 -> a2 -> a3 -> a4 -> a5 -> r) -> m a1 -> m a2 -> m a3 -> m a4 -> m a5 -> m r #
Promote a function to a monad, scanning the monadic arguments from
left to right (cf. liftM2
).
fromMaybe :: a -> Maybe a -> a #
The fromMaybe
function takes a default value and a Maybe
value. If the Maybe
is Nothing
, it returns the default value;
otherwise, it returns the value contained in the Maybe
.
Examples
Basic usage:
>>>
fromMaybe "" (Just "Hello, World!")
"Hello, World!"
>>>
fromMaybe "" Nothing
""
Read an integer from a string using readMaybe
. If we fail to
parse an integer, we want to return 0
by default:
>>>
import Text.Read ( readMaybe )
>>>
fromMaybe 0 (readMaybe "5")
5>>>
fromMaybe 0 (readMaybe "")
0
runST :: (forall s. ST s a) -> a #
Return the value computed by a state thread.
The forall
ensures that the internal state used by the ST
computation is inaccessible to the rest of the program.
void :: Functor f => f a -> f () #
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
sequence_ :: (Foldable t, Monad m) => t (m a) -> m () #
Evaluate each monadic action in the structure from left to right,
and ignore the results. For a version that doesn't ignore the
results see sequence
.
sequence_
is just like sequenceA_
, but specialised to monadic
actions.
tyConPackage :: TyCon -> String #
tyConModule :: TyCon -> String #
tyConFingerprint :: TyCon -> Fingerprint #
typeRepFingerprint :: TypeRep -> Fingerprint #
Takes a value of type a
and returns a concrete representation
of that type.
Since: base-4.7.0.0
typeRepTyCon :: TypeRep -> TyCon #
Observe the type constructor of a quantified type representation.
typeRep :: forall {k} proxy (a :: k). Typeable a => proxy a -> TypeRep #
Takes a value of type a
and returns a concrete representation
of that type.
Since: base-4.7.0.0
rnfTypeRep :: TypeRep -> () #
Force a TypeRep
to normal form.
showsTypeRep :: TypeRep -> ShowS #
Show a type representation
eqT :: forall {k} (a :: k) (b :: k). (Typeable a, Typeable b) => Maybe (a :~: b) #
Extract a witness of equality of two types
Since: base-4.7.0.0
heqT :: forall {k1} {k2} (a :: k1) (b :: k2). (Typeable a, Typeable b) => Maybe (a :~~: b) #
Extract a witness of heterogeneous equality of two types
Since: base-4.18.0.0
gcast :: forall {k} (a :: k) (b :: k) c. (Typeable a, Typeable b) => c a -> Maybe (c b) #
A flexible variation parameterised in a type constructor
gcast1 :: forall {k1} {k2} c (t :: k2 -> k1) (t' :: k2 -> k1) (a :: k2). (Typeable t, Typeable t') => c (t a) -> Maybe (c (t' a)) #
Cast over k1 -> k2
gcast2 :: forall {k1} {k2} {k3} c (t :: k2 -> k3 -> k1) (t' :: k2 -> k3 -> k1) (a :: k2) (b :: k3). (Typeable t, Typeable t') => c (t a b) -> Maybe (c (t' a b)) #
Cast over k1 -> k2 -> k3
funResultTy :: TypeRep -> TypeRep -> Maybe TypeRep #
Applies a type to a function type. Returns: Just u
if the first argument
represents a function of type t -> u
and the second argument represents a
function of type t
. Otherwise, returns Nothing
.
splitTyConApp :: TypeRep -> (TyCon, [TypeRep]) #
Splits a type constructor application. Note that if the type constructor is polymorphic, this will not return the kinds that were used.
typeRepArgs :: TypeRep -> [TypeRep] #
Observe the argument types of a type representation
filterM :: Applicative m => (a -> m Bool) -> [a] -> m [a] #
This generalizes the list-based filter
function.
(>=>) :: Monad m => (a -> m b) -> (b -> m c) -> a -> m c infixr 1 #
Left-to-right composition of Kleisli arrows.
'(bs
' can be understood as the >=>
cs) ado
expression
do b <- bs a cs b
mapAndUnzipM :: Applicative m => (a -> m (b, c)) -> [a] -> m ([b], [c]) #
The mapAndUnzipM
function maps its first argument over a list, returning
the result as a pair of lists. This function is mainly used with complicated
data structures or a state monad.
zipWithM :: Applicative m => (a -> b -> m c) -> [a] -> [b] -> m [c] #
zipWithM_ :: Applicative m => (a -> b -> m c) -> [a] -> [b] -> m () #
foldM :: (Foldable t, Monad m) => (b -> a -> m b) -> b -> t a -> m b #
The foldM
function is analogous to foldl
, except that its result is
encapsulated in a monad. Note that foldM
works from left-to-right over
the list arguments. This could be an issue where (
and the `folded
function' are not commutative.>>
)
foldM f a1 [x1, x2, ..., xm] == do a2 <- f a1 x1 a3 <- f a2 x2 ... f am xm
If right-to-left evaluation is required, the input list should be reversed.
foldM_ :: (Foldable t, Monad m) => (b -> a -> m b) -> b -> t a -> m () #
Like foldM
, but discards the result.
replicateM :: Applicative m => Int -> m a -> m [a] #
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)
replicateM_ :: Applicative m => Int -> m a -> m () #
unless :: Applicative f => Bool -> f () -> f () #
The reverse of when
.
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 #
Use a modified maxSuccess
for given spec.
modifyMaxDiscardRatio :: (Int -> Int) -> SpecWith a -> SpecWith a #
Use a modified maxDiscardRatio
for given spec.
modifyMaxShrinks :: (Int -> Int) -> SpecWith a -> SpecWith a #
Use a modified maxShrinks
for given spec.
beforeWith :: (b -> IO a) -> SpecWith a -> SpecWith b #
Run a custom action before every spec item.
beforeAll :: HasCallStack => IO a -> SpecWith a -> Spec #
Run a custom action before the first spec item.
beforeAll_ :: HasCallStack => IO () -> SpecWith a -> SpecWith a #
Run a custom action before the first spec item.
beforeAllWith :: HasCallStack => (b -> IO a) -> SpecWith a -> SpecWith b #
Run a custom action with an argument before the first spec item.
after :: ActionWith a -> SpecWith a -> SpecWith a #
Run a custom action after every spec item.
around :: (ActionWith a -> IO ()) -> SpecWith a -> Spec #
Run a custom action before and/or after every spec item.
afterAll :: HasCallStack => ActionWith a -> SpecWith a -> SpecWith a #
Run a custom action after the last spec item.
afterAll_ :: HasCallStack => IO () -> SpecWith a -> SpecWith a #
Run a custom action after the last spec item.
around_ :: (IO () -> IO ()) -> SpecWith a -> SpecWith a #
Run a custom action before and/or after every spec item.
aroundWith :: (ActionWith a -> ActionWith b) -> SpecWith a -> SpecWith b #
Run a custom action before and/or after every spec item.
aroundAll :: HasCallStack => (ActionWith a -> IO ()) -> SpecWith a -> Spec #
Wrap an action around the given spec.
aroundAll_ :: HasCallStack => (IO () -> IO ()) -> SpecWith a -> SpecWith a #
Wrap an action around the given spec.
aroundAllWith :: HasCallStack => (ActionWith a -> ActionWith b) -> SpecWith a -> SpecWith b #
Wrap an action around the given spec. Changes the arg type inside.
mapSubject :: (b -> a) -> SpecWith a -> SpecWith b #
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 #
Ignore the subject under test for a given spec.
describe :: HasCallStack => String -> SpecWith a -> SpecWith a #
The describe
function combines a list of specs into a larger spec.
it :: (HasCallStack, Example a) => String -> a -> SpecWith (Arg a) #
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
specify :: (HasCallStack, Example a) => String -> a -> SpecWith (Arg a) #
specify
is an alias for it
.
xspecify :: (HasCallStack, Example a) => String -> a -> SpecWith (Arg a) #
xspecify
is an alias for xit
.
fit :: (HasCallStack, Example a) => String -> a -> SpecWith (Arg a) #
fit
is an alias for fmap focus . it
fspecify :: (HasCallStack, Example a) => String -> a -> SpecWith (Arg a) #
fspecify
is an alias for fit
.
fdescribe :: HasCallStack => String -> SpecWith a -> SpecWith a #
fdescribe
is an alias for fmap focus . describe
parallel :: SpecWith a -> SpecWith a #
parallel
marks all spec items of the given spec to be safe for parallel
evaluation.
sequential :: SpecWith a -> SpecWith a #
sequential
marks all spec items of the given spec to be evaluated sequentially.
pending :: HasCallStack => Expectation #
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 #
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.
example :: Expectation -> Expectation #
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
expectationFailure :: HasCallStack => String -> Expectation #
shouldBe :: (HasCallStack, Show a, Eq a) => a -> a -> Expectation infix 1 #
actual `shouldBe` expected
sets the expectation that actual
is equal
to expected
.
shouldSatisfy :: (HasCallStack, Show a) => a -> (a -> Bool) -> Expectation infix 1 #
v `shouldSatisfy` p
sets the expectation that p v
is True
.
shouldStartWith :: (HasCallStack, Show a, Eq a) => [a] -> [a] -> Expectation infix 1 #
list `shouldStartWith` prefix
sets the expectation that list
starts with prefix
,
shouldEndWith :: (HasCallStack, Show a, Eq a) => [a] -> [a] -> Expectation infix 1 #
list `shouldEndWith` suffix
sets the expectation that list
ends with suffix
,
shouldContain :: (HasCallStack, Show a, Eq a) => [a] -> [a] -> Expectation infix 1 #
list `shouldContain` sublist
sets the expectation that sublist
is contained,
wholly and intact, anywhere in list
.
shouldMatchList :: (HasCallStack, Show a, Eq a) => [a] -> [a] -> Expectation infix 1 #
xs `shouldMatchList` ys
sets the expectation that xs
has the same
elements that ys
has, possibly in another order
shouldReturn :: (HasCallStack, Show a, Eq a) => IO a -> a -> Expectation infix 1 #
action `shouldReturn` expected
sets the expectation that action
returns expected
.
shouldNotBe :: (HasCallStack, Show a, Eq a) => a -> a -> Expectation infix 1 #
actual `shouldNotBe` notExpected
sets the expectation that actual
is not
equal to notExpected
shouldNotSatisfy :: (HasCallStack, Show a) => a -> (a -> Bool) -> Expectation infix 1 #
v `shouldNotSatisfy` p
sets the expectation that p v
is False
.
shouldNotContain :: (HasCallStack, Show a, Eq a) => [a] -> [a] -> Expectation infix 1 #
list `shouldNotContain` sublist
sets the expectation that sublist
is not
contained anywhere in list
.
shouldNotReturn :: (HasCallStack, Show a, Eq a) => IO a -> a -> Expectation infix 1 #
action `shouldNotReturn` notExpected
sets the expectation that action
does not return notExpected
.
shouldThrow :: (HasCallStack, Exception e) => IO a -> Selector e -> Expectation infix 1 #
action `shouldThrow` selector
sets the expectation that action
throws
an exception. The precise nature of the expected exception is described
with a Selector
.
integralLaws :: (Integral a, Arbitrary a, Show a) => Proxy a -> Laws #
Tests the following properties:
- Quotient Remainder
(quot x y) * y + (rem x y) ≡ x
- Division Modulus
(div x y) * y + (mod x y) ≡ x
- Integer Roundtrip
fromInteger (toInteger x) ≡ x
- QuotRem is (Quot, Rem)
quotRem x y ≡ (quot x y, rem x y)
- DivMod is (Div, Mod)
divMod x y ≡ (div x y, mod x y)
genericLaws :: (Generic a, Eq a, Arbitrary a, Show a, Show (Rep a ()), Arbitrary (Rep a ()), Eq (Rep a ())) => Proxy a -> Laws #
Tests the following properties:
Note: This property test is only available when
using base-4.5
or newer.
Note: from
and to
don't actually care about
the type variable x
in
, so here we instantiate
it to Rep
a x
by default. If you would like to instantiate ()
x
as something else, please file a bug report.
generic1Laws :: forall (f :: Type -> Type) proxy. (Generic1 f, Eq1 f, Arbitrary1 f, Show1 f, Eq1 (Rep1 f), Show1 (Rep1 f), Arbitrary1 (Rep1 f)) => proxy f -> Laws #
functorLaws :: forall (f :: Type -> Type) proxy. (Functor f, forall a. Eq a => Eq (f a), forall a. Show a => Show (f a), forall a. Arbitrary a => Arbitrary (f a)) => proxy f -> Laws #
foldableLaws :: forall proxy (f :: Type -> Type). (Foldable f, forall a. Eq a => Eq (f a), forall a. Show a => Show (f a), forall a. Arbitrary a => Arbitrary (f a)) => proxy f -> Laws #
Tests the following Foldable
properties:
- fold
fold
≡foldMap
id
- foldMap
foldMap
f ≡foldr
(mappend
. f)mempty
- foldr
foldr
f z t ≡appEndo
(foldMap
(Endo
. f) t ) z- foldr'
foldr'
f z0 xs ≡ let f' k x z = k$!
f x z infoldl
f'id
xs z0- foldr1
foldr1
f t ≡ letJust
(xs,x) =unsnoc
(toList
t) infoldr
f x xs- foldl
foldl
f z t ≡appEndo
(getDual
(foldMap
(Dual
.Endo
.flip
f) t)) z- foldl'
foldl'
f z0 xs ≡ let f' x k z = k$!
f z x infoldr
f'id
xs z0- foldl1
foldl1
f t ≡ let x : xs =toList
t infoldl
f x xs- toList
toList
≡foldr
(:) []- null
null
≡foldr
(const
(const
False
))True
- length
length
≡getSum
.foldMap
(const
(Sum
1))
Note that this checks to ensure that foldl'
and foldr'
are suitably strict.
eqLaws :: (Eq a, Arbitrary a, Show a) => Proxy a -> Laws #
Tests the following properties:
- Transitive
a
==
b ∧ b==
c ⇒ a==
c- Symmetric
a
==
b ⇒ b==
a- Reflexive
a
==
a- Negation
x
/=
y==
not
(x==
y)
Some of these properties involve implication. In the case that the left hand side of the implication arrow does not hold, we do not retry. Consequently, these properties only end up being useful when the data type has a small number of inhabitants.
substitutiveEqLaws :: (Eq a, Arbitrary a, CoArbitrary a, Function a, Show a) => Proxy a -> Laws #
enumLaws :: (Enum a, Eq a, Arbitrary a, Show a) => Proxy a -> Laws #
Tests the following properties:
This only works for Enum
types that are not bounded, meaning
that succ
and pred
must be total. This means that these property
tests work correctly for types like Integer
but not for Int
.
Sadly, there is not a good way to test fromEnum
and toEnum
,
since many types that have reasonable implementations for succ
and pred
have more inhabitants than Int
does.
contravariantLaws :: forall (f :: Type -> Type) proxy. (Contravariant f, forall a. Eq a => Eq (f a), forall a. Show a => Show (f a), forall a. Arbitrary a => Arbitrary (f a)) => proxy f -> Laws #
categoryLaws :: forall proxy (c :: Type -> Type -> Type). (Category c, forall a b. (Eq a, Eq b) => Eq (c a b), forall a b. (Show a, Show b) => Show (c a b), forall a b. (Arbitrary a, Arbitrary b) => Arbitrary (c a b)) => proxy c -> Laws #
commutativeCategoryLaws :: forall proxy (c :: Type -> Type -> Type). (Category c, forall a b. (Eq a, Eq b) => Eq (c a b), forall a b. (Show a, Show b) => Show (c a b), forall a b. (Arbitrary a, Arbitrary b) => Arbitrary (c a b)) => proxy c -> Laws #
Test everything from categoryLaws
plus the following:
Note: This property test is only available when this package is built with
base-4.9+
or transformers-0.5+
.
bitsLaws :: (FiniteBits a, Arbitrary a, Show a) => Proxy a -> Laws #
Tests the following properties:
- Conjunction Idempotence
n .&. n ≡ n
- Disjunction Idempotence
n .|. n ≡ n
- Double Complement
complement (complement n) ≡ n
- Set Bit
setBit n i ≡ n .|. bit i
- Clear Bit
clearBit n i ≡ n .&. complement (bit i)
- Complement Bit
complementBit n i ≡ xor n (bit i)
- Clear Zero
clearBit zeroBits i ≡ zeroBits
- Set Zero
setBit zeroBits i ≡ bit i
- Test Zero
testBit zeroBits i ≡ False
- Pop Zero
popCount zeroBits ≡ 0
- Right Rotation
no sign extension → (rotateR n i ≡ (shiftR n i) .|. (shiftL n (finiteBitSize ⊥ - i)))
- Left Rotation
no sign extension → (rotateL n i ≡ (shiftL n i) .|. (shiftR n (finiteBitSize ⊥ - i)))
- Count Leading Zeros of Zero
countLeadingZeros zeroBits ≡ finiteBitSize ⊥
- Count Trailing Zeros of Zero
countTrailingZeros zeroBits ≡ finiteBitSize ⊥
All of the useful instances of the Bits
typeclass
also have FiniteBits
instances, so these property
tests actually require that instance as well.
Note: This property test is only available when
using base-4.7
or newer.
bitraversableLaws :: forall proxy (f :: Type -> Type -> Type). (Bitraversable f, forall a b. (Eq a, Eq b) => Eq (f a b), forall a b. (Show a, Show b) => Show (f a b), forall a b. (Arbitrary a, Arbitrary b) => Arbitrary (f a b)) => proxy f -> Laws #
Tests the following Bitraversable
properties:
- Naturality
for every applicative transformationbitraverse
(t.
f) (t.
g) ≡ t.
bitraverse
f gt
- Identity
bitraverse
Identity
Identity
≡Identity
- Composition
Compose
.
fmap
(bitraverse
g1 g2).
bitraverse
f1 f2 ≡bitraverse
(Compose
.
fmap
g1 g2.
f1) (Compose
.
fmap
g2.
f2)
Note: This property test is only available when this package is built with
base-4.9+
or transformers-0.5+
.
bifunctorLaws :: forall proxy (f :: Type -> Type -> Type). (Bifunctor f, forall a b. (Eq a, Eq b) => Eq (f a b), forall a b. (Show a, Show b) => Show (f a b), forall a b. (Arbitrary a, Arbitrary b) => Arbitrary (f a b)) => proxy f -> Laws #
bifoldableLaws :: forall proxy (f :: Type -> Type -> Type). (Bifoldable f, forall a b. (Eq a, Eq b) => Eq (f a b), forall a b. (Show a, Show b) => Show (f a b), forall a b. (Arbitrary a, Arbitrary b) => Arbitrary (f a b)) => proxy f -> Laws #
Tests the following Bifunctor
properties:
- Bifold Identity
bifold
≡bifoldMap
id
id
- BifoldMap Identity
bifoldMap
f g ≡bifoldr
(mappend
.
f) (mappend
.
g)mempty
- Bifoldr Identity
bifoldr
f g z t ≡appEndo
(bifoldMap
(Endo
.
f) (Endo
.
g) t) z
Note: This property test is only available when this package is built with
base-4.10+
or transformers-0.5+
.
isListLaws :: (IsList a, Show a, Show (Item a), Arbitrary a, Arbitrary (Item a), Eq a) => Proxy a -> Laws #
Tests the following properties:
- Partial Isomorphism
fromList . toList ≡ id
- Length Preservation
fromList xs ≡ fromListN (length xs) xs
Note: This property test is only available when
using base-4.7
or newer.
applicativeLaws :: forall (f :: Type -> Type) proxy. (Applicative f, forall a. Eq a => Eq (f a), forall a. Show a => Show (f a), forall a. Arbitrary a => Arbitrary (f a)) => proxy f -> Laws #
alternativeLaws :: forall (f :: Type -> Type) proxy. (Alternative f, forall a. Eq a => Eq (f a), forall a. Show a => Show (f a), forall a. Arbitrary a => Arbitrary (f a)) => proxy f -> Laws #
monadLaws :: forall (f :: Type -> Type) proxy. (Monad f, Applicative f, forall a. Eq a => Eq (f a), forall a. Show a => Show (f a), forall a. Arbitrary a => Arbitrary (f a)) => proxy f -> Laws #
monadPlusLaws :: forall (f :: Type -> Type) proxy. (MonadPlus f, forall a. Eq a => Eq (f a), forall a. Show a => Show (f a), forall a. Arbitrary a => Arbitrary (f a)) => proxy f -> Laws #
monadZipLaws :: forall (f :: Type -> Type) proxy. (MonadZip f, forall a. Eq a => Eq (f a), forall a. Show a => Show (f a), forall a. Arbitrary a => Arbitrary (f a)) => proxy f -> Laws #
monoidLaws :: (Monoid a, Eq a, Arbitrary a, Show a) => Proxy a -> Laws #
Tests the following properties:
- Associative
mappend a (mappend b c) ≡ mappend (mappend a b) c
- Left Identity
mappend mempty a ≡ a
- Right Identity
mappend a mempty ≡ a
- Concatenation
mconcat as ≡ foldr mappend mempty as
commutativeMonoidLaws :: (Monoid a, Eq a, Arbitrary a, Show a) => Proxy a -> Laws #
Tests the following properties:
- Commutative
mappend a b ≡ mappend b a
Note that this does not test associativity or identity. Make sure to use
monoidLaws
in addition to this set of laws.
numLaws :: (Num a, Eq a, Arbitrary a, Show a) => Proxy a -> Laws #
Tests the following properties:
- Additive Commutativity
a + b ≡ b + a
- Additive Left Identity
0 + a ≡ a
- Additive Right Identity
a + 0 ≡ a
- Multiplicative Associativity
a * (b * c) ≡ (a * b) * c
- Multiplicative Left Identity
1 * a ≡ a
- Multiplicative Right Identity
a * 1 ≡ a
- Multiplication Left Distributes Over Addition
a * (b + c) ≡ (a * b) + (a * c)
- Multiplication Right Distributes Over Addition
(a + b) * c ≡ (a * c) + (b * c)
- Multiplicative Left Annihilation
0 * a ≡ 0
- Multiplicative Right Annihilation
a * 0 ≡ 0
- Additive Inverse
negate
a+
a ≡ 0- Subtraction
a
+
negate
b ≡ a-
b- Abs Is Idempotent
- @
abs
(abs
a) ≡abs
a - Signum Is Idempotent
- @
signum
(signum
a) ≡signum
a - Product Of Abs And Signum Is Id
abs
a *signum
a ≡ a
ordLaws :: (Ord a, Arbitrary a, Show a) => Proxy a -> Laws #
Tests the following properties:
- Antisymmetry
a ≤ b ∧ b ≤ a ⇒ a = b
- Transitivity
a ≤ b ∧ b ≤ c ⇒ a ≤ c
- Totality
a ≤ b ∨ a > b
commutativeSemigroupLaws :: (Semigroup a, Eq a, Arbitrary a, Show a) => Proxy a -> Laws #
Tests the following properties:
Note that this does not test associativity. Make sure to use
semigroupLaws
in addition to this set of laws.
idempotentSemigroupLaws :: (Semigroup a, Eq a, Arbitrary a, Show a) => Proxy a -> Laws #
Tests the following properties:
- Idempotent
a
<>
a ≡ a
Note that this does not test associativity. Make sure to use
semigroupLaws
in addition to this set of laws. In literature,
this class of semigroup is known as a band.
rectangularBandSemigroupLaws :: (Semigroup a, Eq a, Arbitrary a, Show a) => Proxy a -> Laws #
Tests the following properties:
Note that this does not test associativity. Make sure to use
semigroupLaws
in addition to this set of laws.
showReadLaws :: (Show a, Read a, Eq a, Arbitrary a) => Proxy a -> Laws #
Tests the following properties:
- Partial Isomorphism:
show
/read
readMaybe
(show
a) ≡Just
a- Partial Isomorphism:
show
/read
with initial space readMaybe
(" " ++show
a) ≡Just
a- Partial Isomorphism:
showsPrec
/readsPrec
(a,"") `elem`
readsPrec
p (showsPrec
p a "")- Partial Isomorphism:
showList
/readList
(as,"") `elem`
readList
(showList
as "")- Partial Isomorphism:
showListWith
shows
/readListDefault
(as,"") `elem`
readListDefault
(showListWith
shows
as "")
Note: When using base-4.5
or older, a shim implementation
of readMaybe
is used.
storableLaws :: (Storable a, Eq a, Arbitrary a, Show a) => Proxy a -> Laws #
Tests the following Storable
properties:
- Set-Get
(
pokeElemOff
ptr ix a >>peekElemOff
ptr ix') ≡pure
a- Get-Set
(
peekElemOff
ptr ix >>pokeElemOff
ptr ix a) ≡pure
a
traversableLaws :: forall (f :: Type -> Type) proxy. (Traversable f, forall a. Eq a => Eq (f a), forall a. Show a => Show (f a), forall a. Arbitrary a => Arbitrary (f a)) => proxy f -> Laws #
Tests the following Traversable
properties:
- Naturality
t
for every applicative transformation.
traverse
f ≡traverse
(t.
f)t
- Identity
traverse
Identity
≡Identity
- Composition
traverse
(Compose
.
fmap
g.
f) ≡Compose
.
fmap
(traverse
g).
traverse
f- Sequence Naturality
t
for every applicative transformation.
sequenceA
≡sequenceA
.
fmap
tt
- Sequence Identity
sequenceA
.
fmap
Identity
≡Identity
- Sequence Composition
sequenceA
.
fmap
Compose
≡Compose
.
fmap
sequenceA
.
sequenceA
- foldMap
foldMap
≡foldMapDefault
- fmap
fmap
≡fmapDefault
Where an applicative transformation is a function
t :: (Applicative f, Applicative g) => f a -> g a
preserving the Applicative
operations, i.e.
A convenience function for testing properties in GHCi. For example, at GHCi:
>>>
lawsCheck (monoidLaws (Proxy :: Proxy Ordering))
Monoid: Associative +++ OK, passed 100 tests. Monoid: Left Identity +++ OK, passed 100 tests. Monoid: Right Identity +++ OK, passed 100 tests.
Assuming that the Arbitrary
instance for Ordering
is good, we now
have confidence that the Monoid
instance for Ordering
satisfies
the monoid laws.
lawsCheckOne :: Proxy a -> [Proxy a -> Laws] -> IO () #
A convenience function that allows one to check many typeclass instances of the same type.
>>>
specialisedLawsCheckMany (Proxy :: Proxy Word) [jsonLaws, showReadLaws]
ToJSON/FromJSON: Encoding Equals Value +++ OK, passed 100 tests. ToJSON/FromJSON: Partial Isomorphism +++ OK, passed 100 tests. Show/Read: Partial Isomorphism +++ OK, passed 100 tests.
A convenience function for checking multiple typeclass instances of multiple types. Consider the following Haskell source file:
import Data.Proxy (Proxy(..)) import Data.Map (Map) import Data.Set (Set) -- AProxy
forSet
Int
. setInt :: Proxy (Set Int) setInt = Proxy -- AProxy
forMap
Int
Int
. mapInt :: Proxy (Map Int Int) mapInt = Proxy myLaws :: Proxy a -> [Laws] myLaws p = [eqLaws p, monoidLaws p] namedTests :: [(String, [Laws])] namedTests = [ ("Set Int", myLaws setInt) , ("Map Int Int", myLaws mapInt) ]
Now, in GHCi:
>>>
lawsCheckMany namedTests
Testing properties for common typeclasses ------------- -- Set Int -- ------------- Eq: Transitive +++ OK, passed 100 tests. Eq: Symmetric +++ OK, passed 100 tests. Eq: Reflexive +++ OK, passed 100 tests. Monoid: Associative +++ OK, passed 100 tests. Monoid: Left Identity +++ OK, passed 100 tests. Monoid: Right Identity +++ OK, passed 100 tests. Monoid: Concatenation +++ OK, passed 100 tests. ----------------- -- Map Int Int -- ----------------- Eq: Transitive +++ OK, passed 100 tests. Eq: Symmetric +++ OK, passed 100 tests. Eq: Reflexive +++ OK, passed 100 tests. Monoid: Associative +++ OK, passed 100 tests. Monoid: Left Identity +++ OK, passed 100 tests. Monoid: Right Identity +++ OK, passed 100 tests. Monoid: Concatenation +++ OK, passed 100 tests.
In the case of a failing test, the program terminates with exit code 1.