Skip to content

Commit 01711a1

Browse files
committed
Use replicateM
1 parent 371eda0 commit 01711a1

1 file changed

Lines changed: 5 additions & 17 deletions

File tree

src/Test/QuickCheck.purs

Lines changed: 5 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
-- | ```
1818
module Test.QuickCheck where
1919

20+
import Control.Monad (replicateM)
2021
import Control.Monad.Eff (Eff())
2122
import Control.Monad.Eff.Exception (Exception(), throwException, error)
2223
import 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.
6465
quickCheckPure :: 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

9084
instance 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).
9688
data 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

Comments
 (0)