Skip to content

Commit

Permalink
Add a test to make sure MoreActions actually introduces a reasonable
Browse files Browse the repository at this point in the history
number of long sequences
  • Loading branch information
MaximilianAlgehed committed Sep 20, 2024
1 parent 66a9519 commit 1f9d4e1
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
2 changes: 1 addition & 1 deletion quickcheck-dynamic/test/Spec/DynamicLogic/RegistryModel.hs
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ tests =
testGroup
"registry model example"
[ testProperty "prop_Registry" $ prop_Registry
, testProperty "prop_Registry . getMoreActions" $ prop_Registry . getMoreActions
, testProperty "prop_Registry . getMoreActions" $ withMaxSuccess 50 . prop_Registry . getMoreActions
, testProperty "canRegister" $ propDL canRegister
, testProperty "canRegisterNoUnregister" $ expectFailure $ propDL canRegisterNoUnregister
]
12 changes: 11 additions & 1 deletion quickcheck-dynamic/test/Test/QuickCheck/StateModelSpec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,12 @@ import Control.Monad.Reader (lift)
import Data.IORef (newIORef)
import Data.List (isInfixOf)
import Spec.DynamicLogic.Counters (Counter (..), FailingCounter, SimpleCounter (..))
import Test.QuickCheck (Property, Result (..), Testable, chatty, choose, counterexample, noShrinking, property, stdArgs)
import Test.QuickCheck (Property, Result (..), Testable, arbitrary, chatty, checkCoverage, choose, counterexample, cover, forAll, noShrinking, property, stdArgs)
import Test.QuickCheck.Extras (runPropertyReaderT)
import Test.QuickCheck.Monadic (assert, monadicIO, monitor, pick)
import Test.QuickCheck.StateModel (
Actions,
MoreActions (..),
lookUpVarMaybe,
mkVar,
runActions,
Expand All @@ -38,6 +39,9 @@ tests =
, testCase "prints counterexample as sequence of steps when postcondition fails" $ do
Failure{output} <- captureTerminal prop_failsOnPostcondition
"do action $ Inc'" `isInfixOf` output @? "Output does not contain \"do action $ Inc'\": " <> output
, testProperty
"MoreActions introduces long sequences of actions"
prop_longSequences
]

captureTerminal :: Testable p => p -> IO Result
Expand Down Expand Up @@ -79,3 +83,9 @@ prop_failsOnPostcondition actions =
ref <- lift $ newIORef (0 :: Int)
runPropertyReaderT (runActions actions) ref
assert True

prop_longSequences :: Property
prop_longSequences =
checkCoverage $
forAll (arbitrary @(MoreActions SimpleCounter)) $ \(MoreActions (Actions steps)) ->
cover 50 (100 < length steps) "Long sequences" True

0 comments on commit 1f9d4e1

Please sign in to comment.