module Test.QuickCheck.DynamicLogic.CanGenerate (canGenerate) where
import System.IO.Unsafe
import Test.QuickCheck
canGenerate :: Double -> Gen a -> (a -> Bool) -> Bool
canGenerate :: forall a. Double -> Gen a -> (a -> Bool) -> Bool
canGenerate Double
prob Gen a
g a -> Bool
p = forall a. IO a -> a
unsafePerformIO forall a b. (a -> b) -> a -> b
$ Double -> IO Bool
tryToGenerate Double
1
where
tryToGenerate :: Double -> IO Bool
tryToGenerate Double
luck
| Double
luck forall a. Ord a => a -> a -> Bool
< Double
eps = forall (m :: * -> *) a. Monad m => a -> m a
return Bool
False
| Bool
otherwise = do
a
x <- forall a. Gen a -> IO a
generate Gen a
g
if a -> Bool
p a
x
then forall (m :: * -> *) a. Monad m => a -> m a
return Bool
True
else Double -> IO Bool
tryToGenerate (Double
luck forall a. Num a => a -> a -> a
* (Double
1 forall a. Num a => a -> a -> a
- Double
prob))
eps :: Double
eps = Double
1.0e-9