checkers 0.1.4 → 0.2
raw patch · 8 files changed
+166/−70 lines, 8 filesdep ~QuickCheckPVP ok
version bump matches the API change (PVP)
Dependency ranges changed: QuickCheck
API changes (from Hackage documentation)
- Test.QuickCheck.Checkers: (.&.) :: (Testable prop1, Testable prop2) => prop1 -> prop2 -> Property
- Test.QuickCheck.Checkers: NonNegative :: a -> NonNegative a
- Test.QuickCheck.Checkers: NonZero :: a -> NonZero a
- Test.QuickCheck.Checkers: instance (Enum a) => Enum (NonNegative a)
- Test.QuickCheck.Checkers: instance (Enum a) => Enum (NonZero a)
- Test.QuickCheck.Checkers: instance (Eq a) => Eq (NonNegative a)
- Test.QuickCheck.Checkers: instance (Eq a) => Eq (NonZero a)
- Test.QuickCheck.Checkers: instance (Integral a) => Integral (NonNegative a)
- Test.QuickCheck.Checkers: instance (Integral a) => Integral (NonZero a)
- Test.QuickCheck.Checkers: instance (Num a) => Num (NonNegative a)
- Test.QuickCheck.Checkers: instance (Num a) => Num (NonZero a)
- Test.QuickCheck.Checkers: instance (Num a, Arbitrary a) => Arbitrary (NonNegative a)
- Test.QuickCheck.Checkers: instance (Num a, Arbitrary a) => Arbitrary (NonZero a)
- Test.QuickCheck.Checkers: instance (Ord a) => Ord (NonNegative a)
- Test.QuickCheck.Checkers: instance (Ord a) => Ord (NonZero a)
- Test.QuickCheck.Checkers: instance (Read a) => Read (NonNegative a)
- Test.QuickCheck.Checkers: instance (Read a) => Read (NonZero a)
- Test.QuickCheck.Checkers: instance (Real a) => Real (NonNegative a)
- Test.QuickCheck.Checkers: instance (Real a) => Real (NonZero a)
- Test.QuickCheck.Checkers: instance (Show a) => Show (NonNegative a)
- Test.QuickCheck.Checkers: instance (Show a) => Show (NonZero a)
- Test.QuickCheck.Checkers: newtype NonNegative a
- Test.QuickCheck.Checkers: newtype NonZero a
- Test.QuickCheck.Checkers: probablisticPureCheck :: (Testable a) => Config -> a -> Bool
- Test.QuickCheck.Checkers: suchThat :: Gen a -> (a -> Bool) -> Gen a
- Test.QuickCheck.Checkers: suchThatMaybe :: Gen a -> (a -> Bool) -> Gen (Maybe a)
- Test.QuickCheck.Checkers: type Positive a = NonZero (NonNegative a)
- Test.QuickCheck.Checkers: unNonNegative :: NonNegative a -> a
- Test.QuickCheck.Checkers: unNonZero :: NonZero a -> a
- Test.QuickCheck.Instances.Char: instance Arbitrary Char
+ Test.QuickCheck.Instances.Array: instance (Ix a, Integral a, CoArbitrary b) => CoArbitrary (Array a b)
+ Test.QuickCheck.Instances.Int: instance CoArbitrary Int16
+ Test.QuickCheck.Instances.Int: instance CoArbitrary Int32
+ Test.QuickCheck.Instances.Int: instance CoArbitrary Int64
+ Test.QuickCheck.Instances.Int: instance CoArbitrary Int8
+ Test.QuickCheck.Instances.Word: instance CoArbitrary Word16
+ Test.QuickCheck.Instances.Word: instance CoArbitrary Word32
+ Test.QuickCheck.Instances.Word: instance CoArbitrary Word64
+ Test.QuickCheck.Instances.Word: instance CoArbitrary Word8
+ Test.QuickCheck.Utils: isAssociative :: (Arbitrary a, Show a, Eq a) => (a -> a -> a) -> Property
+ Test.QuickCheck.Utils: isAssociativeBy :: (Show a, Testable prop) => (a -> a -> prop) -> Gen a -> (a -> a -> a) -> Property
+ Test.QuickCheck.Utils: isCommutable :: (Arbitrary a, Show a, Eq b) => (a -> a -> b) -> Property
+ Test.QuickCheck.Utils: isCommutableBy :: (Show a, Testable prop) => (b -> b -> prop) -> Gen a -> (a -> a -> b) -> Property
+ Test.QuickCheck.Utils: isTotalOrder :: (Arbitrary a, Show a, Ord a) => a -> a -> Property
- Test.QuickCheck.Checkers: checkBatch :: Config -> TestBatch -> IO ()
+ Test.QuickCheck.Checkers: checkBatch :: Args -> TestBatch -> IO ()
- Test.QuickCheck.Classes: applicative :: (Applicative m, Arbitrary a, Arbitrary b, Arbitrary (m a), Arbitrary (m (b -> c)), Show (m (b -> c)), Arbitrary (m (a -> b)), Show (m (a -> b)), Show a, Show (m a), EqProp (m a), EqProp (m b), EqProp (m c)) => m (a, b, c) -> TestBatch
+ Test.QuickCheck.Classes: applicative :: (Applicative m, Arbitrary a, CoArbitrary a, Arbitrary b, Arbitrary (m a), Arbitrary (m (b -> c)), Show (m (b -> c)), Arbitrary (m (a -> b)), Show (m (a -> b)), Show a, Show (m a), EqProp (m a), EqProp (m b), EqProp (m c)) => m (a, b, c) -> TestBatch
- Test.QuickCheck.Classes: arrow :: (Arrow ~>, Show (d ~> e), Show (c ~> d), Show (b ~> c), Show b, Show c, Show d, Show e, Arbitrary (d ~> e), Arbitrary (c ~> d), Arbitrary (b ~> c), Arbitrary b, Arbitrary c, Arbitrary d, Arbitrary e, EqProp (b ~> e), EqProp (b ~> d), EqProp ((b, d) ~> c), EqProp ((b, d) ~> (c, d)), EqProp ((b, e) ~> (d, e)), EqProp ((b, d) ~> (c, e)), EqProp b, EqProp c, EqProp d, EqProp e) => b ~> (c, d, e) -> TestBatch
+ Test.QuickCheck.Classes: arrow :: (Arrow ~>, Show (d ~> e), Show (c ~> d), Show (b ~> c), Show b, Show c, Show d, Show e, Arbitrary (d ~> e), Arbitrary (c ~> d), Arbitrary (b ~> c), Arbitrary b, Arbitrary c, Arbitrary d, Arbitrary e, CoArbitrary b, CoArbitrary c, CoArbitrary d, EqProp (b ~> e), EqProp (b ~> d), EqProp ((b, d) ~> c), EqProp ((b, d) ~> (c, d)), EqProp ((b, e) ~> (d, e)), EqProp ((b, d) ~> (c, e)), EqProp b, EqProp c, EqProp d, EqProp e) => b ~> (c, d, e) -> TestBatch
- Test.QuickCheck.Classes: arrowChoice :: (ArrowChoice ~>, Show (b ~> c), Arbitrary (b ~> c), Arbitrary b, Arbitrary c, Arbitrary d, Arbitrary e, EqProp ((Either b d) ~> (Either c e)), EqProp ((Either b d) ~> (Either c d))) => b ~> (c, d, e) -> TestBatch
+ Test.QuickCheck.Classes: arrowChoice :: (ArrowChoice ~>, Show (b ~> c), Arbitrary (b ~> c), Arbitrary b, Arbitrary c, Arbitrary d, Arbitrary e, CoArbitrary b, CoArbitrary d, EqProp ((Either b d) ~> (Either c e)), EqProp ((Either b d) ~> (Either c d))) => b ~> (c, d, e) -> TestBatch
- Test.QuickCheck.Classes: functor :: (Functor m, Arbitrary a, Arbitrary b, Arbitrary c, Show (m a), Arbitrary (m a), EqProp (m a), EqProp (m c)) => m (a, b, c) -> TestBatch
+ Test.QuickCheck.Classes: functor :: (Functor m, Arbitrary a, Arbitrary b, Arbitrary c, CoArbitrary a, CoArbitrary b, Show (m a), Arbitrary (m a), EqProp (m a), EqProp (m c)) => m (a, b, c) -> TestBatch
- Test.QuickCheck.Classes: monad :: (Monad m, Show a, Arbitrary a, Arbitrary b, Arbitrary (m a), EqProp (m a), Show (m a), Arbitrary (m b), EqProp (m b), Arbitrary (m c), EqProp (m c)) => m (a, b, c) -> TestBatch
+ Test.QuickCheck.Classes: monad :: (Monad m, Show a, Arbitrary a, CoArbitrary a, Arbitrary b, CoArbitrary b, Arbitrary (m a), EqProp (m a), Show (m a), Arbitrary (m b), EqProp (m b), Arbitrary (m c), EqProp (m c)) => m (a, b, c) -> TestBatch
- Test.QuickCheck.Classes: monadFunctor :: (Functor m, Monad m, Arbitrary a, Arbitrary b, Arbitrary (m a), Show (m a), EqProp (m b)) => m (a, b) -> TestBatch
+ Test.QuickCheck.Classes: monadFunctor :: (Functor m, Monad m, Arbitrary a, Arbitrary b, CoArbitrary a, Arbitrary (m a), Show (m a), EqProp (m b)) => m (a, b) -> TestBatch
- Test.QuickCheck.Classes: monadOr :: (MonadPlus m, Show a, Show (m a), Arbitrary a, Arbitrary (m a), Arbitrary (m b), EqProp (m a), EqProp (m b)) => m (a, b) -> TestBatch
+ Test.QuickCheck.Classes: monadOr :: (MonadPlus m, Show a, Show (m a), Arbitrary a, CoArbitrary a, Arbitrary (m a), Arbitrary (m b), EqProp (m a), EqProp (m b)) => m (a, b) -> TestBatch
- Test.QuickCheck.Classes: monadPlus :: (MonadPlus m, Show (m a), Arbitrary a, Arbitrary (m a), Arbitrary (m b), EqProp (m a), EqProp (m b)) => m (a, b) -> TestBatch
+ Test.QuickCheck.Classes: monadPlus :: (MonadPlus m, Show (m a), Arbitrary a, CoArbitrary a, Arbitrary (m a), Arbitrary (m b), EqProp (m a), EqProp (m b)) => m (a, b) -> TestBatch
- Test.QuickCheck.Classes: traversable :: (Traversable f, Monoid m, Show (f a), Arbitrary (f a), Arbitrary b, Arbitrary a, Arbitrary m, EqProp (f b), EqProp m) => f (a, b, m) -> TestBatch
+ Test.QuickCheck.Classes: traversable :: (Traversable f, Monoid m, Show (f a), Arbitrary (f a), Arbitrary b, Arbitrary a, Arbitrary m, CoArbitrary a, EqProp (f b), EqProp m) => f (a, b, m) -> TestBatch
Files
- checkers.cabal +3/−2
- src/Test/QuickCheck/Checkers.hs +65/−52
- src/Test/QuickCheck/Classes.hs +9/−5
- src/Test/QuickCheck/Instances/Array.hs +2/−0
- src/Test/QuickCheck/Instances/Char.hs +9/−3
- src/Test/QuickCheck/Instances/Int.hs +12/−4
- src/Test/QuickCheck/Instances/Word.hs +12/−4
- src/Test/QuickCheck/Utils.hs +54/−0
checkers.cabal view
@@ -1,5 +1,5 @@ Name: checkers-Version: 0.1.4+Version: 0.2 Cabal-Version: >= 1.2 Synopsis: Check properties on standard classes and data structures. Category: Testing@@ -26,8 +26,9 @@ Library hs-Source-Dirs: src Extensions:- Build-Depends: base, random, QuickCheck, array >= 0.1+ Build-Depends: base, random, QuickCheck>=2, array >= 0.1 Exposed-Modules: + Test.QuickCheck.Utils Test.QuickCheck.Checkers Test.QuickCheck.Applicative Test.QuickCheck.Classes
src/Test/QuickCheck/Checkers.hs view
@@ -20,7 +20,7 @@ ( -- * Misc Test, TestBatch, unbatch, checkBatch, quickBatch, verboseBatch- , probablisticPureCheck+ -- , probablisticPureCheck , Unop, Binop, genR, inverseL, inverse , FracT, NumT, OrdT, T -- * Generalized equality@@ -36,8 +36,8 @@ , eqModels , Model1(..) -- * Some handy testing types- , Positive, NonZero(..), NonNegative(..)- , suchThat, suchThatMaybe+ -- , Positive, NonZero(..), NonNegative(..)+ -- , suchThat, suchThatMaybe , arbs, gens , (.&.) , arbitrarySatisfying@@ -51,12 +51,17 @@ import Data.List (foldl') import System.Random import Test.QuickCheck-import System.IO.Unsafe+-- import System.IO.Unsafe +import Test.QuickCheck.Gen (Gen (..)) -- for rand+-- import Test.QuickCheck.Property (Prop(..)) -- for evaluate+ import Test.QuickCheck.Utils++-- import Test.QuickCheck.Utils import Test.QuickCheck.Applicative ()-import Test.QuickCheck.Instances.Num-import Control.Monad.Extensions+-- import Test.QuickCheck.Instances.Num+-- import Control.Monad.Extensions -- import qualified Data.Stream as S@@ -79,13 +84,13 @@ -- TODO: consider a tree structure so that flattening is unnecessary. -- | Run a batch of tests. See 'quickBatch' and 'verboseBatch'.-checkBatch :: Config -> TestBatch -> IO ()-checkBatch config (name,tests) =+checkBatch :: Args -> TestBatch -> IO ()+checkBatch args (name,tests) = do putStrLn $ "\n" ++ name ++ ":" mapM_ pr tests where pr (s,p) = do putStr (padTo (width + 4) (" "++s ++ ":"))- catch (check config p) print+ catch (quickCheckWith args p) print width = foldl' max 0 (map (length.fst) tests) padTo :: Int -> String -> String@@ -99,10 +104,13 @@ verboseBatch :: TestBatch -> IO () verboseBatch = checkBatch verbose' -quick', verbose' :: Config-quick' = defaultConfig { configMaxTest = 500 }-verbose' = quick' { configEvery = \ n args -> show n ++ ":\n" ++ unlines args }+quick', verbose' :: Args+quick' = stdArgs { maxSuccess = 500 }+verbose' = quick'+ -- quick' { configEvery = \ n args -> show n ++ ":\n" ++ unlines args } +-- TODO: Restore verbose functionality. How in QC2?+ {- -- TODO: change TestBatch to be hierarchical/recursive, rather than@@ -407,36 +415,22 @@ -- from QC2, plus tweaks -type Positive a = NonZero (NonNegative a)--newtype NonZero a = NonZero { unNonZero :: a }- deriving ( Eq, Ord, Num, Integral, Real, Enum, Show, Read )--instance (Num a, Arbitrary a) => Arbitrary (NonZero a) where- arbitrary = fmap NonZero $ arbitrary `suchThat` (/= 0)- coarbitrary = coarbitrary . unNonZero--newtype NonNegative a = NonNegative { unNonNegative :: a }- deriving ( Eq, Ord, Num, Integral, Real, Enum, Show, Read )--instance (Num a, Arbitrary a) => Arbitrary (NonNegative a) where- arbitrary = nonNegative- coarbitrary = coarbitrary . unNonNegative+-- type Positive a = NonZero (NonNegative a) arbitrarySatisfying :: Arbitrary a => (a -> Bool) -> Gen a arbitrarySatisfying = (arbitrary `suchThat`) --- | Generates a value that satisfies a predicate.-suchThat :: Gen a -> (a -> Bool) -> Gen a-gen `suchThat` p = satisfiesM p gen+-- -- | Generates a value that satisfies a predicate.+-- suchThat :: Gen a -> (a -> Bool) -> Gen a+-- gen `suchThat` p = satisfiesM p gen --- | Tries to generate a value that satisfies a predicate.-suchThatMaybe :: Gen a -> (a -> Bool) -> Gen (Maybe a)-gen `suchThatMaybe` p = sized (try 0 . max 1)- where- try _ 0 = return Nothing- try k n = do x <- resize (2*k+n) gen- if p x then return (Just x) else try (k+1) (n-1)+-- -- | Tries to generate a value that satisfies a predicate.+-- suchThatMaybe :: Gen a -> (a -> Bool) -> Gen (Maybe a)+-- gen `suchThatMaybe` p = sized (try 0 . max 1)+-- where+-- try _ 0 = return Nothing+-- try k n = do x <- resize (2*k+n) gen+-- if p x then return (Just x) else try (k+1) (n-1) -- | Generate n arbitrary values arbs :: Arbitrary a => Int -> IO [a]@@ -449,11 +443,6 @@ -- The next two are from twanvl: -infixr 3 .&.--- | Property conjunction-(.&.) :: (Testable prop1, Testable prop2) => prop1 -> prop2 -> Property-p1 .&. p2 = property $ \b -> if b then property p1 else property p2- instance Testable a => Testable [a] where property [] = property True property props = property $ \n -> props !! (n `mod` len)@@ -462,30 +451,54 @@ instance (Testable a, Testable b) => Testable (a,b) where property = uncurry (.&.) -probablisticPureCheck :: Testable a => Config -> a -> Bool-probablisticPureCheck config a = unsafePerformIO $+{-+probablisticPureCheck :: Testable a => Args -> a -> Bool+probablisticPureCheck args a = unsafePerformIO $ do rnd <- newStdGen- probablisticPureTests config (evaluate a) rnd 0 0 []+ probablisticPureTests args (evaluate a) rnd 0 0 [] -probablisticPureTests :: Config++probablisticPureTests :: Args -> Gen Result -> StdGen -> Int -> Int -> [[String]] -> IO Bool-probablisticPureTests config gen rnd0 ntest nfail stamps- | ntest == configMaxTest config = return True- | nfail == configMaxFail config = return True+probablisticPureTests args gen rnd0 ntest nfail stamps+ | ntest == maxSuccess args = return True+ | nfail == maxDiscard args = return True | otherwise = case ok result of Nothing ->- probablisticPureTests config gen rnd1 ntest (nfail+1) stamps+ probablisticPureTests args gen rnd1 ntest (nfail+1) stamps Just True ->- probablisticPureTests config gen rnd1 (ntest+1) nfail+ probablisticPureTests args gen rnd1 (ntest+1) nfail (stamp result:stamps) Just False -> return False where- result = generate (configSize config ntest) rnd2 gen+ result = generate (maxSize config ntest) rnd2 gen (rnd1,rnd2) = split rnd0++-}++-- TODO: resurrect probablistic stuff. bob?+++{--------------------------------------------------------------------+ Copied (& tweaked) from QC1+--------------------------------------------------------------------}++-- TODO: are there QC2 replacements for these QC1 operations?++rand :: Gen StdGen+rand = MkGen (\r _ -> r)++generate :: Int -> StdGen -> Gen a -> a+generate n rnd (MkGen m) = m rnd' size+ where+ (size, rnd') = randomR (0, n) rnd++-- evaluate :: Testable a => a -> Gen Result+-- evaluate a = gen where MkProp gen = property a
src/Test/QuickCheck/Classes.hs view
@@ -154,6 +154,7 @@ functor :: forall m a b c. ( Functor m , Arbitrary a, Arbitrary b, Arbitrary c+ , CoArbitrary a, CoArbitrary b , Show (m a), Arbitrary (m a), EqProp (m a), EqProp (m c)) => m (a,b,c) -> TestBatch functor = const ( "functor"@@ -210,7 +211,7 @@ -- properties applicative :: forall m a b c. ( Applicative m- , Arbitrary a, Arbitrary b, Arbitrary (m a)+ , Arbitrary a, CoArbitrary a, Arbitrary b, Arbitrary (m a) , Arbitrary (m (b -> c)), Show (m (b -> c)) , Arbitrary (m (a -> b)), Show (m (a -> b)) , Show a, Show (m a)@@ -275,7 +276,7 @@ -- | Properties to check that the 'Monad' @m@ satisfies the monad properties monad :: forall m a b c. ( Monad m- , Show a, Arbitrary a, Arbitrary b+ , Show a, Arbitrary a, CoArbitrary a, Arbitrary b, CoArbitrary b , Arbitrary (m a), EqProp (m a), Show (m a) , Arbitrary (m b), EqProp (m b) , Arbitrary (m c), EqProp (m c)@@ -299,7 +300,7 @@ -- | Law for monads that are also instances of 'Functor'. monadFunctor :: forall m a b. ( Functor m, Monad m- , Arbitrary a, Arbitrary b+ , Arbitrary a, Arbitrary b, CoArbitrary a , Arbitrary (m a), Show (m a), EqProp (m b)) => m (a, b) -> TestBatch monadFunctor = const ( "monad functor"@@ -390,7 +391,7 @@ -- | Laws for MonadPlus instances with left distribution. monadPlus :: forall m a b. ( MonadPlus m, Show (m a)- , Arbitrary a, Arbitrary (m a), Arbitrary (m b)+ , Arbitrary a, CoArbitrary a, Arbitrary (m a), Arbitrary (m b) , EqProp (m a), EqProp (m b)) => m (a, b) -> TestBatch monadPlus = const ( "MonadPlus laws"@@ -411,7 +412,7 @@ -- | Laws for MonadPlus instances with left catch. monadOr :: forall m a b. ( MonadPlus m, Show a, Show (m a)- , Arbitrary a, Arbitrary (m a), Arbitrary (m b)+ , Arbitrary a, CoArbitrary a, Arbitrary (m a), Arbitrary (m b) , EqProp (m a), EqProp (m b)) => m (a, b) -> TestBatch monadOr = const ( "MonadOr laws"@@ -436,6 +437,7 @@ , Show b, Show c, Show d, Show e , Arbitrary (d ~> e), Arbitrary (c ~> d), Arbitrary (b ~> c) , Arbitrary b, Arbitrary c, Arbitrary d, Arbitrary e+ , CoArbitrary b, CoArbitrary c, CoArbitrary d , EqProp (b ~> e), EqProp (b ~> d) , EqProp ((b,d) ~> c) , EqProp ((b,d) ~> (c,d)), EqProp ((b,e) ~> (d,e))@@ -482,6 +484,7 @@ , Show (b ~> c) , Arbitrary (b ~> c) , Arbitrary b, Arbitrary c, Arbitrary d, Arbitrary e+ , CoArbitrary b, CoArbitrary d , EqProp ((Either b d) ~> (Either c e)) , EqProp ((Either b d) ~> (Either c d)) ) =>@@ -503,6 +506,7 @@ traversable :: forall f a b m. ( Traversable f, Monoid m, Show (f a) , Arbitrary (f a), Arbitrary b, Arbitrary a, Arbitrary m+ , CoArbitrary a , EqProp (f b), EqProp m) => f (a, b, m) -> TestBatch traversable = const ( "traversable"
src/Test/QuickCheck/Instances/Array.hs view
@@ -7,4 +7,6 @@ instance (Ix a, Integral a, Arbitrary b) => Arbitrary (Array a b) where arbitrary = (\x -> listArray (0,fromIntegral (length x - 1)) x) <$> arbitrary ++instance (Ix a, Integral a, CoArbitrary b) => CoArbitrary (Array a b) where coarbitrary = coarbitrary . elems
src/Test/QuickCheck/Instances/Char.hs view
@@ -9,9 +9,15 @@ import Test.QuickCheck import Test.QuickCheck.Instances.Eq -instance Arbitrary Char where- arbitrary = choose ('\0','\255')- coarbitrary = variant . ord+-- instance Arbitrary Char where+-- arbitrary = choose ('\0','\255')+-- coarbitrary = variant . ord++-- instance Arbitrary Char where+-- arbitrary = choose ('\0','\255')++-- instance CoArbitrary Char where+-- coarbitrary = variant . ord -- Bob: why the `rem` 4 ?
src/Test/QuickCheck/Instances/Int.hs view
@@ -6,16 +6,24 @@ instance Arbitrary Int64 where arbitrary = fromInteger <$> arbitrary- coarbitrary = variant . fromIntegral +instance CoArbitrary Int64 where+ coarbitrary = variant . (fromIntegral :: Int64 -> Int)+ instance Arbitrary Int32 where arbitrary = fromInteger <$> arbitrary- coarbitrary = variant . fromIntegral +instance CoArbitrary Int32 where+ coarbitrary = variant . (fromIntegral :: Int32 -> Int)+ instance Arbitrary Int16 where arbitrary = fromInteger <$> arbitrary- coarbitrary = variant . fromIntegral +instance CoArbitrary Int16 where+ coarbitrary = variant . (fromIntegral :: Int16 -> Int)+ instance Arbitrary Int8 where arbitrary = fromInteger <$> arbitrary- coarbitrary = variant . fromIntegral++instance CoArbitrary Int8 where+ coarbitrary = variant . (fromIntegral :: Int8 -> Int)
src/Test/QuickCheck/Instances/Word.hs view
@@ -6,16 +6,24 @@ instance Arbitrary Word64 where arbitrary = fromInteger <$> arbitrary- coarbitrary = variant . fromIntegral +instance CoArbitrary Word64 where+ coarbitrary = variant . (fromIntegral :: Word64 -> Int)+ instance Arbitrary Word32 where arbitrary = fromInteger <$> arbitrary- coarbitrary = variant . fromIntegral +instance CoArbitrary Word32 where+ coarbitrary = variant . (fromIntegral :: Word32 -> Int)+ instance Arbitrary Word16 where arbitrary = fromInteger <$> arbitrary- coarbitrary = variant . fromIntegral +instance CoArbitrary Word16 where+ coarbitrary = variant . (fromIntegral :: Word16 -> Int)+ instance Arbitrary Word8 where arbitrary = fromInteger <$> arbitrary- coarbitrary = variant . fromIntegral++instance CoArbitrary Word8 where+ coarbitrary = variant . (fromIntegral :: Word8 -> Int)
+ src/Test/QuickCheck/Utils.hs view
@@ -0,0 +1,54 @@+-----------------------------------------------------------------------------+-- |+-- Module : Test.QuickCheck.Utils+-- Copyright : (c) Andy Gill 2001+-- License : BSD-style (see the file libraries/base/LICENSE)+-- +-- Maintainer : libraries@haskell.org+-- Stability : experimental+-- Portability : portable+--+-- These are some general purpose utilities for use with QuickCheck.+--+-- Copied from QuickCheck 1.2.0.0. Doesn't appear in 2.x+-----------------------------------------------------------------------------++module Test.QuickCheck.Utils+ ( isAssociativeBy+ , isAssociative+ , isCommutableBy+ , isCommutable+ , isTotalOrder+ ) where++import Prelude++import Test.QuickCheck++isAssociativeBy :: (Show a,Testable prop) + => (a -> a -> prop) -> Gen a -> (a -> a -> a) -> Property+isAssociativeBy (===) src (#) = + forAll src $ \ a ->+ forAll src $ \ b ->+ forAll src $ \ c ->+ ((a # b) # c) === (a # (b # c))++isAssociative :: (Arbitrary a,Show a,Eq a) => (a -> a -> a) -> Property+isAssociative = isAssociativeBy (==) arbitrary++isCommutableBy :: (Show a,Testable prop) + => (b -> b -> prop) -> Gen a -> (a -> a -> b) -> Property+isCommutableBy (===) src (#) =+ forAll src $ \ a ->+ forAll src $ \ b ->+ (a # b) === (b # a)++isCommutable :: (Arbitrary a,Show a,Eq b) => (a -> a -> b) -> Property+isCommutable = isCommutableBy (==) arbitrary++isTotalOrder :: (Arbitrary a,Show a,Ord a) => a -> a -> Property+isTotalOrder x y = + classify (x > y) "less than" $+ classify (x == y) "equals" $+ classify (x < y) "greater than" $+ x < y || x == y || x > y