checkers 0.4.14 → 0.5.0
raw patch · 3 files changed
+76/−23 lines, 3 filesPVP ok
version bump matches the API change (PVP)
API changes (from Hackage documentation)
+ Test.QuickCheck.Checkers: instance Test.QuickCheck.Checkers.EqProp GHC.Integer.Type.Integer
- Test.QuickCheck.Checkers: antiSymmetric :: (Arbitrary a, Show a, Eq a) => BinRel a -> (a -> Gen a) -> Property
+ Test.QuickCheck.Checkers: antiSymmetric :: (Arbitrary a, Show a, Eq a) => BinRel a -> Property
- Test.QuickCheck.Classes: monad :: forall m a b c. (Monad m, Show a, Arbitrary a, CoArbitrary a, 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: monad :: forall m a b c. (Monad m, Show a, Arbitrary a, CoArbitrary a, CoArbitrary b, Arbitrary (m a), EqProp (m a), Show (m a), Arbitrary (m b), EqProp (m b), Arbitrary (m c), EqProp (m c), Show (m (a -> b)), Arbitrary (m (a -> b))) => m (a, b, c) -> TestBatch
- Test.QuickCheck.Classes: semigroup :: forall a. (Semigroup a, Show a, Arbitrary a, EqProp a) => a -> TestBatch
+ Test.QuickCheck.Classes: semigroup :: forall a n. (Semigroup a, Show a, Arbitrary a, EqProp a, Integral n, Show n, Arbitrary n) => (a, n) -> TestBatch
Files
- checkers.cabal +2/−2
- src/Test/QuickCheck/Checkers.hs +7/−11
- src/Test/QuickCheck/Classes.hs +67/−10
checkers.cabal view
@@ -1,5 +1,5 @@ Name: checkers-Version: 0.4.14+Version: 0.5.0 Cabal-Version: >= 1.6 Synopsis: Check properties on standard classes and data structures. Category: Testing@@ -26,7 +26,7 @@ Library hs-Source-Dirs: src Extensions:- Build-Depends: base >= 4 && < 5, random, QuickCheck>=2.3, array >= 0.1, semigroupoids >= 5 && < 6+ Build-Depends: base >= 4.8 && < 5, random, QuickCheck>=2.3, array >= 0.1, semigroupoids >= 5 && < 6 if !impl(ghc >= 8.0) build-depends: semigroups >= 0.18.2 && < 0.19
src/Test/QuickCheck/Checkers.hs view
@@ -190,6 +190,7 @@ instance EqProp Int where (=-=) = eq instance EqProp Float where (=-=) = eq instance EqProp Double where (=-=) = eq+instance EqProp Integer where (=-=) = eq -- Lists instance EqProp a => EqProp [a] where@@ -262,18 +263,13 @@ forAll (gen a) $ \ b -> (a `rel` b) ==> (b `rel` a) --- | Symmetric property: @a `rel` b && b `rel` a ==> a == b@. Generate--- @a@ randomly, but use @gen a@ to generate @b@. @gen@ ought to satisfy--- both @rel@ directions fairly often but not always.+-- | Antisymmetric property: @(a `rel` b) && (a /= b) ==> not (b `rel` a)@.+--+-- @since 0.5.0 antiSymmetric :: (Arbitrary a, Show a, Eq a) =>- BinRel a -> (a -> Gen a) -> Property-antiSymmetric rel gen =- property $ \ a ->- forAll (gen a) $ \ b ->- (a `rel` b) && (b `rel` a) ==> a == b---+ BinRel a -> Property+antiSymmetric rel =+ property $ \ a b -> (a `rel` b) && (a /= b) ==> not (b `rel` a) -- | Has a given left identity, according to '(=-=)' leftId :: (Show a, Arbitrary a, EqProp a) => (i -> a -> a) -> i -> Property
src/Test/QuickCheck/Classes.hs view
@@ -35,7 +35,8 @@ import Data.Functor.Alt (Alt ((<!>))) import Data.Functor.Bind (Bind ((>>-)), apDefault) import qualified Data.Functor.Bind as B (Bind (join))-import Data.Semigroup (Semigroup ((<>)))+import Data.List.NonEmpty (NonEmpty(..))+import Data.Semigroup (Semigroup (..)) import Data.Monoid (Monoid (mappend, mempty), Endo(..), Dual(..), Sum(..), Product(..)) import Data.Traversable (Traversable (..), fmapDefault, foldMapDefault) import Control.Applicative@@ -48,24 +49,44 @@ import Test.QuickCheck.Instances.Char () --- | Total ordering. @gen a@ ought to generate values @b@ satisfying @a--- `rel` b@ fairly often.+-- | Total ordering.+--+-- @gen a@ ought to generate values @b@ satisfying @a `rel` b@ fairly often. ordRel :: forall a. (Ord a, Show a, Arbitrary a) => BinRel a -> (a -> Gen a) -> TestBatch ordRel rel gen = ( "ord" , [ ("reflexive" , reflexive rel ) , ("transitive" , transitive rel gen)- , ("antiSymmetric", antiSymmetric rel gen)+ , ("antiSymmetric", antiSymmetric rel ) ] ) --- | Total ordering+-- | 'Ord' laws.+--+-- @gen a@ ought to generate values @b@ satisfying @a `rel` b@ fairly often. ord :: forall a. (Ord a, Show a, Arbitrary a) => (a -> Gen a) -> TestBatch-ord = ordRel (<=)--+ord gen =+ ( "Ord"+ , [ ("Reflexivity of (<=)", reflexive le)+ , ("Transitivity of (<=)", transitive le gen)+ , ("Antisymmetry of (<=)", antiSymmetric le)+ , ("x >= y = y <= x", p (\x y -> (x >= y) === (y <= x)))+ , ("x < y = x <= y && x /= y", p (\x y -> (x < y) === (x <= y && x /= y)))+ , ("x > y = y < x", p (\x y -> (x > y) === (y < x)))+ , ("x < y = compare x y == LT", p (\x y -> (x < y) === (compare x y == LT)))+ , ("x > y = compare x y == GT", p (\x y -> (x > y) === (compare x y == GT)))+ , ("x == y = compare x y == EQ", p (\x y -> (x == y) === (compare x y == EQ)))+ , ("min x y == if x <= y then x else y = True", p (\x y -> min x y === if x <= y then x else y))+ , ("max x y == if x >= y then x else y = True", p (\x y -> max x y === if x >= y then x else y))+ ]+ )+ where+ le :: a -> a -> Bool+ le = (<=)+ p :: (a -> a -> Property) -> Property+ p = property -- | 'Ord' morphism properties. @h@ is an 'Ord' morphism iff: --@@ -111,18 +132,40 @@ , [ ("left identity", leftId mappend (mempty :: a)) , ("right identity", rightId mappend (mempty :: a)) , ("associativity" , isAssoc (mappend :: Binop a))+#if MIN_VERSION_base(4,11,0)+ , ("mappend = (<>)", property monoidSemigroupP)+#endif+ , ("mconcat", property mconcatP) ] )+ where+#if MIN_VERSION_base(4,11,0)+ monoidSemigroupP :: a -> a -> Property+ monoidSemigroupP x y = mappend x y =-= x <> y+#endif+ mconcatP :: [a] -> Property+ mconcatP as = mconcat as =-= foldr mappend mempty as -- | Properties to check that the 'Semigroup' 'a' satisfies the semigroup -- properties. The argument value is ignored and is present only for its -- type.-semigroup :: forall a. (Semigroup a, Show a, Arbitrary a, EqProp a) =>- a -> TestBatch+--+-- @since 0.5.0+semigroup :: forall a n.+ ( Semigroup a, Show a, Arbitrary a, EqProp a+ , Integral n, Show n, Arbitrary n) =>+ (a, n) -> TestBatch semigroup = const ( "semigroup" , [("associativity", isAssoc ((<>) :: Binop a))+ ,("sconcat", property sconcatP)+ ,("stimes", property stimesP) ] )+ where+ sconcatP :: a -> [a] -> Property+ sconcatP a as = sconcat (a :| as) =-= foldr1 (<>) (a :| as)+ stimesP :: Positive n -> a -> Property+ stimesP (Positive n) a = stimes n a =-= foldr1 (<>) (replicate (fromIntegral n) a) -- | Monoid homomorphism properties. See also 'homomorphism'. monoidMorphism :: (Monoid a, Monoid b, EqProp b, Show a, Arbitrary a) =>@@ -429,24 +472,34 @@ , Arbitrary (m a), EqProp (m a), Show (m a) , Arbitrary (m b), EqProp (m b) , Arbitrary (m c), EqProp (m c)+ , Show (m (a -> b)), Arbitrary (m (a -> b)) ) => m (a,b,c) -> TestBatch monad = const ( "monad laws" , [ ("left identity", property leftP) , ("right identity", property rightP) , ("associativity" , property assocP)+ , ("pure", property pureP)+ , ("ap", property apP) ] ) where leftP :: (a -> m b) -> a -> Property rightP :: m a -> Property assocP :: m a -> (a -> m b) -> (b -> m c) -> Property+ pureP :: a -> Property+ apP :: m (a -> b) -> m a -> Property leftP f a = (return a >>= f) =-= f a rightP m = (m >>= return) =-= m assocP m f g = ((m >>= f) >>= g) =-= (m >>= (\x -> f x >>= g))+ pureP x = (pure x :: m a) =-= return x+ apP f x = (f <*> x) =-= (f `ap` x) -- | Law for monads that are also instances of 'Functor'.+--+-- Note that instances that satisfy 'applicative' and 'monad'+-- are implied to satisfy this property too. monadFunctor :: forall m a b. ( Monad m , Arbitrary b, CoArbitrary a@@ -458,6 +511,7 @@ bindReturnP :: (a -> b) -> m a -> Property bindReturnP f xs = fmap f xs =-= (xs >>= return . f) +-- | Note that 'monad' also contains these properties. monadApplicative :: forall m a b. ( Monad m , EqProp (m a), EqProp (m b)@@ -684,6 +738,8 @@ foldMapP f x = f `foldMap` x =-= f `foldMapDefault` x -- | Note that 'foldable' doesn't check the strictness of 'foldl'', `foldr'' and `foldMap''.+--+-- @since 0.4.13 foldable :: forall t a b m n o. ( Foldable t , CoArbitrary a, CoArbitrary b@@ -754,6 +810,7 @@ elemP :: o -> t o -> Property elemP o t = elem o t =-= elem o (toList t) +-- | @since 0.4.13 foldableFunctor :: forall t a m. ( Functor t, Foldable t , CoArbitrary a