|
1 | 1 | module Test.Kore.Step
|
2 | 2 | ( test_stepStrategy
|
| 3 | + , test_executionStrategy |
3 | 4 | ) where
|
4 | 5 |
|
5 | 6 | import Prelude.Kore
|
6 | 7 |
|
| 8 | +import Hedgehog |
| 9 | + ( Gen |
| 10 | + ) |
| 11 | +import qualified Hedgehog |
| 12 | +import qualified Hedgehog.Gen |
| 13 | +import qualified Hedgehog.Range |
7 | 14 | import Test.Tasty
|
| 15 | +import Test.Tasty.Hedgehog |
8 | 16 |
|
9 | 17 | import qualified Control.Exception as Exception
|
10 | 18 | import qualified Control.Lens as Lens
|
@@ -298,6 +306,47 @@ test_stepStrategy =
|
298 | 306 | Right _ ->
|
299 | 307 | assertFailure "Expected exception LimitExceeded"
|
300 | 308 |
|
| 309 | +test_executionStrategy :: [TestTree] |
| 310 | +test_executionStrategy = |
| 311 | + [ testProperty "every step contains Rewrite" $ Hedgehog.property $ do |
| 312 | + strategies <- Hedgehog.forAll genStrategies |
| 313 | + for_ strategies $ \strategy -> do |
| 314 | + Hedgehog.annotateShow strategy |
| 315 | + Hedgehog.assert (hasRewrite strategy) |
| 316 | + |
| 317 | + , testProperty "Simplify is the last sub-step" $ Hedgehog.property $ do |
| 318 | + strategies <- Hedgehog.forAll genStrategies |
| 319 | + let strategy = last strategies |
| 320 | + Hedgehog.annotateShow strategy |
| 321 | + Hedgehog.assert (isLastSimplify strategy) |
| 322 | + ] |
| 323 | + where |
| 324 | + genStrategies :: Gen [Strategy Prim] |
| 325 | + genStrategies = do |
| 326 | + let range = Hedgehog.Gen.integral (Hedgehog.Range.linear 1 16) |
| 327 | + depthLimit <- Limit <$> range |
| 328 | + pure (limitedExecutionStrategy depthLimit) |
| 329 | + |
| 330 | + hasRewrite :: Strategy Prim -> Bool |
| 331 | + hasRewrite = \case |
| 332 | + Strategy.Seq s1 s2 -> hasRewrite s1 || hasRewrite s2 |
| 333 | + Strategy.And s1 s2 -> hasRewrite s1 || hasRewrite s2 |
| 334 | + Strategy.Or s1 s2 -> hasRewrite s1 || hasRewrite s2 |
| 335 | + Strategy.Apply p -> p == Rewrite |
| 336 | + Strategy.Stuck -> False |
| 337 | + Strategy.Continue -> False |
| 338 | + |
| 339 | + isLastSimplify :: Strategy Prim -> Bool |
| 340 | + isLastSimplify = \case |
| 341 | + Strategy.Seq s Strategy.Continue -> isLastSimplify s |
| 342 | + Strategy.Seq s Strategy.Stuck -> isLastSimplify s |
| 343 | + Strategy.Seq _ s -> isLastSimplify s |
| 344 | + Strategy.And s1 s2 -> isLastSimplify s1 && isLastSimplify s2 |
| 345 | + Strategy.Or s1 s2 -> isLastSimplify s1 && isLastSimplify s2 |
| 346 | + Strategy.Apply p -> p == Simplify |
| 347 | + Strategy.Stuck -> False |
| 348 | + Strategy.Continue -> False |
| 349 | + |
301 | 350 | simpleRewrite
|
302 | 351 | :: TermLike VariableName
|
303 | 352 | -> TermLike VariableName
|
|
0 commit comments