tasty-quickcheck-laws 0.0.1 → 0.0.2
raw patch · 16 files changed
+129/−20 lines, 16 filesPVP ok
version bump matches the API change (PVP)
API changes (from Hackage documentation)
+ Test.Tasty.QuickCheck.Laws.MaybeMonad: testMaybeMonadLawBailThen :: (Monad m, Eq a, Show t, Arbitrary t, Arbitrary (m a), Show (m a)) => Proxy m -> Proxy t -> Proxy a -> (forall u. Eq u => t -> m u -> m u -> Bool) -> (forall a. m a) -> TestTree
+ Test.Tasty.QuickCheck.Laws.MaybeMonad: testMaybeMonadLaws :: (Monad m, Eq a, Show t, Show a, Show (m a), Arbitrary t, Arbitrary a, Arbitrary (m a), Typeable m, Typeable a) => Proxy m -> Proxy t -> Proxy a -> (forall u. Eq u => t -> m u -> m u -> Bool) -> (forall a. m a) -> TestTree
Files
- CHANGELOG.md +10/−0
- README.md +1/−0
- src/Test/Tasty/QuickCheck/Laws.hs +3/−1
- src/Test/Tasty/QuickCheck/Laws/Applicative.hs +1/−1
- src/Test/Tasty/QuickCheck/Laws/Class.hs +1/−1
- src/Test/Tasty/QuickCheck/Laws/Eq.hs +1/−1
- src/Test/Tasty/QuickCheck/Laws/ErrorMonad.hs +1/−1
- src/Test/Tasty/QuickCheck/Laws/Functor.hs +1/−1
- src/Test/Tasty/QuickCheck/Laws/MaybeMonad.hs +86/−0
- src/Test/Tasty/QuickCheck/Laws/Monad.hs +2/−2
- src/Test/Tasty/QuickCheck/Laws/Monoid.hs +1/−1
- src/Test/Tasty/QuickCheck/Laws/ReaderMonad.hs +4/−4
- src/Test/Tasty/QuickCheck/Laws/StateMonad.hs +1/−1
- src/Test/Tasty/QuickCheck/Laws/WriterMonad.hs +2/−2
- tasty-quickcheck-laws.cabal +2/−1
- test/Main.hs +12/−3
CHANGELOG.md view
@@ -1,6 +1,16 @@ Changelog for tasty-quickcheck-laws =================================== +0.0.2+-----++* Added+ * Maybe monad laws+* Fixed+ * Clarified license (it's BSD3)+ * Bug in reference Reader monad implementation,+ exposing a second bug in the local-local property.+ 0.0.1 -----
README.md view
@@ -16,3 +16,4 @@ * Reader Monad * Writer Monad * Error Monad+* Maybe Monad
src/Test/Tasty/QuickCheck/Laws.hs view
@@ -2,7 +2,7 @@ Module : Test.Tasty.QuickCheck.Laws Description : Prefab tasty trees of quickcheck properties for lawful type classes Copyright : 2018, Automattic, Inc.-License : GPL-3+License : BSD3 Maintainer : Nathan Bloomfield (nbloomf@gmail.com) Stability : experimental Portability : POSIX@@ -19,6 +19,7 @@ , module Test.Tasty.QuickCheck.Laws.ReaderMonad , module Test.Tasty.QuickCheck.Laws.StateMonad , module Test.Tasty.QuickCheck.Laws.WriterMonad+ , module Test.Tasty.QuickCheck.Laws.MaybeMonad ) where import Test.Tasty.QuickCheck.Laws.Applicative@@ -31,3 +32,4 @@ import Test.Tasty.QuickCheck.Laws.ReaderMonad import Test.Tasty.QuickCheck.Laws.StateMonad import Test.Tasty.QuickCheck.Laws.WriterMonad+import Test.Tasty.QuickCheck.Laws.MaybeMonad
src/Test/Tasty/QuickCheck/Laws/Applicative.hs view
@@ -2,7 +2,7 @@ Module : Test.Tasty.QuickCheck.Laws.Applicative Description : Prefab tasty trees of quickcheck properties for the Applicative laws Copyright : 2018, Automattic, Inc.-License : GPL-3+License : BSD3 Maintainer : Nathan Bloomfield (nbloomf@gmail.com) Stability : experimental Portability : POSIX
src/Test/Tasty/QuickCheck/Laws/Class.hs view
@@ -2,7 +2,7 @@ Module : Test.Tasty.QuickCheck.Laws.Class Description : Convenience typeclass Copyright : 2018, Automattic, Inc.-License : GPL-3+License : BSD3 Maintainer : Nathan Bloomfield (nbloomf@gmail.com) Stability : experimental Portability : POSIX
src/Test/Tasty/QuickCheck/Laws/Eq.hs view
@@ -2,7 +2,7 @@ Module : Test.Tasty.QuickCheck.Laws.Eq Description : Prefab tasty trees of quickcheck properties for the Eq laws Copyright : 2018, Automattic, Inc.-License : GPL-3+License : BSD3 Maintainer : Nathan Bloomfield (nbloomf@gmail.com) Stability : experimental Portability : POSIX
src/Test/Tasty/QuickCheck/Laws/ErrorMonad.hs view
@@ -2,7 +2,7 @@ Module : Test.Tasty.QuickCheck.Laws.ErrorMonad Description : Prefab tasty trees of quickcheck properties for error monad laws Copyright : 2018, Automattic, Inc.-License : GPL-3+License : BSD3 Maintainer : Nathan Bloomfield (nbloomf@gmail.com) Stability : experimental Portability : POSIX
src/Test/Tasty/QuickCheck/Laws/Functor.hs view
@@ -2,7 +2,7 @@ Module : Test.Tasty.QuickCheck.Laws.Functor Description : Prefab tasty trees of quickcheck properties for the Functor laws Copyright : 2018, Automattic, Inc.-License : GPL-3+License : BSD3 Maintainer : Nathan Bloomfield (nbloomf@gmail.com) Stability : experimental Portability : POSIX
+ src/Test/Tasty/QuickCheck/Laws/MaybeMonad.hs view
@@ -0,0 +1,86 @@+{- |+Module : Test.Tasty.QuickCheck.Laws.MaybeMonad+Description : Prefab tasty trees of quickcheck properties for the maybe monad laws+Copyright : 2019, Automattic, Inc.+License : BSD3+Maintainer : Nathan Bloomfield (nbloomf@gmail.com)+Stability : experimental+Portability : POSIX+-}++++{-# LANGUAGE Rank2Types #-}+module Test.Tasty.QuickCheck.Laws.MaybeMonad (+ testMaybeMonadLaws++ -- * Maybe Monad Laws+ , testMaybeMonadLawBailThen+) where++import Data.Proxy+ ( Proxy(..) )+import Data.Typeable+ ( Typeable, typeRep )+import Test.Tasty+ ( TestTree, testGroup )+import Test.Tasty.QuickCheck+ ( testProperty, Property, Arbitrary(..) )+import Text.Show.Functions+ ()++import Test.Tasty.QuickCheck.Laws.Class++++-- | Constructs a @TestTree@ checking that the maybe monad laws hold for @m@ with maybe type @r@ and value types @a@ and @b@, using a given equality test for values of type @forall u. m u@. The equality context type @t@ is for constructors @m@ from which we can only extract a value within a context, such as reader-like constructors.+testMaybeMonadLaws+ :: ( Monad m+ , Eq a+ , Show t, Show a+ , Show (m a)+ , Arbitrary t, Arbitrary a+ , Arbitrary (m a)+ , Typeable m, Typeable a+ )+ => Proxy m -- ^ Type constructor under test+ -> Proxy t -- ^ Equality context for @m@+ -> Proxy a -- ^ Value type+ -> (forall u. (Eq u) => t -> m u -> m u -> Bool) -- ^ Equality test+ -> (forall a. m a) -- ^ @bail@+ -> TestTree+testMaybeMonadLaws pm pt pa eq bail =+ let+ label = "Maybe Monad Laws for " ++ (show $ typeRep pm) ++ " with " +++ "a :: " ++ (show $ typeRep pa)+ in+ testGroup label+ [ testMaybeMonadLawBailThen pm pt pa eq bail+ ]++++-- | @bail >> x === bail@+testMaybeMonadLawBailThen+ :: ( Monad m, Eq a+ , Show t+ , Arbitrary t, Arbitrary (m a), Show (m a)+ )+ => Proxy m -- ^ Type constructor under test+ -> Proxy t -- ^ Equality context for @m@+ -> Proxy a -- ^ Value type+ -> (forall u. (Eq u) => t -> m u -> m u -> Bool) -- ^ Equality test+ -> (forall a. m a) -- ^ @bail@+ -> TestTree+testMaybeMonadLawBailThen pm pt pa eq bail =+ testProperty "bail >> x === x" $+ maybeMonadLawBailThen pm pt pa eq bail++maybeMonadLawBailThen+ :: (Monad m, Eq a)+ => Proxy m -> Proxy t -> Proxy a+ -> (forall u. (Eq u) => t -> m u -> m u -> Bool) -- ^ Equality test+ -> (forall a. m a) -- ^ bail+ -> t -> m a -> Bool+maybeMonadLawBailThen _ _ _ eq bail t x =+ (eq t) (bail >> x) (bail)
src/Test/Tasty/QuickCheck/Laws/Monad.hs view
@@ -2,7 +2,7 @@ Module : Test.Tasty.QuickCheck.Laws.Monad Description : Prefab tasty trees of quickcheck properties for the Monad laws Copyright : 2018, Automattic, Inc.-License : GPL-3+License : BSD3 Maintainer : Nathan Bloomfield (nbloomf@gmail.com) Stability : experimental Portability : POSIX@@ -14,7 +14,7 @@ {-# LANGUAGE Rank2Types #-} module Test.Tasty.QuickCheck.Laws.Monad (- testMonadLaws+ testMonadLaws -- * Monad Laws , testMonadLawRightIdentity
src/Test/Tasty/QuickCheck/Laws/Monoid.hs view
@@ -2,7 +2,7 @@ Module : Test.Tasty.QuickCheck.Laws.Monoid Description : Prefab tasty trees of quickcheck properties for the Monoid laws Copyright : 2018, Automattic, Inc.-License : GPL-3+License : BSD3 Maintainer : Nathan Bloomfield (nbloomf@gmail.com) Stability : experimental Portability : POSIX
src/Test/Tasty/QuickCheck/Laws/ReaderMonad.hs view
@@ -2,7 +2,7 @@ Module : Test.Tasty.QuickCheck.Laws.ReaderMonad Description : Prefab tasty trees of quickcheck properties for the reader monad laws Copyright : 2018, Automattic, Inc.-License : GPL-3+License : BSD3 Maintainer : Nathan Bloomfield (nbloomf@gmail.com) Stability : experimental Portability : POSIX@@ -106,7 +106,7 @@ --- | @local u (local v x) === local (u . v) x@+-- | @local u (local v x) === local (v . u) x@ testReaderMonadLawLocalLocal :: ( Monad m , Eq a@@ -124,7 +124,7 @@ -> (forall u. (r -> r) -> m u -> m u) -- ^ @local@ -> TestTree testReaderMonadLawLocalLocal pm pt pr pa eq local =- testProperty "local u (local v x) === local (u . v) x" $+ testProperty "local u (local v x) === local (v . u) x" $ readerMonadLawLocalLocal pm pt pr pa eq local readerMonadLawLocalLocal@@ -134,7 +134,7 @@ -> (forall u. (r -> r) -> m u -> m u) -- ^ local -> t -> (r -> r) -> (r -> r) -> m a -> Bool readerMonadLawLocalLocal _ _ _ _ eq local t u v x =- (eq t) (local u (local v x)) (local (u . v) x)+ (eq t) (local u (local v x)) (local (v . u) x)
src/Test/Tasty/QuickCheck/Laws/StateMonad.hs view
@@ -2,7 +2,7 @@ Module : Test.Tasty.QuickCheck.Laws.StateMonad Description : Prefab tasty trees of quickcheck properties for the state monad laws Copyright : 2018, Automattic, Inc.-License : GPL-3+License : BSD3 Maintainer : Nathan Bloomfield (nbloomf@gmail.com) Stability : experimental Portability : POSIX
src/Test/Tasty/QuickCheck/Laws/WriterMonad.hs view
@@ -2,7 +2,7 @@ Module : Test.Tasty.QuickCheck.Laws.WriterMonad Description : Prefab tasty trees of quickcheck properties for writer monad laws Copyright : 2018, Automattic, Inc.-License : GPL-3+License : BSD3 Maintainer : Nathan Bloomfield (nbloomf@gmail.com) Stability : experimental Portability : POSIX@@ -170,7 +170,7 @@ --- | @draft (return a) === return a@+-- | @draft (return a) === return (a, mempty)@ testWriterMonadLawDraftReturn :: ( Monoid w, Monad m , Eq w, Eq a
tasty-quickcheck-laws.cabal view
@@ -1,5 +1,5 @@ name: tasty-quickcheck-laws-version: 0.0.1+version: 0.0.2 description: Please see the README on GitHub at <https://github.com/nbloomf/tasty-quickcheck-laws#readme> homepage: https://github.com/nbloomf/tasty-quickcheck-laws#readme bug-reports: https://github.com/nbloomf/tasty-quickcheck-laws/issues@@ -45,6 +45,7 @@ Test.Tasty.QuickCheck.Laws.ReaderMonad Test.Tasty.QuickCheck.Laws.StateMonad Test.Tasty.QuickCheck.Laws.WriterMonad+ Test.Tasty.QuickCheck.Laws.MaybeMonad
test/Main.hs view
@@ -12,7 +12,8 @@ main :: IO () main = do- setEnv "NUM_TASTY_THREADS" "6"+ setEnv "TASTY_NUM_THREADS" "6"+ setEnv "TASTY_QUICKCHECK_TESTS" "1000" defaultMain $ testGroup "Laws" [ testGroup "Eq Laws" [ testEqLaws pU@@ -84,6 +85,11 @@ , testWriterMonadEquivalences (pWLs pI) pU (pLs' pI) pU (const (==)) tell draft listen pass ] ]+ , testGroup "Maybe Monads"+ [ testMaybeMonadLaws pMb pU pU eqMaybe Nothing+ , testMaybeMonadLaws pMb pU pB eqMaybe Nothing+ , testMaybeMonadLaws pMb pU pI eqMaybe Nothing+ ] ] @@ -115,6 +121,9 @@ +eqMaybe :: (Eq a) => () -> Maybe a -> Maybe a -> Bool+eqMaybe () = (==)+ -- Basic State Monad data State s a = State@@ -174,8 +183,8 @@ instance Functor (Reader r) where fmap f x = x >>= (return . f) -instance (Arbitrary a) => Arbitrary (Reader r a) where- arbitrary = return <$> arbitrary+instance (Arbitrary a, CoArbitrary r) => Arbitrary (Reader r a) where+ arbitrary = Reader <$> arbitrary instance Show (Reader r a) where show _ = "<Reader>"