smallcheck-1.1.7/Test/0000755000000000000000000000000013670251014012732 5ustar0000000000000000smallcheck-1.1.7/Test/SmallCheck/0000755000000000000000000000000013670525167014755 5ustar0000000000000000smallcheck-1.1.7/Test/SmallCheck/Property/0000755000000000000000000000000013670246521016573 5ustar0000000000000000smallcheck-1.1.7/Test/SmallCheck.hs0000644000000000000000000000631513670251014015301 0ustar0000000000000000-------------------------------------------------------------------- -- | -- Module : Test.SmallCheck -- Copyright : (c) Colin Runciman et al. -- License : BSD3 -- Maintainer: Roman Cheplyaka -- -- This module exports the main pieces of SmallCheck functionality. -- -- To generate test cases for your own types, refer to -- "Test.SmallCheck.Series". -- -- For pointers to other sources of information about SmallCheck, please refer -- to the README at -- -------------------------------------------------------------------- {-# LANGUAGE Safe #-} module Test.SmallCheck ( -- * Constructing tests -- | The simplest kind of test is a function (possibly of many -- arguments) returning 'Bool'. The function arguments are interpreted -- as being universally, existentially or uniquely quantified, depending -- on the quantification context. -- -- The default quantification context is universal ('forAll'). -- -- 'forAll', 'exists' and 'existsUnique' functions set the quantification -- context for function arguments. Depending on the quantification -- context, the test @\\x y -> p x y@ may be equivalent to: -- -- * ∀ x, y. p x y ('forAll') -- -- * ∃ x, y: p x y ('exists') -- -- * ∃! x, y: p x y ('existsUnique') -- -- The quantification context affects all the variables immediately -- following the quantification operator, also extending past 'over', -- 'changeDepth' and 'changeDepth1' functions. -- -- However, it doesn't extend past other functions, like 'monadic', and -- doesn't affect the operands of '==>'. Such functions start a fresh -- default quantification context. -- ** Examples -- | -- * @\\x y -> p x y@ means ∀ x, y. p x y -- -- * @'exists' $ \\x y -> p x y@ means ∃ x, y: p x y -- -- * @'exists' $ \\x -> 'forAll' $ \\y -> p x y@ means ∃ x: ∀ y. p x y -- -- * @'existsUnique' $ \\x y -> p x y@ means ∃! (x, y): p x y -- -- * @'existsUnique' $ \\x -> 'over' s $ \\y -> p x y@ means ∃! (x, y): y ∈ s && p x y -- -- * @'existsUnique' $ \\x -> 'monadic' $ \\y -> p x y@ means ∃! x: ∀ y. [p x y] -- -- * @'existsUnique' $ \\x -> 'existsUnique' $ \\y -> p x y@ means ∃! x: ∃! y: p x y -- -- * @'exists' $ \\x -> (\\y -> p y) '==>' (\\z -> q z)@ means ∃ x: (∀ y. p y) => (∀ z. p z) forAll, exists, existsUnique, over, monadic, (==>), changeDepth, changeDepth1, -- * Running tests -- | 'smallCheck' is a simple way to run a test. -- -- As an alternative, consider using a testing framework. -- -- The packages -- and -- -- provide integration with Tasty and HSpec, two popular testing -- frameworks. -- -- They allow to organize SmallCheck properties into a test suite (possibly -- together with HUnit or QuickCheck tests) and provide other useful -- features. -- -- For more ways to run the tests, see "Test.SmallCheck.Drivers". Depth, smallCheck, -- * Main types and classes Testable(..), Property, Reason ) where import Test.SmallCheck.Property import Test.SmallCheck.Drivers smallcheck-1.1.7/Test/SmallCheck/Drivers.hs0000644000000000000000000000517713670246521016733 0ustar0000000000000000-------------------------------------------------------------------- -- | -- Module : Test.SmallCheck.Drivers -- Copyright : (c) Colin Runciman et al. -- License : BSD3 -- Maintainer: Roman Cheplyaka -- -- You should only need this module if you wish to create your own way to -- run SmallCheck tests -------------------------------------------------------------------- {-# LANGUAGE FlexibleContexts #-} {-# LANGUAGE Safe #-} module Test.SmallCheck.Drivers ( smallCheck, smallCheckM, smallCheckWithHook, test, ppFailure, PropertyFailure(..), PropertySuccess(..), Argument, Reason, TestQuality(..) ) where import Control.Monad (when) import Test.SmallCheck.Property import Test.SmallCheck.Property.Result import Text.Printf (printf) import Data.IORef (readIORef, writeIORef, IORef, newIORef) -- NB: explicit import list to avoid name clash with modifyIORef' -- | A simple driver that runs the test in the 'IO' monad and prints the -- results. smallCheck :: Testable IO a => Depth -> a -> IO () smallCheck d a = do ((good, bad), mbEx) <- runTestWithStats d a let testsRun = good + bad case mbEx of Nothing -> do printf "Completed %d tests without failure.\n" testsRun when (bad > 0) $ printf "But %d did not meet ==> condition.\n" bad Just x -> do printf "Failed test no. %d.\n" testsRun putStrLn $ ppFailure x runTestWithStats :: Testable IO a => Depth -> a -> IO ((Integer, Integer), Maybe PropertyFailure) runTestWithStats d prop = do good <- newIORef 0 bad <- newIORef 0 let hook GoodTest = modifyIORef' good (+1) hook BadTest = modifyIORef' bad (+1) r <- smallCheckWithHook d hook prop goodN <- readIORef good badN <- readIORef bad return ((goodN, badN), r) -- NB: modifyIORef' is in base starting at least from GHC 7.6.1. -- -- So get rid of this once 7.6.1 becomes widely adopted. modifyIORef' :: IORef a -> (a -> a) -> IO () modifyIORef' ref f = do x <- readIORef ref let x' = f x x' `seq` writeIORef ref x' -- | Use this if: -- -- * You need to run a test in a monad different from 'IO' -- -- * You need to analyse the results rather than just print them smallCheckM :: Testable m a => Depth -> a -> m (Maybe PropertyFailure) smallCheckM d = smallCheckWithHook d (const $ return ()) -- | Like `smallCheckM`, but allows to specify a monadic hook that gets -- executed after each test is run. -- -- Useful for applications that want to report progress information to the -- user. smallCheckWithHook :: Testable m a => Depth -> (TestQuality -> m ()) -> a -> m (Maybe PropertyFailure) smallCheckWithHook d hook a = runProperty d hook $ test a smallcheck-1.1.7/Test/SmallCheck/Series.hs0000644000000000000000000006240113670525167016546 0ustar0000000000000000-- vim:fdm=marker:foldtext=foldtext() -------------------------------------------------------------------- -- | -- Module : Test.SmallCheck.Series -- Copyright : (c) Colin Runciman et al. -- License : BSD3 -- Maintainer: Roman Cheplyaka -- -- 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. -------------------------------------------------------------------- {-# LANGUAGE CPP #-} {-# LANGUAGE DefaultSignatures #-} {-# LANGUAGE FlexibleContexts #-} {-# LANGUAGE FlexibleInstances #-} {-# LANGUAGE MultiParamTypeClasses #-} {-# LANGUAGE RankNTypes #-} {-# LANGUAGE ScopedTypeVariables #-} {-# LANGUAGE TypeOperators #-} #if MIN_VERSION_base(4,8,0) {-# LANGUAGE Safe #-} #else {-# LANGUAGE OverlappingInstances #-} {-# LANGUAGE Trustworthy #-} #endif module Test.SmallCheck.Series ( -- {{{ -- * Generic instances -- | The easiest way to create the necessary instances is to use GHC -- generics (available starting with GHC 7.2.1). -- -- Here's a complete example: -- -- >{-# LANGUAGE FlexibleInstances, MultiParamTypeClasses #-} -- >{-# LANGUAGE DeriveGeneric #-} -- > -- >import Test.SmallCheck.Series -- >import GHC.Generics -- > -- >data Tree a = Null | Fork (Tree a) a (Tree a) -- > deriving Generic -- > -- >instance Serial m a => Serial m (Tree a) -- -- Here we enable the @DeriveGeneric@ extension which allows to derive 'Generic' -- instance for our data type. Then we declare that @Tree a@ is an instance of -- 'Serial', but do not provide any definitions. This causes GHC to use the -- default definitions that use the 'Generic' instance. -- -- One minor limitation of generic instances is that there's currently no -- way to distinguish newtypes and datatypes. Thus, newtype constructors -- will also count as one level of depth. -- * Data Generators -- | Writing 'Serial' instances for application-specific types is -- straightforward. You need to define a 'series' generator, typically using -- @consN@ family of generic combinators where N is constructor arity. -- -- For example: -- -- >data Tree a = Null | Fork (Tree a) a (Tree a) -- > -- >instance Serial m a => Serial m (Tree a) where -- > series = cons0 Null \/ cons3 Fork -- -- For newtypes use 'newtypeCons' instead of 'cons1'. -- The difference is that 'cons1' is counts as one level of depth, while -- 'newtypeCons' doesn't affect the depth. -- -- >newtype Light a = Light a -- > -- >instance Serial m a => Serial m (Light a) where -- > series = newtypeCons Light -- -- For data types with more than 4 fields define @consN@ as -- -- >consN f = decDepth $ -- > f <$> series -- > <~> series -- > <~> series -- > <~> ... {- series repeated N times in total -} -- ** What does consN do, exactly? -- | @consN@ has type -- @(Serial t_1, ..., Serial t_N) => (t_1 -> ... -> t_N -> t) -> Series t@. -- -- @consN f@ is a series which, for a given depth @d > 0@, produces values of the -- form -- -- >f x_1 ... x_N -- -- where @x_i@ ranges over all values of type @t_i@ of depth up to @d-1@ -- (as defined by the 'series' functions for @t_i@). -- -- @consN@ functions also ensure that x_i are enumerated in the -- breadth-first order. Thus, combinations of smaller depth come first -- (assuming the same is true for @t_i@). -- -- If @d <= 0@, no values are produced. cons0, cons1, cons2, cons3, cons4, newtypeCons, -- * Function Generators -- | To generate functions of an application-specific argument type, -- make the type an instance of 'CoSerial'. -- -- Again there is a standard pattern, this time using the altsN -- combinators where again N is constructor arity. Here are @Tree@ and -- @Light@ instances: -- -- -- >instance CoSerial m a => CoSerial m (Tree a) where -- > coseries rs = -- > alts0 rs >>- \z -> -- > alts3 rs >>- \f -> -- > return $ \t -> -- > case t of -- > Null -> z -- > Fork t1 x t2 -> f t1 x t2 -- -- >instance CoSerial m a => CoSerial m (Light a) where -- > coseries rs = -- > newtypeAlts rs >>- \f -> -- > return $ \l -> -- > case l of -- > Light x -> f x -- -- For data types with more than 4 fields define @altsN@ as -- -- >altsN rs = do -- > rs <- fixDepth rs -- > decDepthChecked -- > (constM $ constM $ ... $ constM rs) -- > (coseries $ coseries $ ... $ coseries rs) -- > {- constM and coseries are repeated N times each -} -- ** What does altsN do, exactly? -- | @altsN@ has type -- @(Serial t_1, ..., Serial t_N) => Series t -> Series (t_1 -> ... -> t_N -> t)@. -- -- @altsN s@ is a series which, for a given depth @d@, produces functions of -- type -- -- >t_1 -> ... -> t_N -> t -- -- If @d <= 0@, these are constant functions, one for each value produced -- by @s@. -- -- If @d > 0@, these functions inspect each of their arguments up to the depth -- @d-1@ (as defined by the 'coseries' functions for the corresponding -- types) and return values produced by @s@. The depth to which the -- values are enumerated does not depend on the depth of inspection. alts0, alts1, alts2, alts3, alts4, newtypeAlts, -- * Basic definitions Depth, Series, Serial(..), CoSerial(..), -- * Generic implementations genericSeries, genericCoseries, -- * Convenient wrappers Positive(..), NonNegative(..), NonEmpty(..), -- * Other useful definitions (\/), (><), (<~>), (>>-), localDepth, decDepth, getDepth, generate, limit, listSeries, list, listM, fixDepth, decDepthChecked, constM -- }}} ) where import Control.Monad (liftM, guard, mzero, mplus, msum) import Control.Monad.Logic (MonadLogic, (>>-), interleave, msplit, observeAllT) import Control.Monad.Reader (ask, local) import Control.Applicative (empty, pure, (<$>)) import Control.Monad.Identity (Identity(..)) import Data.Int (Int, Int8, Int16, Int32, Int64) import Data.List (intercalate) import Data.Ratio (Ratio, numerator, denominator, (%)) import Data.Word (Word, Word8, Word16, Word32, Word64) import Numeric.Natural (Natural) import Test.SmallCheck.SeriesMonad import GHC.Generics (Generic, (:+:)(..), (:*:)(..), C1, K1(..), M1(..), U1(..), Rep, to, from) ------------------------------ -- Main types and classes ------------------------------ --{{{ class Monad m => Serial m a where series :: Series m a default series :: (Generic a, GSerial m (Rep a)) => Series m a series = genericSeries genericSeries :: (Monad m, Generic a, GSerial m (Rep a)) => Series m a genericSeries = to <$> gSeries class Monad m => CoSerial m a where -- | A proper 'coseries' implementation should pass the depth unchanged to -- its first argument. Doing otherwise will make enumeration of curried -- functions non-uniform in their arguments. coseries :: Series m b -> Series m (a->b) default coseries :: (Generic a, GCoSerial m (Rep a)) => Series m b -> Series m (a->b) coseries = genericCoseries genericCoseries :: (Monad m, Generic a, GCoSerial m (Rep a)) => Series m b -> Series m (a->b) genericCoseries rs = (. from) <$> gCoseries rs -- }}} ------------------------------ -- Helper functions ------------------------------ -- {{{ -- | A simple series specified by a function from depth to the list of -- values up to that depth. generate :: (Depth -> [a]) -> Series m a generate f = do d <- getDepth msum $ map return $ f d -- | Limit a 'Series' to its first @n@ elements limit :: forall m a . Monad m => Int -> Series m a -> Series m a limit n0 (Series s) = Series $ go n0 s where go :: MonadLogic ml => Int -> ml b -> ml b go 0 _ = mzero go n mb1 = do cons :: Maybe (b, ml b) <- msplit mb1 case cons of Nothing -> mzero Just (b, mb2) -> return b `mplus` go (n-1) mb2 suchThat :: Series m a -> (a -> Bool) -> Series m a suchThat s p = s >>= \x -> if p x then pure x else empty -- | Given a depth, return the list of values generated by a Serial instance. -- -- Example, list all integers up to depth 1: -- -- * @listSeries 1 :: [Int] -- returns [0,1,-1]@ listSeries :: Serial Identity a => Depth -> [a] listSeries d = list d series -- | Return the list of values generated by a 'Series'. Useful for -- debugging 'Serial' instances. -- -- Examples: -- -- * @list 3 'series' :: [Int] -- returns [0,1,-1,2,-2,3,-3]@ -- -- * @list 3 ('series' :: 'Series' 'Identity' Int) -- returns [0,1,-1,2,-2,3,-3]@ -- -- * @list 2 'series' :: [[Bool]] -- returns [[],[True],[False]]@ -- -- The first two are equivalent. The second has a more explicit type binding. list :: Depth -> Series Identity a -> [a] list d s = runIdentity $ observeAllT $ runSeries d s -- | Monadic version of 'list' listM :: Monad m => Depth -> Series m a -> m [a] listM d s = observeAllT $ runSeries d s -- | Sum (union) of series infixr 7 \/ (\/) :: Monad m => Series m a -> Series m a -> Series m a (\/) = interleave -- | Product of series infixr 8 >< (><) :: Monad m => Series m a -> Series m b -> Series m (a,b) a >< b = (,) <$> a <~> b -- | Fair version of 'ap' and '<*>' infixl 4 <~> (<~>) :: Monad m => Series m (a -> b) -> Series m a -> Series m b a <~> b = a >>- (<$> b) uncurry3 :: (a->b->c->d) -> ((a,b,c)->d) uncurry3 f (x,y,z) = f x y z uncurry4 :: (a->b->c->d->e) -> ((a,b,c,d)->e) uncurry4 f (w,x,y,z) = f w x y z -- | Query the current depth getDepth :: Series m Depth getDepth = Series ask -- | Run a series with a modified depth localDepth :: (Depth -> Depth) -> Series m a -> Series m a localDepth f (Series a) = Series $ local f 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 decDepth a = do checkDepth localDepth (subtract 1) a checkDepth :: Series m () checkDepth = do d <- getDepth guard $ d > 0 -- | @'constM' = 'liftM' 'const'@ constM :: Monad m => m b -> m (a -> b) constM = liftM const -- | Fix the depth of a series at the current level. The resulting series -- will no longer depend on the \"ambient\" depth. fixDepth :: Series m a -> Series m (Series m a) fixDepth s = getDepth >>= \d -> return $ localDepth (const d) s -- | If the current depth is 0, evaluate the first argument. Otherwise, -- evaluate the second argument with decremented depth. decDepthChecked :: Series m a -> Series m a -> Series m a decDepthChecked b r = do d <- getDepth if d <= 0 then b else decDepth r unwind :: MonadLogic m => m a -> m [a] unwind a = msplit a >>= maybe (return []) (\(x,a') -> (x:) `liftM` unwind a') -- }}} ------------------------------ -- cons* and alts* functions ------------------------------ -- {{{ cons0 :: a -> Series m a cons0 x = decDepth $ pure x cons1 :: Serial m a => (a->b) -> Series m b cons1 f = decDepth $ f <$> series -- | Same as 'cons1', but preserves the depth. newtypeCons :: Serial m a => (a->b) -> Series m b newtypeCons f = f <$> series cons2 :: (Serial m a, Serial m b) => (a->b->c) -> Series m c cons2 f = decDepth $ f <$> series <~> series cons3 :: (Serial m a, Serial m b, Serial m c) => (a->b->c->d) -> Series m d cons3 f = decDepth $ f <$> series <~> series <~> series cons4 :: (Serial m a, Serial m b, Serial m c, Serial m d) => (a->b->c->d->e) -> Series m e cons4 f = decDepth $ f <$> series <~> series <~> series <~> series alts0 :: Series m a -> Series m a alts0 s = s alts1 :: CoSerial m a => Series m b -> Series m (a->b) alts1 rs = do rs <- fixDepth rs decDepthChecked (constM rs) (coseries rs) alts2 :: (CoSerial m a, CoSerial m b) => Series m c -> Series m (a->b->c) alts2 rs = do rs <- fixDepth rs decDepthChecked (constM $ constM rs) (coseries $ coseries rs) alts3 :: (CoSerial m a, CoSerial m b, CoSerial m c) => Series m d -> Series m (a->b->c->d) alts3 rs = do rs <- fixDepth rs decDepthChecked (constM $ constM $ constM rs) (coseries $ coseries $ coseries rs) alts4 :: (CoSerial m a, CoSerial m b, CoSerial m c, CoSerial m d) => Series m e -> Series m (a->b->c->d->e) alts4 rs = do rs <- fixDepth rs decDepthChecked (constM $ constM $ constM $ constM rs) (coseries $ coseries $ coseries $ coseries rs) -- | Same as 'alts1', but preserves the depth. newtypeAlts :: CoSerial m a => Series m b -> Series m (a->b) newtypeAlts = coseries -- }}} ------------------------------ -- Generic instances ------------------------------ -- {{{ class GSerial m f where gSeries :: Series m (f a) class GCoSerial m f where gCoseries :: Series m b -> Series m (f a -> b) instance {-# OVERLAPPABLE #-} GSerial m f => GSerial m (M1 i c f) where gSeries = M1 <$> gSeries {-# INLINE gSeries #-} instance GCoSerial m f => GCoSerial m (M1 i c f) where gCoseries rs = (. unM1) <$> gCoseries rs {-# INLINE gCoseries #-} instance Serial m c => GSerial m (K1 i c) where gSeries = K1 <$> series {-# INLINE gSeries #-} instance CoSerial m c => GCoSerial m (K1 i c) where gCoseries rs = (. unK1) <$> coseries rs {-# INLINE gCoseries #-} instance GSerial m U1 where gSeries = pure U1 {-# INLINE gSeries #-} instance GCoSerial m U1 where gCoseries rs = constM rs {-# INLINE gCoseries #-} instance (Monad m, GSerial m a, GSerial m b) => GSerial m (a :*: b) where gSeries = (:*:) <$> gSeries <~> gSeries {-# INLINE gSeries #-} instance (Monad m, GCoSerial m a, GCoSerial m b) => GCoSerial m (a :*: b) where gCoseries rs = uncur <$> gCoseries (gCoseries rs) where uncur f (x :*: y) = f x y {-# INLINE gCoseries #-} instance (Monad m, GSerial m a, GSerial m b) => GSerial m (a :+: b) where gSeries = (L1 <$> gSeries) `interleave` (R1 <$> gSeries) {-# INLINE gSeries #-} instance (Monad m, GCoSerial m a, GCoSerial m b) => GCoSerial m (a :+: b) where gCoseries rs = gCoseries rs >>- \f -> gCoseries rs >>- \g -> return $ \e -> case e of L1 x -> f x R1 y -> g y {-# INLINE gCoseries #-} instance {-# OVERLAPPING #-} GSerial m f => GSerial m (C1 c f) where gSeries = M1 <$> decDepth gSeries {-# INLINE gSeries #-} -- }}} ------------------------------ -- Instances for basic types ------------------------------ -- {{{ instance Monad m => Serial m () where series = return () instance Monad m => CoSerial m () where coseries rs = constM rs instance Monad m => Serial m Integer where series = unM <$> series instance Monad m => CoSerial m Integer where coseries = fmap (. M) . coseries instance Monad m => Serial m Natural where series = unN <$> series instance Monad m => CoSerial m Natural where coseries = fmap (. N) . coseries instance Monad m => Serial m Int where series = unM <$> series instance Monad m => CoSerial m Int where coseries = fmap (. M) . coseries instance Monad m => Serial m Word where series = unN <$> series instance Monad m => CoSerial m Word where coseries = fmap (. N) . coseries instance Monad m => Serial m Int8 where series = unM <$> series instance Monad m => CoSerial m Int8 where coseries = fmap (. M) . coseries instance Monad m => Serial m Word8 where series = unN <$> series instance Monad m => CoSerial m Word8 where coseries = fmap (. N) . coseries instance Monad m => Serial m Int16 where series = unM <$> series instance Monad m => CoSerial m Int16 where coseries = fmap (. M) . coseries instance Monad m => Serial m Word16 where series = unN <$> series instance Monad m => CoSerial m Word16 where coseries = fmap (. N) . coseries instance Monad m => Serial m Int32 where series = unM <$> series instance Monad m => CoSerial m Int32 where coseries = fmap (. M) . coseries instance Monad m => Serial m Word32 where series = unN <$> series instance Monad m => CoSerial m Word32 where coseries = fmap (. N) . coseries instance Monad m => Serial m Int64 where series = unM <$> series instance Monad m => CoSerial m Int64 where coseries = fmap (. M) . coseries instance Monad m => Serial m Word64 where series = unN <$> series instance Monad m => CoSerial m Word64 where coseries = fmap (. N) . coseries -- | '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@. newtype N a = N { unN :: a } deriving (Eq, Ord) instance Real a => Real (N a) where toRational (N x) = toRational x instance Enum a => Enum (N a) where toEnum x = N (toEnum x) fromEnum (N x) = fromEnum x instance Num a => Num (N a) where N x + N y = N (x + y) N x * N y = N (x * y) negate (N x) = N (negate x) abs (N x) = N (abs x) signum (N x) = N (signum x) fromInteger x = N (fromInteger x) instance Integral a => Integral (N a) where quotRem (N x) (N y) = (N q, N r) where (q, r) = x `quotRem` y toInteger (N x) = toInteger x instance (Num a, Enum a, Serial m a) => Serial m (N a) where series = generate $ \d -> take (d+1) [0..] instance (Integral a, Monad m) => CoSerial m (N a) where coseries rs = -- This is a recursive function, because @alts1 rs@ typically calls -- back to 'coseries' (but with lower depth). -- -- The recursion stops when depth == 0. Then alts1 produces a constant -- function, and doesn't call back to 'coseries'. alts0 rs >>- \z -> alts1 rs >>- \f -> return $ \(N i) -> if i > 0 then f (N $ i-1) else z -- | 'M' is a helper type to generate values of a signed type of increasing magnitude. newtype M a = M { unM :: a } deriving (Eq, Ord) instance Real a => Real (M a) where toRational (M x) = toRational x instance Enum a => Enum (M a) where toEnum x = M (toEnum x) fromEnum (M x) = fromEnum x instance Num a => Num (M a) where M x + M y = M (x + y) M x * M y = M (x * y) negate (M x) = M (negate x) abs (M x) = M (abs x) signum (M x) = M (signum x) fromInteger x = M (fromInteger x) instance Integral a => Integral (M a) where quotRem (M x) (M y) = (M q, M r) where (q, r) = x `quotRem` y toInteger (M x) = toInteger x instance (Num a, Enum a, Monad m) => Serial m (M a) where series = others `interleave` positives where positives = generate $ \d -> take d [1..] others = generate $ \d -> take (d+1) [0,-1..] instance (Ord a, Num a, Monad m) => CoSerial m (M a) where coseries rs = alts0 rs >>- \z -> alts1 rs >>- \f -> alts1 rs >>- \g -> pure $ \ i -> case compare i 0 of GT -> f (M (i - 1)) LT -> g (M (abs i - 1)) EQ -> z instance Monad m => Serial m Float where series = series >>- \(sig, exp) -> guard (odd sig || sig==0 && exp==0) >> return (encodeFloat sig exp) instance Monad m => CoSerial m Float where coseries rs = coseries rs >>- \f -> return $ f . decodeFloat instance Monad m => Serial m Double where series = (realToFrac :: Float -> Double) <$> series instance Monad m => CoSerial m Double where coseries rs = (. (realToFrac :: Double -> Float)) <$> coseries rs instance (Integral i, Serial m i) => Serial m (Ratio i) where series = pairToRatio <$> series where pairToRatio (n, Positive d) = n % d instance (Integral i, CoSerial m i) => CoSerial m (Ratio i) where coseries rs = (. ratioToPair) <$> coseries rs where ratioToPair r = (numerator r, denominator r) instance Monad m => Serial m Char where series = generate $ \d -> take (d+1) ['a'..'z'] instance Monad m => CoSerial m Char where coseries rs = coseries rs >>- \f -> return $ \c -> f (N (fromEnum c - fromEnum 'a')) instance (Serial m a, Serial m b) => Serial m (a,b) where series = cons2 (,) instance (CoSerial m a, CoSerial m b) => CoSerial m (a,b) where coseries rs = uncurry <$> alts2 rs instance (Serial m a, Serial m b, Serial m c) => Serial m (a,b,c) where series = cons3 (,,) instance (CoSerial m a, CoSerial m b, CoSerial m c) => CoSerial m (a,b,c) where coseries rs = uncurry3 <$> alts3 rs instance (Serial m a, Serial m b, Serial m c, Serial m d) => Serial m (a,b,c,d) where series = cons4 (,,,) instance (CoSerial m a, CoSerial m b, CoSerial m c, CoSerial m d) => CoSerial m (a,b,c,d) where coseries rs = uncurry4 <$> alts4 rs instance Monad m => Serial m Bool where series = cons0 True \/ cons0 False instance Monad m => CoSerial m Bool where coseries rs = rs >>- \r1 -> rs >>- \r2 -> return $ \x -> if x then r1 else r2 instance (Serial m a) => Serial m (Maybe a) where series = cons0 Nothing \/ cons1 Just instance (CoSerial m a) => CoSerial m (Maybe a) where coseries rs = maybe <$> alts0 rs <~> alts1 rs instance (Serial m a, Serial m b) => Serial m (Either a b) where series = cons1 Left \/ cons1 Right instance (CoSerial m a, CoSerial m b) => CoSerial m (Either a b) where coseries rs = either <$> alts1 rs <~> alts1 rs instance Serial m a => Serial m [a] where series = cons0 [] \/ cons2 (:) instance CoSerial m a => CoSerial m [a] where coseries rs = alts0 rs >>- \y -> alts2 rs >>- \f -> return $ \xs -> case xs of [] -> y; x:xs' -> f x xs' instance (CoSerial m a, Serial m b) => Serial m (a->b) where series = coseries series -- Thanks to Ralf Hinze for the definition of coseries -- using the nest auxiliary. instance (Serial m a, CoSerial m a, Serial m b, CoSerial m b) => CoSerial m (a->b) where coseries r = do args <- unwind series g <- nest r args return $ \f -> g $ map f args where nest :: forall a b m c . (Serial m b, CoSerial m b) => Series m c -> [a] -> Series m ([b] -> c) nest rs args = do case args of [] -> const `liftM` rs _:rest -> do let sf = coseries $ nest rs rest f <- sf return $ \(b:bs) -> f b bs -- show the extension of a function (in part, bounded both by -- the number and depth of arguments) instance (Serial Identity a, Show a, Show b) => Show (a -> b) where show f = if maxarheight == 1 && sumarwidth + length ars * length "->;" < widthLimit then "{"++ intercalate ";" [a++"->"++r | (a,r) <- ars] ++"}" else concat $ [a++"->\n"++indent r | (a,r) <- ars] where ars = take lengthLimit [ (show x, show (f x)) | x <- list depthLimit series ] maxarheight = maximum [ max (height a) (height r) | (a,r) <- ars ] sumarwidth = sum [ length a + length r | (a,r) <- ars] indent = unlines . map (" "++) . lines height = length . lines (widthLimit,lengthLimit,depthLimit) = (80,20,3)::(Int,Int,Depth) -- }}} ------------------------------ -- Convenient wrappers ------------------------------ -- {{{ -------------------------------------------------------------------------- -- | @Positive x@: guarantees that @x \> 0@. newtype Positive a = Positive { getPositive :: a } deriving (Eq, Ord) instance Real a => Real (Positive a) where toRational (Positive x) = toRational x instance Enum a => Enum (Positive a) where toEnum x = Positive (toEnum x) fromEnum (Positive x) = fromEnum x instance Num a => Num (Positive a) where Positive x + Positive y = Positive (x + y) Positive x * Positive y = Positive (x * y) negate (Positive x) = Positive (negate x) abs (Positive x) = Positive (abs x) signum (Positive x) = Positive (signum x) fromInteger x = Positive (fromInteger x) instance Integral a => Integral (Positive a) where quotRem (Positive x) (Positive y) = (Positive q, Positive r) where (q, r) = x `quotRem` y toInteger (Positive x) = toInteger x instance (Num a, Ord a, Serial m a) => Serial m (Positive a) where series = Positive <$> series `suchThat` (> 0) instance Show a => Show (Positive a) where showsPrec n (Positive x) = showsPrec n x -- | @NonNegative x@: guarantees that @x \>= 0@. newtype NonNegative a = NonNegative { getNonNegative :: a } deriving (Eq, Ord) instance Real a => Real (NonNegative a) where toRational (NonNegative x) = toRational x instance Enum a => Enum (NonNegative a) where toEnum x = NonNegative (toEnum x) fromEnum (NonNegative x) = fromEnum x instance Num a => Num (NonNegative a) where NonNegative x + NonNegative y = NonNegative (x + y) NonNegative x * NonNegative y = NonNegative (x * y) negate (NonNegative x) = NonNegative (negate x) abs (NonNegative x) = NonNegative (abs x) signum (NonNegative x) = NonNegative (signum x) fromInteger x = NonNegative (fromInteger x) instance Integral a => Integral (NonNegative a) where quotRem (NonNegative x) (NonNegative y) = (NonNegative q, NonNegative r) where (q, r) = x `quotRem` y toInteger (NonNegative x) = toInteger x instance (Num a, Ord a, Serial m a) => Serial m (NonNegative a) where series = NonNegative <$> series `suchThat` (>= 0) instance Show a => Show (NonNegative a) where showsPrec n (NonNegative x) = showsPrec n x -- | @NonEmpty xs@: guarantees that @xs@ is not null newtype NonEmpty a = NonEmpty { getNonEmpty :: [a] } instance (Serial m a) => Serial m (NonEmpty a) where series = NonEmpty <$> cons2 (:) instance Show a => Show (NonEmpty a) where showsPrec n (NonEmpty x) = showsPrec n x -- }}} smallcheck-1.1.7/Test/SmallCheck/Property.hs0000644000000000000000000002517213670246521017136 0ustar0000000000000000-- vim:fdm=marker:foldtext=foldtext() -------------------------------------------------------------------- -- | -- Module : Test.SmallCheck.Property -- Copyright : (c) Colin Runciman et al. -- License : BSD3 -- Maintainer: Roman Cheplyaka -- -- Properties and tools to construct them. -------------------------------------------------------------------- {-# LANGUAGE CPP #-} {-# LANGUAGE DeriveDataTypeable #-} {-# LANGUAGE FlexibleInstances #-} {-# LANGUAGE MultiParamTypeClasses #-} {-# LANGUAGE ScopedTypeVariables #-} {-# LANGUAGE TypeFamilies #-} -- Are we using new, polykinded and derivable Typeable yet? #define NEWTYPEABLE MIN_VERSION_base(4,7,0) #if NEWTYPEABLE {-# LANGUAGE Safe #-} #else -- Trustworthy is needed because of the hand-written Typeable instance {-# LANGUAGE Trustworthy #-} #endif module Test.SmallCheck.Property ( -- * Constructors forAll, exists, existsUnique, over, (==>), monadic, changeDepth, changeDepth1, -- * Property's entrails Property, PropertySuccess(..), PropertyFailure(..), runProperty, TestQuality(..), Argument, Reason, Depth, Testable(..), ) where import Test.SmallCheck.Series import Test.SmallCheck.SeriesMonad import Test.SmallCheck.Property.Result import Control.Arrow (first) import Control.Monad (liftM, mzero) import Control.Monad.Logic (MonadLogic, runLogicT, ifte, once, msplit, lnot) import Control.Monad.Reader (Reader, runReader, lift, ask, local, reader) import Control.Applicative (pure, (<$>), (<$)) import Data.Typeable (Typeable(..)) #if !NEWTYPEABLE import Data.Typeable (Typeable1, mkTyConApp, mkTyCon3, typeOf) #endif ------------------------------ -- Property-related types ------------------------------ --{{{ -- | The type of properties over the monad @m@ newtype Property m = Property { unProperty :: Reader (Env m) (PropertySeries m) } #if NEWTYPEABLE deriving Typeable #endif data PropertySeries m = PropertySeries { searchExamples :: Series m PropertySuccess , searchCounterExamples :: Series m PropertyFailure , searchClosest :: Series m (Property m, [Argument]) } data Env m = Env { quantification :: Quantification , testHook :: TestQuality -> m () } data Quantification = Forall | Exists | ExistsUnique data TestQuality = GoodTest | BadTest deriving (Eq, Ord, Enum, Show) #if !NEWTYPEABLE -- Typeable here is not polykinded yet, and also GHC doesn't know how to -- derive this. instance Typeable1 m => Typeable (Property m) where typeOf _ = mkTyConApp (mkTyCon3 "smallcheck" "Test.SmallCheck.Property" "Property") [typeOf (undefined :: m ())] #endif -- }}} ------------------------------------ -- Property runners and constructors ------------------------------------ --{{{ unProp :: Env t -> Property t -> PropertySeries t unProp q (Property p) = runReader p q runProperty :: Monad m => Depth -> (TestQuality -> m ()) -> Property m -> m (Maybe PropertyFailure) runProperty depth hook prop = (\l -> runLogicT l (\x _ -> return $ Just x) (return Nothing)) $ runSeries depth $ searchCounterExamples $ flip runReader (Env Forall hook) $ unProperty prop atomicProperty :: Series m PropertySuccess -> Series m PropertyFailure -> PropertySeries m atomicProperty s f = let prop = PropertySeries s f (pure (Property $ pure prop, [])) in prop makeAtomic :: Property m -> Property m makeAtomic (Property prop) = Property $ flip fmap prop $ \ps -> atomicProperty (searchExamples ps) (searchCounterExamples ps) -- | @'over' s $ \\x -> p x@ makes @x@ range over the 'Series' @s@ (by -- default, all variables range over the 'series' for their types). -- -- Note that, unlike the quantification operators, this affects only the -- variable following the operator and not subsequent variables. -- -- 'over' does not affect the quantification context. over :: (Show a, Testable m b) => Series m a -> (a -> b) -> Property m over = testFunction -- | Execute a monadic test monadic :: Testable m a => m a -> Property m monadic a = Property $ reader $ \env -> let pair = unProp env . freshContext <$> lift a in atomicProperty (searchExamples =<< pair) (searchCounterExamples =<< pair) -- }}} ------------------------------- -- Testable class and instances ------------------------------- -- {{{ -- | Class of tests that can be run in a monad. For pure tests, it is -- recommended to keep their types polymorphic in @m@ rather than -- specialising it to 'Identity'. class Monad m => Testable m a where test :: a -> Property m instance Monad m => Testable m Bool where test b = Property $ reader $ \env -> let success = do lift $ testHook env GoodTest if b then return $ PropertyTrue Nothing else mzero failure = PropertyFalse Nothing <$ lnot success in atomicProperty success failure -- | Works like the 'Bool' instance, but includes an explanation of the result. -- -- 'Left' and 'Right' correspond to test failure and success -- respectively. instance Monad m => Testable m (Either Reason Reason) where test r = Property $ reader $ \env -> let success = do lift $ testHook env GoodTest either (const mzero) (pure . PropertyTrue . Just) r failure = do lift $ testHook env GoodTest either (pure . PropertyFalse . Just) (const mzero) r in atomicProperty success failure instance (Serial m a, Show a, Testable m b) => Testable m (a->b) where test = testFunction series instance (Monad m, m ~ n) => Testable n (Property m) where test = id testFunction :: (Show a, Testable m b) => Series m a -> (a -> b) -> Property m testFunction s f = Property $ reader $ \env -> let closest = do x <- s (p, args) <- searchClosest $ unProp env $ test $ f x return (p, show x : args) in case quantification env of Forall -> PropertySeries success failure closest -- {{{ where failure = do x <- s failure <- searchCounterExamples $ unProp env $ test $ f x let arg = show x return $ case failure of CounterExample args etc -> CounterExample (arg:args) etc _ -> CounterExample [arg] failure success = PropertyTrue Nothing <$ lnot failure -- }}} Exists -> PropertySeries success failure closest -- {{{ where success = do x <- s s <- searchExamples $ unProp env $ test $ f x let arg = show x return $ case s of Exist args etc -> Exist (arg:args) etc _ -> Exist [arg] s failure = NotExist <$ lnot success -- }}} ExistsUnique -> PropertySeries success failure closest -- {{{ where search = atMost 2 $ do (prop, args) <- closest ex <- once $ searchExamples $ unProp env $ test prop return (args, ex) success = search >>= \examples -> case examples of [(x,s)] -> return $ ExistUnique x s _ -> mzero failure = search >>= \examples -> case examples of [] -> return NotExist (x1,s1):(x2,s2):_ -> return $ AtLeastTwo x1 s1 x2 s2 _ -> mzero -- }}} atMost :: MonadLogic m => Int -> m a -> m [a] atMost n m | n <= 0 = return [] | otherwise = do m' <- msplit m case m' of Nothing -> return [] Just (x,rest) -> (x:) `liftM` atMost (n-1) rest -- }}} ------------------------------ -- Test constructors ------------------------------ -- {{{ quantify :: Quantification -> Property m -> Property m quantify q (Property a) = makeAtomic $ Property $ local (\env -> env { quantification = q }) a freshContext :: Testable m a => a -> Property m freshContext = forAll -- | Set the universal quantification context forAll :: Testable m a => a -> Property m forAll = quantify Forall . test -- | Set the existential quantification context exists :: Testable m a => a -> Property m exists = quantify Exists . test -- | Set the uniqueness quantification context. -- -- Bear in mind that ∃! (x, y): p x y is not the same as ∃! x: ∃! y: p x y. -- -- For example, ∃! x: ∃! y: |x| = |y| is true (it holds only when x=0), but ∃! (x,y): |x| = |y| is false (there are many such pairs). -- -- As is customary in mathematics, -- @'existsUnique' $ \\x y -> p x y@ is equivalent to -- @'existsUnique' $ \\(x,y) -> p x y@ and not to -- @'existsUnique' $ \\x -> 'existsUnique' $ \\y -> p x y@ -- (the latter, of course, may be explicitly written when desired). -- -- That is, all the variables affected by the same uniqueness context are -- quantified simultaneously as a tuple. existsUnique :: Testable m a => a -> Property m existsUnique = quantify ExistsUnique . test -- | The '==>' operator can be used to express a restricting condition -- under which a property should hold. It corresponds to implication in the -- classical logic. -- -- Note that '==>' resets the quantification context for its operands to -- the default (universal). infixr 0 ==> (==>) :: (Testable m c, Testable m a) => c -> a -> Property m cond ==> prop = Property $ do env <- ask let counterExample = once $ searchCounterExamples $ unProp env' $ freshContext cond -- NB: we do not invoke the test hook in the antecedent where env' = env { testHook = const $ return () } consequent = unProp env $ freshContext prop badTestHook = lift $ testHook env BadTest success = ifte counterExample -- then (\ex -> do badTestHook return $ Vacuously ex ) -- else (searchExamples consequent) failure = ifte counterExample -- then (const $ do lift $ testHook env BadTest mzero ) -- else (searchCounterExamples consequent) return $ atomicProperty success failure -- | Run property with a modified depth. Affects all quantified variables -- in the property. changeDepth :: Testable m a => (Depth -> Depth) -> a -> Property m changeDepth modifyDepth a = Property (changeDepthPS <$> unProperty (test a)) where changeDepthPS (PropertySeries ss sf sc) = PropertySeries (localDepth modifyDepth ss) (localDepth modifyDepth sf) (first (changeDepth modifyDepth) <$> localDepth modifyDepth sc) -- | Quantify the function's argument over its 'series', but adjust the -- depth. This doesn't affect any subsequent variables. changeDepth1 :: (Show a, Serial m a, Testable m b) => (Depth -> Depth) -> (a -> b) -> Property m changeDepth1 modifyDepth = over $ localDepth modifyDepth series -- }}} smallcheck-1.1.7/Test/SmallCheck/SeriesMonad.hs0000644000000000000000000000415013670246521017514 0ustar0000000000000000{-# LANGUAGE Safe #-} module Test.SmallCheck.SeriesMonad where import Control.Applicative (Applicative(..), Alternative(..), (<$>)) import Control.Monad (MonadPlus(..)) import Control.Monad.Logic (MonadLogic(..), LogicT) import Control.Monad.Reader (MonadTrans(..), ReaderT, runReaderT) import Control.Arrow (second) -- | 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. newtype Series m a = Series (ReaderT Depth (LogicT m) a) instance Functor (Series m) where fmap f (Series x) = Series (fmap f x) instance Monad (Series m) where Series x >>= f = Series (x >>= unSeries . f) where unSeries (Series y) = y return = pure instance Applicative (Series m) where pure = Series . pure Series x <*> Series y = Series (x <*> y) instance MonadPlus (Series m) where mzero = empty mplus = (<|>) instance Alternative (Series m) where empty = Series empty Series x <|> Series y = Series (x <|> y) -- This instance is written manually. Using the GND for it is not safe. instance Monad m => MonadLogic (Series m) where msplit (Series a) = Series (fmap (second Series) <$> msplit a) instance MonadTrans Series where lift a = Series $ lift . lift $ a runSeries :: Depth -> Series m a -> LogicT m a runSeries d (Series a) = runReaderT a d smallcheck-1.1.7/Test/SmallCheck/Property/Result.hs0000644000000000000000000000451113670246521020406 0ustar0000000000000000{-# LANGUAGE FlexibleInstances #-} {-# LANGUAGE Safe #-} module Test.SmallCheck.Property.Result ( PropertySuccess(..) , PropertyFailure(..) , ppFailure , Reason , Argument ) where import Text.PrettyPrint (Doc, empty, hsep, nest, render, text, (<+>), ($+$), ($$)) type Argument = String -- | An explanation for the test outcome type Reason = String data PropertySuccess = Exist [Argument] PropertySuccess | ExistUnique [Argument] PropertySuccess | PropertyTrue (Maybe Reason) | Vacuously PropertyFailure deriving (Eq, Show) data PropertyFailure = NotExist | AtLeastTwo [Argument] PropertySuccess [Argument] PropertySuccess | CounterExample [Argument] PropertyFailure | PropertyFalse (Maybe Reason) deriving (Eq, Show) class Pretty a where pretty :: a -> Doc instance Pretty PropertyFailure where pretty NotExist = text "argument does not exist" pretty (AtLeastTwo args1 s1 args2 s2) = text "there are at least two" <+> plural args1 empty (text "sets of") <+> text "arguments satisfying the property:" $$ formatExample args1 s1 $$ formatExample args2 s2 where formatExample args s = nest ind $ text "for" <+> prettyArgs args pretty s pretty (CounterExample args f) = text "there" <+> text (plural args "exists" "exist") <+> prettyArgs args <+> text "such that" pretty f pretty (PropertyFalse Nothing) = text "condition is false" pretty (PropertyFalse (Just s)) = text s instance Pretty PropertySuccess where pretty (PropertyTrue Nothing) = text "condition is true" pretty (PropertyTrue (Just s)) = text s pretty (Exist args s) = existsMsg False args s pretty (ExistUnique args s) = existsMsg True args s pretty (Vacuously s) = text "property is vacuously true because" pretty s ind :: Int ind = 2 infixl 5 () :: Doc -> Doc -> Doc a b = a $+$ nest ind b prettyArgs :: [Argument] -> Doc prettyArgs = hsep . map text existsMsg :: Pretty a => Bool -> [Argument] -> a -> Doc existsMsg unique args s = text "there" <+> text (plural args "exists" "exist") <+> (if unique then text "unique" else empty) <+> prettyArgs args <+> text "such that" pretty s plural :: [a] -> b -> b -> b plural lst sing pl = case lst of _:_:_ -> pl _ -> sing ppFailure :: PropertyFailure -> String ppFailure = render . pretty smallcheck-1.1.7/LICENSE0000644000000000000000000000261613667504267013046 0ustar0000000000000000All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 3. Neither the name of the author nor the names of his contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. smallcheck-1.1.7/Setup.hs0000644000000000000000000000005613667504267013471 0ustar0000000000000000import Distribution.Simple main = defaultMain smallcheck-1.1.7/smallcheck.cabal0000644000000000000000000000255313670525167015127 0ustar0000000000000000name: smallcheck version: 1.1.7 license: BSD3 license-file: LICENSE maintainer: Andrew Lelechenko author: Colin Runciman, Roman Cheplyaka cabal-version: >=1.10 tested-with: ghc ==8.10.1 ghc ==8.8.3 ghc ==8.6.5 ghc ==8.4.4 ghc ==8.2.2 ghc ==8.0.2 ghc ==7.10.3 ghc ==7.8.4 ghc ==7.6.3 ghc ==7.4.2 homepage: https://github.com/Bodigrim/smallcheck bug-reports: https://github.com/Bodigrim/smallcheck/issues synopsis: A property-based testing library description: 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. category: Testing build-type: Simple extra-source-files: README.md CREDITS.md CHANGELOG.md source-repository head type: git location: git://github.com/Bodigrim/smallcheck.git library default-language: Haskell2010 exposed-modules: Test.SmallCheck Test.SmallCheck.Drivers Test.SmallCheck.Series other-modules: Test.SmallCheck.Property Test.SmallCheck.SeriesMonad Test.SmallCheck.Property.Result build-depends: base >=4.5 && <5, mtl, logict, pretty if impl(ghc <7.10) build-depends: nats if impl(ghc <7.6) build-depends: ghc-prim >=0.2 smallcheck-1.1.7/README.md0000644000000000000000000000264113670251014013275 0ustar0000000000000000SmallCheck: a property-based testing library for Haskell ======================================================== 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. Usefulness of such an approach to testing is based on the following observation: > If a program fails to meet its specification in some cases, it almost always > fails in some simple case. To get started with SmallCheck: * Read the [documentation][haddock] * If you have experience with QuickCheck, [read the comparison of QuickCheck and SmallCheck][comparison] * Install it and give it a try! `cabal update; cabal install smallcheck` * Read the [paper][paper] or [other materials][oldpage] from the original authors of SmallCheck (note that that information might be somewhat outdated) * If you see something that can be improved, please [submit an issue][issues] * Check out [the source code][github] at GitHub [haddock]: http://hackage.haskell.org/package/smallcheck/docs/Test-SmallCheck.html [hackage]: http://hackage.haskell.org/package/smallcheck [paper]: http://www.cs.york.ac.uk/fp/smallcheck/smallcheck.pdf [oldpage]: http://www.cs.york.ac.uk/fp/smallcheck/ [comparison]: https://github.com/Bodigrim/smallcheck/wiki/Comparison-with-QuickCheck [github]: https://github.com/Bodigrim/smallcheck [issues]: https://github.com/Bodigrim/smallcheck/issues smallcheck-1.1.7/CREDITS.md0000644000000000000000000000116413667504267013455 0ustar0000000000000000Credits ======= The original authors of SmallCheck are Colin Runciman, Matthew Naylor, and Fredrik Lindblad. Colin Runciman: > Thanks to Galois Connections, my hosts when I first wrote SmallCheck, > to users who have mailed me with feedback, to Ralf Hinze who suggested > the better method for functional coseries, to Neil Mitchell for > automating the derivation of Serial instances, to Matt Naylor for > the circuit-design examples and to Gwern Branwen for Cabal packaging. Contributors ------------ The following people have contributed to SmallCheck: * Bas van Dijk (default Generic implementation of Serial instance) smallcheck-1.1.7/CHANGELOG.md0000644000000000000000000000654013670525167013646 0ustar0000000000000000Changes ======= Version 1.1.7 ------------- * Fix overlapping instances of `GSerial`. Version 1.1.6 ------------- * Mark modules as `Safe`, not just `Trustworthy`. Version 1.1.5 ------------- * Add `limit :: Monad m => Int -> Series m a -> Series m a` * Add `genericSeries` and `genericCoseries`, so that you can use the generic implementations more flexibly. Previously, the generic implementation was only avaialable as the default method for `series`/`coseries` but not as standalone functions. Version 1.1.4 ------------- * Add instances for fixed-width Int and Word types (Int8, Word8 etc.) Version 1.1.3.1 --------------- * Fix compatibility with GHC 7.8 and older Version 1.1.3 ------------- * Add `Serial` and `CoSerial` instances for `Word` and `Natural` Version 1.1.2 ------------- * Export the `test` function * Add a `listSeries` function Version 1.1.1 ------------- Export some auxiliary functions from `T.S.Series`, and document how to express `consN` and `altsN` for `N > 4`. Version 1.1.0.1 --------------- Documentation fixes Version 1.1 ----------- * Add a `Serial` instance for `Ratio` * Add the `NonEmpty` wrapper for lists * Add `listM` (the monadic version of `list`) * Add optional explanation for test outcomes Version 1.0.4 ------------- Fix compatibility with GHC 7.4.1 Version 1.0.3 ------------- Fix a bug where no test cases were generated for some functional types (#19). Version 1.0.2 ------------- Fix a bug in the generic instance Version 1.0.1 ------------- Make SmallCheck build with GHC 7.4 Version 1.0 ----------- This is a major incompatible release of SmallCheck. Virtually every function has changed its name, type, semantics or module. So please carefully read the docs when upgrading. For some highlights, see [this blog post](http://ro-che.info/articles/2013-02-19-smallcheck.html). Version 0.6.2 ----------- * Derive Typeable Property instance * Add smallCheckPure Version 0.6.1 ----------- * Documentation improvements * Make the package build with GHC 7.4.1 Version 0.6 ----------- * Default Generic implementation of Serial instance (by Bas van Dijk) * The code is split into modules * Convert much of README into haddock documentation * Many small API changes * Remove impure Testable (IO a) instance Version 0.5 ----------- Make the package build with GHC 7.2. Some cosmetic changes. Version 0.4 ----------- The module SmallCheck is now Test.SmallCheck. Packaged with Cabal. Version 0.3 ----------- Existential quantifiers now have unique variants for which two witnesses are reported when uniqueness fails. The over-generating coseries method for functions of functional arguments has been replaced; now 'coseries' and the 'alts' family take a series argument. Test counters are now Integers, not Ints. Ord and Eq are now derived for the N types. Examples extended. Version 0.2 ----------- The 'smallCheck' driver now takes an argument d and runs test series at depths 0..d without interaction, stopping if any test fails. The interactive variant is still available as 'smallCheckI'. All Prelude numeric types now have Serial instances, including floating-point types. Serial types Nat and Natural are also defined. Examples extended. Version 0.1 ----------- The differences from 0.0 are two fixes (space-fault, output buffering), an 'unsafe' but sometimes useful Testable (IO a) instance and additional examples.