You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

180 lines
9.0 KiB

  1. #include "gtest/gtest.h"
  2. #include "storm-config.h"
  3. #include "src/parser/FormulaParser.h"
  4. #include "src/logic/FragmentChecker.h"
  5. #include "src/exceptions/WrongFormatException.h"
  6. TEST(FragmentCheckerTest, Propositional) {
  7. storm::logic::FragmentChecker checker;
  8. storm::logic::FragmentSpecification prop = storm::logic::propositional();
  9. storm::parser::FormulaParser formulaParser;
  10. std::shared_ptr<storm::logic::Formula const> formula;
  11. ASSERT_NO_THROW(formula = formulaParser.parseSingleFormulaFromString("\"label\""));
  12. EXPECT_TRUE(checker.conformsToSpecification(*formula, prop));
  13. ASSERT_NO_THROW(formula = formulaParser.parseSingleFormulaFromString("true"));
  14. EXPECT_TRUE(checker.conformsToSpecification(*formula, prop));
  15. ASSERT_NO_THROW(formula = formulaParser.parseSingleFormulaFromString("true | \"label\""));
  16. EXPECT_TRUE(checker.conformsToSpecification(*formula, prop));
  17. ASSERT_NO_THROW(formula = formulaParser.parseSingleFormulaFromString("!true"));
  18. EXPECT_TRUE(checker.conformsToSpecification(*formula, prop));
  19. ASSERT_NO_THROW(formula = formulaParser.parseSingleFormulaFromString("true"));
  20. EXPECT_TRUE(checker.conformsToSpecification(*formula, prop));
  21. ASSERT_NO_THROW(formula = formulaParser.parseSingleFormulaFromString("P=? [F true]"));
  22. EXPECT_FALSE(checker.conformsToSpecification(*formula, prop));
  23. ASSERT_NO_THROW(formula = formulaParser.parseSingleFormulaFromString("false | P>0.5 [G \"label\"]"));
  24. EXPECT_FALSE(checker.conformsToSpecification(*formula, prop));
  25. ASSERT_NO_THROW(formula = formulaParser.parseSingleFormulaFromString("P=? [F \"label\"]"));
  26. EXPECT_FALSE(checker.conformsToSpecification(*formula, prop));
  27. }
  28. TEST(FragmentCheckerTest, Pctl) {
  29. storm::logic::FragmentChecker checker;
  30. storm::logic::FragmentSpecification pctl = storm::logic::pctl();
  31. storm::parser::FormulaParser formulaParser;
  32. std::shared_ptr<storm::logic::Formula const> formula;
  33. ASSERT_NO_THROW(formula = formulaParser.parseSingleFormulaFromString("\"label\""));
  34. EXPECT_TRUE(checker.conformsToSpecification(*formula, pctl));
  35. ASSERT_NO_THROW(formula = formulaParser.parseSingleFormulaFromString("P=? [F \"label\"]"));
  36. EXPECT_TRUE(checker.conformsToSpecification(*formula, pctl));
  37. ASSERT_NO_THROW(formula = formulaParser.parseSingleFormulaFromString("P=? [F P=? [F \"label\"]]"));
  38. EXPECT_TRUE(checker.conformsToSpecification(*formula, pctl));
  39. ASSERT_NO_THROW(formula = formulaParser.parseSingleFormulaFromString("R=? [F \"label\"]"));
  40. EXPECT_FALSE(checker.conformsToSpecification(*formula, pctl));
  41. }
  42. TEST(FragmentCheckerTest, Prctl) {
  43. storm::logic::FragmentChecker checker;
  44. storm::logic::FragmentSpecification prctl = storm::logic::prctl();
  45. storm::parser::FormulaParser formulaParser;
  46. std::shared_ptr<storm::logic::Formula const> formula;
  47. ASSERT_NO_THROW(formula = formulaParser.parseSingleFormulaFromString("\"label\""));
  48. EXPECT_TRUE(checker.conformsToSpecification(*formula, prctl));
  49. ASSERT_NO_THROW(formula = formulaParser.parseSingleFormulaFromString("P=? [F \"label\"]"));
  50. EXPECT_TRUE(checker.conformsToSpecification(*formula, prctl));
  51. ASSERT_NO_THROW(formula = formulaParser.parseSingleFormulaFromString("P=? [F P=? [F \"label\"]]"));
  52. EXPECT_TRUE(checker.conformsToSpecification(*formula, prctl));
  53. ASSERT_NO_THROW(formula = formulaParser.parseSingleFormulaFromString("R=? [F \"label\"]"));
  54. EXPECT_TRUE(checker.conformsToSpecification(*formula, prctl));
  55. ASSERT_NO_THROW(formula = formulaParser.parseSingleFormulaFromString("R=? [C<=3]"));
  56. EXPECT_TRUE(checker.conformsToSpecification(*formula, prctl));
  57. ASSERT_NO_THROW(formula = formulaParser.parseSingleFormulaFromString("P=? [F[0,1] \"label\"]"));
  58. EXPECT_FALSE(checker.conformsToSpecification(*formula, prctl));
  59. }
  60. TEST(FragmentCheckerTest, Csl) {
  61. storm::logic::FragmentChecker checker;
  62. storm::logic::FragmentSpecification csl = storm::logic::csl();
  63. storm::parser::FormulaParser formulaParser;
  64. std::shared_ptr<storm::logic::Formula const> formula;
  65. ASSERT_NO_THROW(formula = formulaParser.parseSingleFormulaFromString("\"label\""));
  66. EXPECT_TRUE(checker.conformsToSpecification(*formula, csl));
  67. ASSERT_NO_THROW(formula = formulaParser.parseSingleFormulaFromString("P=? [F \"label\"]"));
  68. EXPECT_TRUE(checker.conformsToSpecification(*formula, csl));
  69. ASSERT_NO_THROW(formula = formulaParser.parseSingleFormulaFromString("P=? [F P=? [F \"label\"]]"));
  70. EXPECT_TRUE(checker.conformsToSpecification(*formula, csl));
  71. ASSERT_NO_THROW(formula = formulaParser.parseSingleFormulaFromString("R=? [F \"label\"]"));
  72. EXPECT_FALSE(checker.conformsToSpecification(*formula, csl));
  73. ASSERT_NO_THROW(formula = formulaParser.parseSingleFormulaFromString("P=? [F[0,1] \"label\"]"));
  74. EXPECT_TRUE(checker.conformsToSpecification(*formula, csl));
  75. }
  76. TEST(FragmentCheckerTest, Csrl) {
  77. storm::logic::FragmentChecker checker;
  78. storm::logic::FragmentSpecification csrl = storm::logic::csrl();
  79. storm::parser::FormulaParser formulaParser;
  80. std::shared_ptr<storm::logic::Formula const> formula;
  81. ASSERT_NO_THROW(formula = formulaParser.parseSingleFormulaFromString("\"label\""));
  82. EXPECT_TRUE(checker.conformsToSpecification(*formula, csrl));
  83. ASSERT_NO_THROW(formula = formulaParser.parseSingleFormulaFromString("P=? [F \"label\"]"));
  84. EXPECT_TRUE(checker.conformsToSpecification(*formula, csrl));
  85. ASSERT_NO_THROW(formula = formulaParser.parseSingleFormulaFromString("P=? [F P=? [F \"label\"]]"));
  86. EXPECT_TRUE(checker.conformsToSpecification(*formula, csrl));
  87. ASSERT_NO_THROW(formula = formulaParser.parseSingleFormulaFromString("R=? [F \"label\"]"));
  88. EXPECT_TRUE(checker.conformsToSpecification(*formula, csrl));
  89. ASSERT_NO_THROW(formula = formulaParser.parseSingleFormulaFromString("R=? [C<=3]"));
  90. EXPECT_TRUE(checker.conformsToSpecification(*formula, csrl));
  91. ASSERT_NO_THROW(formula = formulaParser.parseSingleFormulaFromString("P=? [F[0,1] \"label\"]"));
  92. EXPECT_TRUE(checker.conformsToSpecification(*formula, csrl));
  93. }
  94. TEST(FragmentCheckerTest, MultiObjective) {
  95. storm::logic::FragmentChecker checker;
  96. storm::logic::FragmentSpecification multiobjective = storm::logic::multiObjective();
  97. storm::parser::FormulaParser formulaParser;
  98. std::shared_ptr<storm::logic::Formula const> formula;
  99. ASSERT_NO_THROW(formula = formulaParser.parseSingleFormulaFromString("\"label\""));
  100. EXPECT_TRUE(checker.conformsToSpecification(*formula, multiobjective));
  101. ASSERT_NO_THROW(formula = formulaParser.parseSingleFormulaFromString("P=? [F \"label\"]"));
  102. EXPECT_TRUE(checker.conformsToSpecification(*formula, multiobjective));
  103. ASSERT_NO_THROW(formula = formulaParser.parseSingleFormulaFromString("P=? [F P=? [F \"label\"]]"));
  104. EXPECT_TRUE(checker.conformsToSpecification(*formula, multiobjective));
  105. ASSERT_NO_THROW(formula = formulaParser.parseSingleFormulaFromString("R=? [F \"label\"]"));
  106. EXPECT_TRUE(checker.conformsToSpecification(*formula, multiobjective));
  107. ASSERT_NO_THROW(formula = formulaParser.parseSingleFormulaFromString("R=? [C]"));
  108. EXPECT_TRUE(checker.conformsToSpecification(*formula, multiobjective));
  109. ASSERT_NO_THROW(formula = formulaParser.parseSingleFormulaFromString("P=? [F[0.5,1] \"label\"]"));
  110. EXPECT_FALSE(checker.conformsToSpecification(*formula, multiobjective));
  111. ASSERT_NO_THROW(formula = formulaParser.parseSingleFormulaFromString("multi(R<0.3 [ C ], P<0.6 [F \"label\"] & \"label\" & R<=4[F \"label\"])"));
  112. EXPECT_FALSE(checker.conformsToSpecification(*formula, multiobjective));
  113. ASSERT_NO_THROW(formula = formulaParser.parseSingleFormulaFromString("multi(R<0.3 [ C ], P<0.6 [F \"label\"], \"label\", R<=4[F \"label\"])"));
  114. EXPECT_FALSE(checker.conformsToSpecification(*formula, multiobjective));
  115. ASSERT_NO_THROW(formula = formulaParser.parseSingleFormulaFromString("multi(R<0.3 [ C ], P<0.6 [F \"label\"], R<=4[F \"label\"])"));
  116. EXPECT_TRUE(checker.conformsToSpecification(*formula, multiobjective));
  117. ASSERT_NO_THROW(formula = formulaParser.parseSingleFormulaFromString("multi(R<0.3 [ C<=3 ], P<0.6 [F \"label\"], R<=4[F \"label\"])"));
  118. EXPECT_FALSE(checker.conformsToSpecification(*formula, multiobjective));
  119. ASSERT_NO_THROW(formula = formulaParser.parseSingleFormulaFromString("multi(R<0.3 [ C ], multi(P<0.6 [F \"label\"], R<=4[F \"label\"]))"));
  120. EXPECT_FALSE(checker.conformsToSpecification(*formula, multiobjective));
  121. ASSERT_NO_THROW(formula = formulaParser.parseSingleFormulaFromString("multi(R<0.3 [ C ], P<0.6 [F \"label\" & \"otherlabel\"], P<=4[\"label\" U<=42 \"otherlabel\"])"));
  122. EXPECT_TRUE(checker.conformsToSpecification(*formula, multiobjective));
  123. ASSERT_NO_THROW(formula = formulaParser.parseSingleFormulaFromString("multi(P=? [F P<0.5 [F \"label\"]], R<0.3 [ C ] )"));
  124. EXPECT_FALSE(checker.conformsToSpecification(*formula, multiobjective));
  125. }