1717-- | ```
1818module Test.QuickCheck where
1919
20+ import Control.Monad (replicateM )
2021import Control.Monad.Eff (Eff ())
2122import Control.Monad.Eff.Exception (Exception (), throwException , error )
2223import Control.Monad.Eff.Random (Random (), random )
@@ -62,14 +63,7 @@ quickCheck' n prop = do
6263-- | The first argument is the _random seed_ to be passed to the random generator.
6364-- | The second argument is the number of tests to run.
6465quickCheckPure :: forall prop . (Testable prop ) => Int -> Int -> prop -> [Result ]
65- quickCheckPure s = quickCheckPure' { newSeed: s, size: fromNumber 10 } where
66- quickCheckPure' st n prop = evalGen (go n) st
67- where
68- go n | n <= zero = return []
69- go n = do
70- result <- test prop
71- rest <- go (n - one)
72- return $ result : rest
66+ quickCheckPure s n prop = evalGen (replicateM n (test prop)) { newSeed: s, size: fromNumber 10 }
7367
7468-- | The `Testable` class represents _testable properties_.
7569-- |
@@ -88,9 +82,7 @@ instance testableBoolean :: Testable Boolean where
8882 test false = return $ Failed " Test returned false"
8983
9084instance testableFunction :: (Arbitrary t , Testable prop ) => Testable (t -> prop ) where
91- test f = do
92- t <- arbitrary
93- test (f t)
85+ test f = arbitrary >>= test <<< f
9486
9587-- | The result of a test: success or failure (with an error message).
9688data Result = Success | Failed String
@@ -112,12 +104,8 @@ instance showResult :: Show Result where
112104
113105-- | Self-documenting equality assertion
114106(===) :: forall a b . (Eq a , Show a ) => a -> a -> Result
115- (===) a b = a == b <?> msg
116- where
117- msg = show a ++ " /= " ++ show b
107+ (===) a b = a == b <?> show a ++ " /= " ++ show b
118108
119109-- | Self-documenting inequality assertion
120110(/==) :: forall a b . (Eq a , Show a ) => a -> a -> Result
121- (/==) a b = a /= b <?> msg
122- where
123- msg = show a ++ " == " ++ show b
111+ (/==) a b = a /= b <?> show a ++ " == " ++ show b
0 commit comments