{-# LANGUAGE Rank2Types #-}
module Test.Tasty.QuickCheck.Laws.ReaderMonad (
testReaderMonadLaws
, testReaderMonadLawLocalAsk
, testReaderMonadLawLocalLocal
, testReaderMonadLawLocalThenAsk
, testReaderMonadLawLocalReturn
, testReaderMonadLawLocalBind
) where
import Data.Proxy
( Proxy(..) )
import Data.Typeable
( Typeable, typeRep )
import Test.Tasty
( TestTree, testGroup )
import Test.Tasty.QuickCheck
( testProperty, Property, Arbitrary(..), CoArbitrary(..) )
import Text.Show.Functions
()
import Test.Tasty.QuickCheck.Laws.Class
testReaderMonadLaws
:: ( Monad m
, Eq r, Eq a, Eq b
, Show t, Show a
, Show (m a)
, Arbitrary t, Arbitrary r, Arbitrary a
, Arbitrary (m a), Arbitrary (m b)
, CoArbitrary r, CoArbitrary a
, Typeable m, Typeable r, Typeable a
)
=> Proxy m
-> Proxy t
-> Proxy r
-> Proxy a
-> Proxy b
-> (forall u. (Eq u) => t -> m u -> m u -> Bool)
-> m r
-> (forall u. (r -> r) -> m u -> m u)
-> TestTree
testReaderMonadLaws pm pt pr pa pb eq ask local =
let
label = "Reader Monad Laws for " ++ (show $ typeRep pm) ++ " with " ++
"r :: " ++ (show $ typeRep pr) ++ ", " ++
"a :: " ++ (show $ typeRep pa)
in
testGroup label
[ testReaderMonadLawLocalAsk pm pt pr eq ask local
, testReaderMonadLawLocalLocal pm pt pr pa eq local
, testReaderMonadLawLocalThenAsk pm pt pr pa eq ask local
, testReaderMonadLawLocalReturn pm pt pr pa eq local
, testReaderMonadLawLocalBind pm pt pr pa pb eq local
]
testReaderMonadLawLocalAsk
:: ( Monad m
, Eq r
, Show t
, Arbitrary t, Arbitrary r
, CoArbitrary r
)
=> Proxy m
-> Proxy t
-> Proxy r
-> (forall u. (Eq u) => t -> m u -> m u -> Bool)
-> m r
-> (forall u. (r -> r) -> m u -> m u)
-> TestTree
testReaderMonadLawLocalAsk pm pt pr eq ask local =
testProperty "local u ask === fmap u ask" $
readerMonadLawLocalAsk pm pt pr eq ask local
readerMonadLawLocalAsk
:: (Monad m, Eq r)
=> Proxy m -> Proxy t -> Proxy r
-> (forall u. (Eq u) => t -> m u -> m u -> Bool)
-> m r
-> (forall u. (r -> r) -> m u -> m u)
-> t -> (r -> r) -> Bool
readerMonadLawLocalAsk _ _ _ eq ask local t u =
(eq t) (local u ask) (fmap u ask)
testReaderMonadLawLocalLocal
:: ( Monad m
, Eq a
, Show t
, Show (m a)
, Arbitrary t, Arbitrary r
, Arbitrary (m a)
, CoArbitrary r
)
=> Proxy m
-> Proxy t
-> Proxy r
-> Proxy a
-> (forall u. (Eq u) => t -> m u -> m u -> Bool)
-> (forall u. (r -> r) -> m u -> m u)
-> TestTree
testReaderMonadLawLocalLocal pm pt pr pa eq local =
testProperty "local u (local v x) === local (v . u) x" $
readerMonadLawLocalLocal pm pt pr pa eq local
readerMonadLawLocalLocal
:: (Monad m, Eq a)
=> Proxy m -> Proxy t -> Proxy r -> Proxy a
-> (forall u. (Eq u) => t -> m u -> m u -> Bool)
-> (forall u. (r -> r) -> m u -> m u)
-> t -> (r -> r) -> (r -> r) -> m a -> Bool
readerMonadLawLocalLocal _ _ _ _ eq local t u v x =
(eq t) (local u (local v x)) (local (v . u) x)
testReaderMonadLawLocalThenAsk
:: ( Monad m
, Eq r
, Show t
, Show (m a)
, Arbitrary t, Arbitrary r
, Arbitrary (m a)
, CoArbitrary r
)
=> Proxy m
-> Proxy t
-> Proxy r
-> Proxy a
-> (forall u. (Eq u) => t -> m u -> m u -> Bool)
-> m r
-> (forall u. (r -> r) -> m u -> m u)
-> TestTree
testReaderMonadLawLocalThenAsk pm pt pr pa eq ask local =
testProperty "local u ask === fmap u ask" $
readerMonadLawLocalThenAsk pm pt pr pa eq ask local
readerMonadLawLocalThenAsk
:: (Monad m, Eq r)
=> Proxy m -> Proxy t -> Proxy r -> Proxy a
-> (forall u. (Eq u) => t -> m u -> m u -> Bool)
-> m r
-> (forall u. (r -> r) -> m u -> m u)
-> t -> (r -> r) -> m a -> Bool
readerMonadLawLocalThenAsk _ _ _ _ eq ask local t u x =
(eq t) (local u x >> ask) (ask >>= \r -> local u x >> return r)
testReaderMonadLawLocalReturn
:: ( Monad m
, Eq a
, Show t, Show a
, Arbitrary t, Arbitrary r, Arbitrary a
, CoArbitrary r
)
=> Proxy m
-> Proxy t
-> Proxy r
-> Proxy a
-> (forall u. (Eq u) => t -> m u -> m u -> Bool)
-> (forall u. (r -> r) -> m u -> m u)
-> TestTree
testReaderMonadLawLocalReturn pm pt pr pa eq local =
testProperty "local u (return a) === return a" $
readerMonadLawLocalReturn pm pt pr pa eq local
readerMonadLawLocalReturn
:: (Monad m, Eq a)
=> Proxy m -> Proxy t -> Proxy r -> Proxy a
-> (forall u. (Eq u) => t -> m u -> m u -> Bool)
-> (forall u. (r -> r) -> m u -> m u)
-> t -> (r -> r) -> a -> Bool
readerMonadLawLocalReturn _ _ _ _ eq local t u a =
(eq t) (local u (return a)) (return a)
testReaderMonadLawLocalBind
:: ( Monad m
, Eq b
, Show t, Show a
, Show (m a)
, Arbitrary t, Arbitrary r, Arbitrary a
, Arbitrary (m a), Arbitrary (m b)
, CoArbitrary r, CoArbitrary a
)
=> Proxy m
-> Proxy t
-> Proxy r
-> Proxy a
-> Proxy b
-> (forall u. (Eq u) => t -> m u -> m u -> Bool)
-> (forall u. (r -> r) -> m u -> m u)
-> TestTree
testReaderMonadLawLocalBind pm pt pr pa pb eq local =
testProperty "local u (x >>= f) === local u x >>= (local u . f)" $
readerMonadLawLocalBind pm pt pr pa pb eq local
readerMonadLawLocalBind
:: (Monad m, Eq b)
=> Proxy m -> Proxy t -> Proxy r -> Proxy a -> Proxy b
-> (forall u. (Eq u) => t -> m u -> m u -> Bool)
-> (forall u. (r -> r) -> m u -> m u)
-> t -> (r -> r) -> m a -> (a -> m b) -> Bool
readerMonadLawLocalBind _ _ _ _ _ eq local t u x f =
(eq t) (local u (x >>= f)) (local u x >>= (local u . f))