From 1f9d4e1932c6732df33c5119992164ab007dc88c Mon Sep 17 00:00:00 2001 From: Maximilian Algehed Date: Fri, 20 Sep 2024 11:09:47 +0200 Subject: [PATCH] Add a test to make sure MoreActions actually introduces a reasonable number of long sequences --- .../test/Spec/DynamicLogic/RegistryModel.hs | 2 +- .../test/Test/QuickCheck/StateModelSpec.hs | 12 +++++++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/quickcheck-dynamic/test/Spec/DynamicLogic/RegistryModel.hs b/quickcheck-dynamic/test/Spec/DynamicLogic/RegistryModel.hs index 8f4cb99..f5c422e 100644 --- a/quickcheck-dynamic/test/Spec/DynamicLogic/RegistryModel.hs +++ b/quickcheck-dynamic/test/Spec/DynamicLogic/RegistryModel.hs @@ -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 ] diff --git a/quickcheck-dynamic/test/Test/QuickCheck/StateModelSpec.hs b/quickcheck-dynamic/test/Test/QuickCheck/StateModelSpec.hs index 12add89..e4d6853 100644 --- a/quickcheck-dynamic/test/Test/QuickCheck/StateModelSpec.hs +++ b/quickcheck-dynamic/test/Test/QuickCheck/StateModelSpec.hs @@ -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, @@ -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 @@ -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