-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | A property-based testing library -- -- SmallCheck is a testing library that allows to verify properties for -- all test cases up to some depth. The test cases are generated -- automatically by SmallCheck. @package smallcheck @version 0.6 -- | Generation of test data. module Test.SmallCheck.Series -- | Maximum depth of generated test values -- -- For data values, it is the depth of nested constructor applications. -- -- For functional values, it is both the depth of nested case analysis -- and the depth of results. type Depth = Int -- | Series is a function from the depth to a finite list of values. type Series a = Depth -> [a] class Serial a series :: Serial a => Series a coseries :: Serial a => Series b -> Series (a -> b) cons0 :: a -> Series a cons1 :: Serial a => (a -> b) -> Series b cons2 :: (Serial a, Serial b) => (a -> b -> c) -> Series c cons3 :: (Serial a, Serial b, Serial c) => (a -> b -> c -> d) -> Series d cons4 :: (Serial a, Serial b, Serial c, Serial d) => (a -> b -> c -> d -> e) -> Series e alts0 :: Series a -> Series a alts1 :: Serial a => Series b -> Series (a -> b) alts2 :: (Serial a, Serial b) => Series c -> Series (a -> b -> c) alts3 :: (Serial a, Serial b, Serial c) => Series d -> Series (a -> b -> c -> d) alts4 :: (Serial a, Serial b, Serial c, Serial d) => Series e -> Series (a -> b -> c -> d -> e) -- | Sum (union) of series (\/) :: Series a -> Series a -> Series a -- | Product of series (><) :: Series a -> Series b -> Series (a, b) -- | N is a wrapper for Integral types that causes only -- non-negative values to be generated. Generated functions of type N -- a -> b do not distinguish different negative values of -- a. -- -- See also Nat and Natural. newtype N a N :: a -> N a type Nat = N Int type Natural = N Integer -- | For customising the depth measure. Use with care! depth :: Depth -> Depth -> Depth instance Eq a => Eq (N a) instance Ord a => Ord (N a) instance (Serial a, Show a, Show b) => Show (a -> b) instance (Serial a, Serial b) => Serial (a -> b) instance Serial a => Serial [a] instance (Serial a, Serial b) => Serial (Either a b) instance Serial a => Serial (Maybe a) instance Serial Bool instance (Serial a, Serial b, Serial c, Serial d) => Serial (a, b, c, d) instance (Serial a, Serial b, Serial c) => Serial (a, b, c) instance (Serial a, Serial b) => Serial (a, b) instance Serial Char instance Serial Double instance Serial Float instance (Integral a, Serial a) => Serial (N a) instance Show a => Show (N a) instance Serial Integer instance Serial Int instance Serial () instance GSerial f => GSerialSum (C1 c f) instance (GSerialSum a, GSerialSum b) => GSerialSum (a :+: b) instance (GSerialSum a, GSerialSum b) => GSerial (a :+: b) instance (GSerial a, GSerial b) => GSerial (a :*: b) instance GSerial U1 instance Serial c => GSerial (K1 i c) instance GSerial f => GSerial (M1 i c f) -- | Properties and tools to construct them. module Test.SmallCheck.Property data TestCase TestCase :: TestResult -> [String] -> TestCase result :: TestCase -> TestResult arguments :: TestCase -> [String] data TestResult Pass :: TestResult Fail :: TestResult -- | Inappropriate means that the precondition of ==> was -- not satisfied Inappropriate :: TestResult -- | Return False iff the result is Fail resultIsOk :: TestResult -> Bool -- | Wrapper type for Testables data Property -- | Maximum depth of generated test values -- -- For data values, it is the depth of nested constructor applications. -- -- For functional values, it is both the depth of nested case analysis -- and the depth of results. type Depth = Int -- | Anything of a Testable type can be regarded as a "test" class Testable a test :: Testable a => a -> Depth -> [TestCase] -- | Wrap a Testable into a Property property :: Testable a => a -> Property -- | A lower-level way to create properties. Use property if -- possible. -- -- The argument is a function that produces the list of results given the -- depth of testing. mkProperty :: (Depth -> [TestCase]) -> Property -- | The ==> operator can be used to express a restricting -- condition under which a property should hold. For example, testing a -- propositional-logic module (see examples/logical), we might define: -- --
-- prop_tautEval :: Proposition -> Environment -> Property -- prop_tautEval p e = -- tautology p ==> eval p e ---- -- But here is an alternative definition: -- --
-- prop_tautEval :: Proposition -> Property -- prop_taut p = -- tautology p ==> \e -> eval p e ---- -- The first definition generates p and e for each test, whereas the -- second only generates e if the tautology p holds. -- -- The second definition is far better as the test-space is reduced from -- PE to T'+TE where P, T, T' and E are the numbers of propositions, -- tautologies, non-tautologies and environments. (==>) :: Testable a => Bool -> a -> Property -- | exists p holds iff it is possible to find an argument -- a (within the depth constraints!) satisfying the predicate -- p exists :: (Show a, Serial a, Testable b) => (a -> b) -> Property -- | The default testing of existentials is bounded by the same depth as -- their context. This rule has important consequences. Just as a -- universal property may be satisfied when the depth bound is shallow -- but fail when it is deeper, so the reverse may be true for an -- existential property. So when testing properties involving -- existentials it may be appropriate to try deeper testing after a -- shallow failure. However, sometimes the default same-depth-bound -- interpretation of existential properties can make testing of a valid -- property fail at all depths. Here is a contrived but illustrative -- example: -- --
-- prop_append1 :: [Bool] -> [Bool] -> Property -- prop_append1 xs ys = exists $ \zs -> zs == xs++ys ---- -- existsDeeperBy transforms the depth bound by a given -- Depth -> Depth function: -- --
-- prop_append2 :: [Bool] -> [Bool] -> Property -- prop_append2 xs ys = existsDeeperBy (*2) $ \zs -> zs == xs++ys --existsDeeperBy :: (Show a, Serial a, Testable b) => (Depth -> Depth) -> (a -> b) -> Property -- | Like exists, but additionally require the uniqueness of the -- argument satisfying the predicate exists1 :: (Show a, Serial a, Testable b) => (a -> b) -> Property -- | Like existsDeeperBy, but additionally require the uniqueness of -- the argument satisfying the predicate exists1DeeperBy :: (Show a, Serial a, Testable b) => (Depth -> Depth) -> (a -> b) -> Property forAll :: (Show a, Testable b) => Series a -> (a -> b) -> Property forAllElem :: (Show a, Testable b) => [a] -> (a -> b) -> Property thereExists :: (Show a, Testable b) => Series a -> (a -> b) -> Property thereExistsElem :: (Show a, Testable b) => [a] -> (a -> b) -> Property thereExists1 :: (Show a, Testable b) => Series a -> (a -> b) -> Property thereExists1Elem :: (Show a, Testable b) => [a] -> (a -> b) -> Property instance Testable Property instance (Serial a, Show a, Testable b) => Testable (a -> b) instance Testable Bool -- | Functions to run SmallCheck tests. module Test.SmallCheck.Drivers -- | Run series of tests using depth bounds 0..d, stopping if any test -- fails, and print a summary report or a counter-example. smallCheck :: Testable a => Depth -> a -> IO () -- | Interactive variant, asking the user whether testing should -- continue/go deeper after a failure/completed iteration. -- -- Example session: -- --
-- haskell> smallCheckI prop_append1 -- Depth 0: -- Completed 1 test(s) without failure. -- Deeper? y -- Depth 1: -- Failed test no. 5. Test values follow. -- [True] -- [True] -- Continue? n -- Deeper? n -- haskell> --smallCheckI :: Testable a => a -> IO () -- | Same as smallCheck, but test for values of depth d only depthCheck :: Testable a => Depth -> a -> IO () -- | This module exports the main pieces of SmallCheck functionality. -- -- For pointers to other sources of information about SmallCheck, please -- refer to the README at -- https://github.com/feuerbach/smallcheck/blob/master/README.md module Test.SmallCheck -- | Anything of a Testable type can be regarded as a "test" class Testable a -- | Wrapper type for Testables data Property -- | Wrap a Testable into a Property property :: Testable a => a -> Property -- | exists p holds iff it is possible to find an argument -- a (within the depth constraints!) satisfying the predicate -- p exists :: (Show a, Serial a, Testable b) => (a -> b) -> Property -- | Like exists, but additionally require the uniqueness of the -- argument satisfying the predicate exists1 :: (Show a, Serial a, Testable b) => (a -> b) -> Property -- | The default testing of existentials is bounded by the same depth as -- their context. This rule has important consequences. Just as a -- universal property may be satisfied when the depth bound is shallow -- but fail when it is deeper, so the reverse may be true for an -- existential property. So when testing properties involving -- existentials it may be appropriate to try deeper testing after a -- shallow failure. However, sometimes the default same-depth-bound -- interpretation of existential properties can make testing of a valid -- property fail at all depths. Here is a contrived but illustrative -- example: -- --
-- prop_append1 :: [Bool] -> [Bool] -> Property -- prop_append1 xs ys = exists $ \zs -> zs == xs++ys ---- -- existsDeeperBy transforms the depth bound by a given -- Depth -> Depth function: -- --
-- prop_append2 :: [Bool] -> [Bool] -> Property -- prop_append2 xs ys = existsDeeperBy (*2) $ \zs -> zs == xs++ys --existsDeeperBy :: (Show a, Serial a, Testable b) => (Depth -> Depth) -> (a -> b) -> Property -- | Like existsDeeperBy, but additionally require the uniqueness of -- the argument satisfying the predicate exists1DeeperBy :: (Show a, Serial a, Testable b) => (Depth -> Depth) -> (a -> b) -> Property -- | The ==> operator can be used to express a restricting -- condition under which a property should hold. For example, testing a -- propositional-logic module (see examples/logical), we might define: -- --
-- prop_tautEval :: Proposition -> Environment -> Property -- prop_tautEval p e = -- tautology p ==> eval p e ---- -- But here is an alternative definition: -- --
-- prop_tautEval :: Proposition -> Property -- prop_taut p = -- tautology p ==> \e -> eval p e ---- -- The first definition generates p and e for each test, whereas the -- second only generates e if the tautology p holds. -- -- The second definition is far better as the test-space is reduced from -- PE to T'+TE where P, T, T' and E are the numbers of propositions, -- tautologies, non-tautologies and environments. (==>) :: Testable a => Bool -> a -> Property -- | Run series of tests using depth bounds 0..d, stopping if any test -- fails, and print a summary report or a counter-example. smallCheck :: Testable a => Depth -> a -> IO () -- | Same as smallCheck, but test for values of depth d only depthCheck :: Testable a => Depth -> a -> IO () -- | Interactive variant, asking the user whether testing should -- continue/go deeper after a failure/completed iteration. -- -- Example session: -- --
-- haskell> smallCheckI prop_append1 -- Depth 0: -- Completed 1 test(s) without failure. -- Deeper? y -- Depth 1: -- Failed test no. 5. Test values follow. -- [True] -- [True] -- Continue? n -- Deeper? n -- haskell> --smallCheckI :: Testable a => a -> IO () -- | Maximum depth of generated test values -- -- For data values, it is the depth of nested constructor applications. -- -- For functional values, it is both the depth of nested case analysis -- and the depth of results. type Depth = Int