module Test.QuickCheck.Extras where

import Control.Monad.Reader
import Control.Monad.State
import Test.QuickCheck.Monadic

runPropertyStateT :: Monad m => PropertyM (StateT s m) a -> s -> PropertyM m (a, s)
runPropertyStateT :: forall (m :: * -> *) s a.
Monad m =>
PropertyM (StateT s m) a -> s -> PropertyM m (a, s)
runPropertyStateT PropertyM (StateT s m) a
p s
s0 = (((a, s) -> Gen (m Property)) -> Gen (m Property))
-> PropertyM m (a, s)
forall (m :: * -> *) a.
((a -> Gen (m Property)) -> Gen (m Property)) -> PropertyM m a
MkPropertyM ((((a, s) -> Gen (m Property)) -> Gen (m Property))
 -> PropertyM m (a, s))
-> (((a, s) -> Gen (m Property)) -> Gen (m Property))
-> PropertyM m (a, s)
forall a b. (a -> b) -> a -> b
$ \(a, s) -> Gen (m Property)
k -> do
  StateT s m Property
m <- PropertyM (StateT s m) (a, s)
-> ((a, s) -> Gen (StateT s m Property))
-> Gen (StateT s m Property)
forall (m :: * -> *) a.
PropertyM m a -> (a -> Gen (m Property)) -> Gen (m Property)
unPropertyM (do a
a <- PropertyM (StateT s m) a
p; s
s <- StateT s m s -> PropertyM (StateT s m) s
forall (m :: * -> *) a. Monad m => m a -> PropertyM m a
run StateT s m s
forall s (m :: * -> *). MonadState s m => m s
get; (a, s) -> PropertyM (StateT s m) (a, s)
forall a. a -> PropertyM (StateT s m) a
forall (m :: * -> *) a. Monad m => a -> m a
return (a
a, s
s)) (((a, s) -> Gen (StateT s m Property))
 -> Gen (StateT s m Property))
-> ((a, s) -> Gen (StateT s m Property))
-> Gen (StateT s m Property)
forall a b. (a -> b) -> a -> b
$ (m Property -> StateT s m Property)
-> Gen (m Property) -> Gen (StateT s m Property)
forall a b. (a -> b) -> Gen a -> Gen b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap m Property -> StateT s m Property
forall (m :: * -> *) a. Monad m => m a -> StateT s m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (Gen (m Property) -> Gen (StateT s m Property))
-> ((a, s) -> Gen (m Property))
-> (a, s)
-> Gen (StateT s m Property)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (a, s) -> Gen (m Property)
k
  m Property -> Gen (m Property)
forall a. a -> Gen a
forall (m :: * -> *) a. Monad m => a -> m a
return (m Property -> Gen (m Property)) -> m Property -> Gen (m Property)
forall a b. (a -> b) -> a -> b
$ StateT s m Property -> s -> m Property
forall (m :: * -> *) s a. Monad m => StateT s m a -> s -> m a
evalStateT StateT s m Property
m s
s0

runPropertyReaderT :: Monad m => PropertyM (ReaderT e m) a -> e -> PropertyM m a
runPropertyReaderT :: forall (m :: * -> *) e a.
Monad m =>
PropertyM (ReaderT e m) a -> e -> PropertyM m a
runPropertyReaderT PropertyM (ReaderT e m) a
p e
e = ((a -> Gen (m Property)) -> Gen (m Property)) -> PropertyM m a
forall (m :: * -> *) a.
((a -> Gen (m Property)) -> Gen (m Property)) -> PropertyM m a
MkPropertyM (((a -> Gen (m Property)) -> Gen (m Property)) -> PropertyM m a)
-> ((a -> Gen (m Property)) -> Gen (m Property)) -> PropertyM m a
forall a b. (a -> b) -> a -> b
$ \a -> Gen (m Property)
k -> do
  ReaderT e m Property
m <- PropertyM (ReaderT e m) a
-> (a -> Gen (ReaderT e m Property)) -> Gen (ReaderT e m Property)
forall (m :: * -> *) a.
PropertyM m a -> (a -> Gen (m Property)) -> Gen (m Property)
unPropertyM PropertyM (ReaderT e m) a
p ((a -> Gen (ReaderT e m Property)) -> Gen (ReaderT e m Property))
-> (a -> Gen (ReaderT e m Property)) -> Gen (ReaderT e m Property)
forall a b. (a -> b) -> a -> b
$ (m Property -> ReaderT e m Property)
-> Gen (m Property) -> Gen (ReaderT e m Property)
forall a b. (a -> b) -> Gen a -> Gen b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap m Property -> ReaderT e m Property
forall (m :: * -> *) a. Monad m => m a -> ReaderT e m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (Gen (m Property) -> Gen (ReaderT e m Property))
-> (a -> Gen (m Property)) -> a -> Gen (ReaderT e m Property)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> Gen (m Property)
k
  m Property -> Gen (m Property)
forall a. a -> Gen a
forall (m :: * -> *) a. Monad m => a -> m a
return (m Property -> Gen (m Property)) -> m Property -> Gen (m Property)
forall a b. (a -> b) -> a -> b
$ ReaderT e m Property -> e -> m Property
forall r (m :: * -> *) a. ReaderT r m a -> r -> m a
runReaderT ReaderT e m Property
m e
e