Skip to content

Commit ba48265

Browse files
authored
Merge pull request #88 from matthewleon/resize-state
ensure Gen seed is modified after resize
2 parents bc66856 + 579d61d commit ba48265

File tree

1 file changed

+6
-9
lines changed

1 file changed

+6
-9
lines changed

src/Test/QuickCheck/Gen.purs

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -33,14 +33,13 @@ module Test.QuickCheck.Gen
3333
import Prelude
3434

3535
import Control.Alt (class Alt)
36+
import Control.Lazy (class Lazy)
3637
import Control.Monad.Eff (Eff)
3738
import Control.Monad.Eff.Random (RANDOM)
39+
import Control.Monad.Gen.Class (class MonadGen)
3840
import Control.Monad.Rec.Class (class MonadRec, Step(..), tailRecM)
3941
import Control.Monad.State (State, runState, evalState)
40-
import Control.Monad.State.Class (state, get, modify)
41-
import Control.Monad.Gen.Class (class MonadGen)
42-
import Control.Lazy (class Lazy)
43-
42+
import Control.Monad.State.Class (modify, state)
4443
import Data.Array ((!!), length, zip, sortBy)
4544
import Data.Enum (class BoundedEnum, fromEnum, toEnum)
4645
import Data.Foldable (fold)
@@ -49,13 +48,10 @@ import Data.List (List(..), toUnfoldable)
4948
import Data.Maybe (fromMaybe, fromJust)
5049
import Data.Monoid.Additive (Additive(..))
5150
import Data.Newtype (unwrap)
52-
import Data.Tuple (Tuple(..), fst, snd)
5351
import Data.NonEmpty (NonEmpty, (:|))
54-
52+
import Data.Tuple (Tuple(..), fst, snd)
5553
import Math ((%))
56-
5754
import Partial.Unsafe (unsafePartial)
58-
5955
import Test.QuickCheck.LCG (Seed, lcgPerturb, lcgN, lcgNext, runSeed, randomSeed)
6056

6157
-- | Tests are parameterized by the `Size` of the randomly-generated data,
@@ -118,7 +114,8 @@ sized f = stateful (\s -> f s.size)
118114

119115
-- | Modify a random generator by setting a new size parameter.
120116
resize :: forall a. Size -> Gen a -> Gen a
121-
resize sz g = Gen $ fst <<< runGen g <<< (_ { size = sz }) <$> get
117+
resize sz g = Gen $ state \{ newSeed, size } ->
118+
(_ {size = size} ) <$> runGen g { newSeed, size: sz}
122119

123120
-- | Create a random generator which samples a range of `Number`s i
124121
-- | with uniform probability.

0 commit comments

Comments
 (0)