packages feed

quickcheck-classes 0.4.9 → 0.4.10

raw patch · 6 files changed

+56/−3 lines, 6 files

Files

changelog.md view
@@ -4,6 +4,12 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) and this project adheres to the [Haskell Package Versioning Policy](https://pvp.haskell.org/). +## [0.4.10] - 2018-05-03+### Added+- Property tests for `mconcat`, `sconcat`, and `stimes`. It isn't+  common to override the defaults for these, but when you do, it's+  nice to check that they agree with what they are supposed to do.+ ## [0.4.9] - 2018-04-06 ### Change - Be more careful with import of `Data.Primitive`. There is a
quickcheck-classes.cabal view
@@ -1,5 +1,5 @@ name: quickcheck-classes-version: 0.4.9+version: 0.4.10 synopsis: QuickCheck common typeclasses description:   This library provides quickcheck properties to ensure
src/Test/QuickCheck/Classes/Common.hs view
@@ -76,7 +76,16 @@     -- ^ Pairs of law name and property   } -myForAllShrink :: (Arbitrary a, Show b, Eq b) => Bool -> (a -> Bool) -> (a -> [String]) -> String -> (a -> b) -> String -> (a -> b) -> Property+myForAllShrink :: (Arbitrary a, Show b, Eq b)+  => Bool -- Should we show the RHS. It's better not to show it+          -- if the RHS is equal to the input.+  -> (a -> Bool) -- is the value a valid input+  -> (a -> [String])+  -> String+  -> (a -> b)+  -> String+  -> (a -> b)+  -> Property myForAllShrink displayRhs isValid showInputs name1 calc1 name2 calc2 =   again $   MkProperty $
src/Test/QuickCheck/Classes/Monoid.hs view
@@ -22,11 +22,14 @@ --   @mappend mempty a ≡ a@ -- [/Right Identity/] --   @mappend a mempty ≡ a@+-- [/Concatenation/]+--   @mconcat as ≡ foldr mappend mempty as@ monoidLaws :: (Monoid a, Eq a, Arbitrary a, Show a) => Proxy a -> Laws monoidLaws p = Laws "Monoid"   [ ("Associative", monoidAssociative p)   , ("Left Identity", monoidLeftIdentity p)   , ("Right Identity", monoidRightIdentity p)+  , ("Concatenation", monoidConcatenation p)   ]  -- | Tests everything from 'monoidProps' plus the following:@@ -37,6 +40,14 @@ commutativeMonoidLaws p = Laws "Commutative Monoid" $ lawsProperties (monoidLaws p) ++   [ ("Commutative", monoidCommutative p)   ]++monoidConcatenation :: forall a. (Monoid a, Eq a, Arbitrary a, Show a) => Proxy a -> Property+monoidConcatenation _ = myForAllShrink True (const True)+  (\(as :: [a]) -> ["as = " ++ show as])+  "mconcat as"+  (\as -> mconcat as)+  "foldr mappend mempty as"+  (\as -> foldr mappend mempty as)  monoidAssociative :: forall a. (Monoid a, Eq a, Arbitrary a, Show a) => Proxy a -> Property monoidAssociative _ = myForAllShrink True (const True)
src/Test/QuickCheck/Classes/Semigroup.hs view
@@ -6,22 +6,48 @@   ( semigroupLaws   ) where +import Prelude hiding (foldr1) import Data.Semigroup (Semigroup(..)) import Data.Proxy (Proxy) import Test.QuickCheck hiding ((.&.)) import Test.QuickCheck.Property (Property) -import Test.QuickCheck.Classes.Common (Laws(..))+import Test.QuickCheck.Classes.Common (Laws(..), myForAllShrink) +import Data.Foldable (foldr1,toList)+import Data.List.NonEmpty (NonEmpty((:|)))+ -- | Tests the following properties: -- -- [/Associative/] --   @a <> (b <> c) ≡ (a <> b) <> c@+-- [/Concatenation/]+--   @sconcat as ≡ foldr1 (<>) as@+-- [/Times/]+--   @stimes n a ≡ foldr1 (<>) (replicate n a)@ semigroupLaws :: (Semigroup a, Eq a, Arbitrary a, Show a) => Proxy a -> Laws semigroupLaws p = Laws "Semigroup"   [ ("Associative", semigroupAssociative p)+  , ("Concatenation", semigroupConcatenation p)+  , ("Times", semigroupTimes p)   ]  semigroupAssociative :: forall a. (Semigroup a, Eq a, Arbitrary a, Show a) => Proxy a -> Property semigroupAssociative _ = property $ \(a :: a) b c -> a <> (b <> c) == (a <> b) <> c++semigroupConcatenation :: forall a. (Semigroup a, Eq a, Arbitrary a, Show a) => Proxy a -> Property+semigroupConcatenation _ = myForAllShrink True (const True)+  (\(a, as :: [a]) -> ["as = " ++ show (a :| as)])+  "sconcat as"+  (\(a,as) -> sconcat (a :| as))+  "foldr1 (<>) as"+  (\(a,as) -> foldr1 (<>) (a :| as))++semigroupTimes :: forall a. (Semigroup a, Eq a, Arbitrary a, Show a) => Proxy a -> Property+semigroupTimes _ = myForAllShrink True (\(_,n) -> n > 0)+  (\(a :: a, n :: Int) -> ["a = " ++ show a, "n = " ++ show n])+  "stimes n a"+  (\(a,n) -> stimes n a)+  "foldr1 (<>) (replicate n a)"+  (\(a,n) -> foldr1 (<>) (replicate n a)) 
test/Spec.hs view
@@ -71,6 +71,7 @@ allLaws p =    [ primLaws p   , storableLaws p+  , semigroupLaws (Proxy :: Proxy (Sum a))   , monoidLaws (Proxy :: Proxy (Sum a))   , showReadLaws p #if defined(VERSION_aeson)