-- 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 1.0 -- | You need this module if you want to generate test values of your own -- types. -- -- You'll typically need the following extensions: -- --
-- {-# LANGUAGE FlexibleInstances, MultiParamTypeClasses #-}
--
--
-- SmallCheck itself defines data generators for all the data types used
-- by the Prelude.
--
-- In order to generate values and functions of your own types, you need
-- to make them instances of Serial (for values) and
-- CoSerial (for functions). There are two main ways to do so:
-- using Generics or writing the instances by hand.
module Test.SmallCheck.Series
cons0 :: a -> Series m a
cons1 :: Serial m a => (a -> b) -> Series m b
cons2 :: (Serial m a, Serial m b) => (a -> b -> c) -> Series m c
cons3 :: (Serial m a, Serial m b, Serial m c) => (a -> b -> c -> d) -> Series m d
cons4 :: (Serial m a, Serial m b, Serial m c, Serial m d) => (a -> b -> c -> d -> e) -> Series m e
-- | Same as cons1, but preserves the depth.
newtypeCons :: Serial m a => (a -> b) -> Series m b
alts0 :: Series m a -> Series m a
alts1 :: (Monad m, CoSerial m a) => Series m b -> Series m (a -> b)
alts2 :: (CoSerial m a, CoSerial m b) => Series m c -> Series m (a -> b -> c)
alts3 :: (CoSerial m a, CoSerial m b, CoSerial m c) => Series m d -> Series m (a -> b -> c -> d)
alts4 :: (CoSerial m a, CoSerial m b, CoSerial m c, CoSerial m d) => Series m e -> Series m (a -> b -> c -> d -> e)
-- | Same as alts1, but preserves the depth.
newtypeAlts :: (Monad m, CoSerial m a) => Series m b -> Series m (a -> b)
-- | 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 MonadLogic action that enumerates values of
-- a certain type, up to some depth.
--
-- The depth bound is tracked in the SC monad and can be
-- extracted using getDepth and changed using
-- localDepth.
--
-- To manipulate series at the lowest level you can use its Monad,
-- MonadPlus and MonadLogic instances. This module provides
-- some higher-level combinators which simplify creating series.
--
-- A proper Series should be monotonic with respect to the depth —
-- i.e. localDepth (+1) s should emit all the values that
-- s emits (and possibly some more).
--
-- It is also desirable that values of smaller depth come before the
-- values of greater depth.
data Series m a
class Monad m => Serial m a where series = to <$> gSeries
series :: Serial m a => Series m a
class Monad m => CoSerial m a where coseries rs = (. from) <$> gCoseries rs
coseries :: CoSerial m a => Series m b -> Series m (a -> b)
-- | Positive x: guarantees that x > 0.
newtype Positive a
Positive :: a -> Positive a
getPositive :: Positive a -> a
-- | NonNegative x: guarantees that x >= 0.
newtype NonNegative a
NonNegative :: a -> NonNegative a
getNonNegative :: NonNegative a -> a
-- | Sum (union) of series
(\/) :: Monad m => Series m a -> Series m a -> Series m a
-- | Product of series
(><) :: Monad m => Series m a -> Series m b -> Series m (a, b)
-- | Fair version of ap and <*>
(<~>) :: Monad m => Series m (a -> b) -> Series m a -> Series m b
-- | Fair conjunction. Similarly to the previous function, consider the
-- distributivity law for MonadPlus:
--
-- -- (mplus a b) >>= k = (a >>= k) `mplus` (b >>= k) ---- -- If 'a >>= k' can backtrack arbitrarily many tmes, (b >>= -- k) may never be considered. (>>-) takes similar care to consider -- both branches of a disjunctive computation. (>>-) :: MonadLogic m => forall a b. m a -> (a -> m b) -> m b -- | Run a series with a modified depth localDepth :: (Depth -> Depth) -> Series m a -> Series m a -- | Run a Series with the depth decreased by 1. -- -- If the current depth is less or equal to 0, the result is -- mzero. decDepth :: Series m a -> Series m a -- | Query the current depth getDepth :: Series m Depth -- | A simple series specified by a function from depth to the list of -- values up to that depth. generate :: (Depth -> [a]) -> Series m a -- | Return the list of values generated by a Series. Useful for -- debugging Serial instances. list :: Depth -> Series Identity a -> [a] instance Eq a => Eq (N a) instance Ord a => Ord (N a) instance Real a => Real (N a) instance Enum a => Enum (N a) instance Num a => Num (N a) instance Integral a => Integral (N a) instance Eq a => Eq (Positive a) instance Ord a => Ord (Positive a) instance Num a => Num (Positive a) instance Integral a => Integral (Positive a) instance Real a => Real (Positive a) instance Enum a => Enum (Positive a) instance Eq a => Eq (NonNegative a) instance Ord a => Ord (NonNegative a) instance Num a => Num (NonNegative a) instance Integral a => Integral (NonNegative a) instance Real a => Real (NonNegative a) instance Enum a => Enum (NonNegative a) instance Show a => Show (NonNegative a) instance (Num a, Ord a, Serial m a) => Serial m (NonNegative a) instance Show a => Show (Positive a) instance (Num a, Ord a, Serial m a) => Serial m (Positive a) instance (Serial Identity a, Show a, Show b) => Show (a -> b) instance (Serial m a, CoSerial m a, Serial m b, CoSerial m b, Monad m) => CoSerial m (a -> b) instance (CoSerial m a, Serial m b, Monad m) => Serial m (a -> b) instance CoSerial m a => CoSerial m [a] instance Serial m a => Serial m [a] instance (Monad m, CoSerial m a, CoSerial m b) => CoSerial m (Either a b) instance (Monad m, Serial m a, Serial m b) => Serial m (Either a b) instance (Monad m, CoSerial m a) => CoSerial m (Maybe a) instance (Monad m, Serial m a) => Serial m (Maybe a) instance Monad m => CoSerial m Bool instance Monad m => Serial m Bool instance (Monad m, CoSerial m a, CoSerial m b, CoSerial m c, CoSerial m d) => CoSerial m (a, b, c, d) instance (Monad m, Serial m a, Serial m b, Serial m c, Serial m d) => Serial m (a, b, c, d) instance (Monad m, CoSerial m a, CoSerial m b, CoSerial m c) => CoSerial m (a, b, c) instance (Monad m, Serial m a, Serial m b, Serial m c) => Serial m (a, b, c) instance (Monad m, CoSerial m a, CoSerial m b) => CoSerial m (a, b) instance (Monad m, Serial m a, Serial m b) => Serial m (a, b) instance Monad m => CoSerial m Char instance Monad m => Serial m Char instance Monad m => CoSerial m Double instance Monad m => Serial m Double instance Monad m => CoSerial m Float instance Monad m => Serial m Float instance (Integral a, Serial m a) => CoSerial m (N a) instance (Integral a, Serial m a) => Serial m (N a) instance Monad m => CoSerial m Integer instance Monad m => Serial m Integer instance Monad m => CoSerial m Int instance Monad m => Serial m Int instance Monad m => CoSerial m () instance Monad m => Serial m () instance (Monad m, GCoSerial m a, GCoSerial m b) => GCoSerial m (a :+: b) instance (Monad m, GSerial m a, GSerial m b) => GSerial m (a :+: b) instance (Monad m, GCoSerial m a, GCoSerial m b) => GCoSerial m (a :*: b) instance (Monad m, GSerial m a, GSerial m b) => GSerial m (a :*: b) instance GCoSerial m U1 instance GSerial m U1 instance CoSerial m c => GCoSerial m (K1 i c) instance Serial m c => GSerial m (K1 i c) instance GCoSerial m f => GCoSerial m (M1 i c f) instance GSerial m f => GSerial m (M1 i c f) -- | You should only need this module if you wish to create your own way to -- run SmallCheck tests module Test.SmallCheck.Drivers -- | A simple driver that runs the test in the IO monad and prints -- the results. smallCheck :: Testable IO a => Depth -> a -> IO () -- | Use this if: -- --