Skip to content

Commit 9736ac6

Browse files
committed
Allow using a custom initial state when generating actions
1 parent 19eda90 commit 9736ac6

File tree

1 file changed

+5
-7
lines changed

1 file changed

+5
-7
lines changed

quickcheck-dynamic/src/Test/QuickCheck/StateModel.hs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -387,7 +387,7 @@ class QCDProp state p | p -> state where
387387
instance QCDProp state (QCDProperty state) where
388388
qcdProperty = id
389389

390-
instance Testable p => QCDProp state (Actions state -> p) where
390+
instance (StateModel state, Testable p) => QCDProp state (Actions state -> p) where
391391
qcdProperty p = QCDProperty (property . p) defaultOptions
392392

393393
modifyOptions :: QCDProperty state -> (Options state -> Options state) -> QCDProperty state
@@ -399,18 +399,16 @@ moreActions :: QCDProp state p => Rational -> p -> QCDProperty state
399399
moreActions r p =
400400
modifyOptions (qcdProperty p) $ \opts -> opts{actionLengthMultiplier = actionLengthMultiplier opts * r}
401401

402-
-- NOTE: indexed on state for forwards compatibility, e.g. when we
403-
-- want to give an explicit initial state
404-
data Options state = Options {actionLengthMultiplier :: Rational}
402+
data Options state = Options {actionLengthMultiplier :: Rational, oInitialState :: Annotated state}
405403

406-
defaultOptions :: Options state
407-
defaultOptions = Options{actionLengthMultiplier = 1}
404+
defaultOptions :: StateModel state => Options state
405+
defaultOptions = Options{actionLengthMultiplier = 1, oInitialState = initialAnnotatedState}
408406

409407
-- | Generate arbitrary actions with the `GenActionsOptions`. More flexible than using the type-based
410408
-- modifiers.
411409
generateActionsWithOptions :: forall state. StateModel state => Options state -> Gen (Actions state)
412410
generateActionsWithOptions Options{..} = do
413-
(as, rejected) <- arbActions [] [] initialAnnotatedState 1
411+
(as, rejected) <- arbActions [] [] oInitialState 1
414412
return $ Actions_ rejected (Smart 0 as)
415413
where
416414
arbActions :: [Step state] -> [String] -> Annotated state -> Int -> Gen ([Step state], [String])

0 commit comments

Comments
 (0)