Skip to content

Commit 2660f9b

Browse files
Random generation of initial states
1 parent 95b8ad1 commit 2660f9b

File tree

7 files changed

+195
-118
lines changed

7 files changed

+195
-118
lines changed

quickcheck-dynamic/CHANGELOG.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,16 @@ changes.
99

1010
## UNRELEASED
1111

12+
* **BREAKING**: The `Actions` pattern now has a field for the initial state of
13+
the actions sequence and the `runActions` function returns a triple with the
14+
intial state, environment, and final state.
15+
16+
* **BREAKING**: Made `initialState` `Gen state` instead of a `state` and
17+
introduced `setup :: state -> m ()` to `RunModel`.
18+
- To migrate an existing model simply replace `initialState = MyState{..}`
19+
with `initialState = pure $ MyState{..}` and everything else should work
20+
straight-forwardly.
21+
1222
* **BREAKING**: Removed `Realized`
1323
- To migrate uses of `Realized` with `IOSim`, index the state type on the choice of `RunModel` monad
1424
and index the relevant types:

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

Lines changed: 40 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ module Test.QuickCheck.DynamicLogic (
2727
forAllDL,
2828
forAllMappedDL,
2929
forAllUniqueDL,
30+
forAllDLS,
31+
forAllMappedDLS,
32+
forAllUniqueDLS,
3033
DL.DynLogicModel (..),
3134
module Test.QuickCheck.DynamicLogic.Quantify,
3235
) where
@@ -131,22 +134,23 @@ forAllNonVariableQ :: QuantifyConstraints (HasNoVariables a) => Quantification a
131134
forAllNonVariableQ q = DL $ \s k -> DL.forAllQ (hasNoVariablesQ q) $ \(HasNoVariables x) -> k x s
132135

133136
runDL :: Annotated s -> DL s () -> DL.DynFormula s
134-
runDL s dl = unDL dl s $ \_ _ -> DL.passTest
137+
runDL s dl = (unDL dl s $ \_ _ -> DL.passTest)
135138

136139
forAllUniqueDL
137140
:: (DL.DynLogicModel s, Testable a)
138-
=> Annotated s
139-
-> DL s ()
141+
=> DL s ()
140142
-> (Actions s -> a)
141143
-> Property
142-
forAllUniqueDL initState d = DL.forAllUniqueScripts initState (runDL initState d)
144+
forAllUniqueDL d p =
145+
forAllBlind initialState $ \st -> forAllUniqueDLS st d p
143146

144147
forAllDL
145148
:: (DL.DynLogicModel s, Testable a)
146149
=> DL s ()
147150
-> (Actions s -> a)
148151
-> Property
149-
forAllDL d = DL.forAllScripts (runDL initialAnnotatedState d)
152+
forAllDL d p =
153+
forAllBlind initialState $ \st -> forAllDLS st d p
150154

151155
forAllMappedDL
152156
:: (DL.DynLogicModel s, Testable a)
@@ -157,4 +161,34 @@ forAllMappedDL
157161
-> (srep -> a)
158162
-> Property
159163
forAllMappedDL to from fromScript d prop =
160-
DL.forAllMappedScripts to from (runDL initialAnnotatedState d) (prop . fromScript)
164+
forAll initialState $ \st -> forAllMappedDLS st to from fromScript d prop
165+
166+
forAllUniqueDLS
167+
:: (DL.DynLogicModel s, Testable a)
168+
=> s
169+
-> DL s ()
170+
-> (Actions s -> a)
171+
-> Property
172+
forAllUniqueDLS st d p =
173+
DL.forAllUniqueScripts st (runDL (Metadata mempty st) d) p
174+
175+
forAllDLS
176+
:: (DL.DynLogicModel s, Testable a)
177+
=> s
178+
-> DL s ()
179+
-> (Actions s -> a)
180+
-> Property
181+
forAllDLS st d p =
182+
DL.forAllScripts st (runDL (Metadata mempty st) d) p
183+
184+
forAllMappedDLS
185+
:: (DL.DynLogicModel s, Testable a)
186+
=> s
187+
-> (rep -> DL.DynLogicTest s)
188+
-> (DL.DynLogicTest s -> rep)
189+
-> (Actions s -> srep)
190+
-> DL s ()
191+
-> (srep -> a)
192+
-> Property
193+
forAllMappedDLS st to from fromScript d prop =
194+
DL.forAllMappedScripts st to from (runDL (Metadata mempty st) d) (prop . fromScript)

0 commit comments

Comments
 (0)