@@ -57,18 +57,17 @@ import Prelude
57
57
import Control.Monad.Rec.Class (Step (..), tailRec )
58
58
import Data.Foldable (for_ )
59
59
import Data.FoldableWithIndex (foldlWithIndex )
60
- import Data.List (List )
60
+ import Data.List (List , (:) )
61
61
import Data.List as List
62
62
import Data.Maybe (Maybe (..))
63
63
import Data.Maybe.First (First (..))
64
- import Data.Tuple (Tuple (..))
65
- import Data.Unfoldable (replicateA )
64
+ import Data.Tuple (Tuple (..), snd )
66
65
import Effect (Effect )
67
66
import Effect.Console (log )
68
67
import Effect.Exception (throwException , error )
69
68
import Random.LCG (Seed , mkSeed , unSeed , randomSeed )
70
69
import Test.QuickCheck.Arbitrary (class Arbitrary , arbitrary , class Coarbitrary , coarbitrary )
71
- import Test.QuickCheck.Gen (Gen , evalGen , runGen , stateful )
70
+ import Test.QuickCheck.Gen (Gen , runGen )
72
71
73
72
-- | Test a property.
74
73
-- |
@@ -149,17 +148,33 @@ type LoopState =
149
148
-- | The first argument is the _random seed_ to be passed to the random generator.
150
149
-- | The second argument is the number of tests to run.
151
150
quickCheckPure :: forall prop . Testable prop => Seed -> Int -> prop -> List Result
152
- quickCheckPure s n prop = evalGen (replicateA n (test prop)) { newSeed: s, size: 10 }
151
+ quickCheckPure s n prop = map snd (quickCheckPure' s n prop)
153
152
154
153
-- | Test a property, returning all test results as a List, with the Seed that
155
154
-- | was used for each result.
156
155
-- |
157
156
-- | The first argument is the _random seed_ to be passed to the random generator.
158
157
-- | The second argument is the number of tests to run.
159
158
quickCheckPure' :: forall prop . Testable prop => Seed -> Int -> prop -> List (Tuple Seed Result )
160
- quickCheckPure' s n prop = evalGen (replicateA n (go prop)) { newSeed : s, size: 10 }
159
+ quickCheckPure' s n prop = tailRec loop { seed : s, index: 0 , results: mempty }
161
160
where
162
- go p = stateful \gs -> Tuple gs.newSeed <$> test p
161
+ loop :: PureLoopState -> Step PureLoopState (List (Tuple Seed Result ))
162
+ loop { seed, index, results }
163
+ | index == n = Done (List .reverse (results))
164
+ | otherwise =
165
+ case runGen (test prop) { newSeed: seed, size: 10 } of
166
+ Tuple r {newSeed} ->
167
+ Loop
168
+ { seed: newSeed
169
+ , index: index + 1
170
+ , results: (Tuple seed r) : results
171
+ }
172
+
173
+ type PureLoopState =
174
+ { seed :: Seed
175
+ , index :: Int
176
+ , results :: List (Tuple Seed Result )
177
+ }
163
178
164
179
-- | A version of `quickCheckPure` with the property specialized to `Gen`.
165
180
quickCheckGenPure :: forall prop . Testable prop => Seed -> Int -> Gen prop -> List Result
0 commit comments