@@ -57,18 +57,17 @@ import Prelude
5757import Control.Monad.Rec.Class (Step (..), tailRec )
5858import Data.Foldable (for_ )
5959import Data.FoldableWithIndex (foldlWithIndex )
60- import Data.List (List )
60+ import Data.List (List , (:) )
6161import Data.List as List
6262import Data.Maybe (Maybe (..))
6363import Data.Maybe.First (First (..))
64- import Data.Tuple (Tuple (..))
65- import Data.Unfoldable (replicateA )
64+ import Data.Tuple (Tuple (..), snd )
6665import Effect (Effect )
6766import Effect.Console (log )
6867import Effect.Exception (throwException , error )
6968import Random.LCG (Seed , mkSeed , unSeed , randomSeed )
7069import 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 )
7271
7372-- | Test a property.
7473-- |
@@ -149,17 +148,33 @@ type LoopState =
149148-- | The first argument is the _random seed_ to be passed to the random generator.
150149-- | The second argument is the number of tests to run.
151150quickCheckPure :: 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)
153152
154153-- | Test a property, returning all test results as a List, with the Seed that
155154-- | was used for each result.
156155-- |
157156-- | The first argument is the _random seed_ to be passed to the random generator.
158157-- | The second argument is the number of tests to run.
159158quickCheckPure' :: 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 }
161160 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+ }
163178
164179-- | A version of `quickCheckPure` with the property specialized to `Gen`.
165180quickCheckGenPure :: forall prop . Testable prop => Seed -> Int -> Gen prop -> List Result
0 commit comments