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.

141 lines
3.8 KiB

  1. /*
  2. * LtlParserTest.cpp
  3. *
  4. * Created on: 22.04.2013
  5. * Author: thomas
  6. */
  7. #include "gtest/gtest.h"
  8. #include "storm-config.h"
  9. #include "src/parser/LtlParser.h"
  10. TEST(LtlParserTest, parseApOnlyTest) {
  11. std::string formula = "ap";
  12. storm::property::ltl::AbstractLtlFormula<double>* ltlFormula = nullptr;
  13. ASSERT_NO_THROW(
  14. ltlFormula = storm::parser::LtlParser(formula);
  15. );
  16. ASSERT_NE(ltlFormula, nullptr);
  17. ASSERT_EQ(ltlFormula->toString(), formula);
  18. delete ltlFormula;
  19. }
  20. TEST(LtlParserTest, parsePropositionalFormulaTest) {
  21. std::string formula = "!(a & b) | a & ! c";
  22. storm::property::ltl::AbstractLtlFormula<double>* ltlFormula = nullptr;
  23. ASSERT_NO_THROW(
  24. ltlFormula = storm::parser::LtlParser(formula);
  25. );
  26. ASSERT_NE(ltlFormula, nullptr);
  27. ASSERT_EQ(ltlFormula->toString(), "(!(a & b) | (a & !c))");
  28. delete ltlFormula;
  29. }
  30. /*!
  31. * The following test checks whether in the formula "F & b", F is correctly interpreted as proposition instead of the
  32. * "Eventually" operator.
  33. */
  34. TEST(LtlParserTest, parseAmbiguousFormulaTest) {
  35. std::string formula = "F & b";
  36. storm::property::ltl::AbstractLtlFormula<double>* ltlFormula = nullptr;
  37. ASSERT_NO_THROW(
  38. ltlFormula = storm::parser::LtlParser(formula);
  39. );
  40. ASSERT_NE(ltlFormula, nullptr);
  41. ASSERT_EQ(ltlFormula->toString(), "(F & b)");
  42. delete ltlFormula;
  43. }
  44. /*!
  45. * The following test checks whether in the formula "F F", F is interpreted as "eventually" operator or atomic proposition,
  46. * depending where it occurs.
  47. */
  48. TEST(LtlParserTest, parseAmbiguousFormulaTest2) {
  49. std::string formula = "F F";
  50. storm::property::ltl::AbstractLtlFormula<double>* ltlFormula = nullptr;
  51. ASSERT_NO_THROW(
  52. ltlFormula = storm::parser::LtlParser(formula);
  53. );
  54. ASSERT_NE(ltlFormula, nullptr);
  55. ASSERT_EQ(ltlFormula->toString(), "F F");
  56. delete ltlFormula;
  57. }
  58. TEST(LtlParserTest, parseBoundedEventuallyFormulaTest) {
  59. std::string formula = "F<=5 a";
  60. storm::property::ltl::AbstractLtlFormula<double>* ltlFormula = nullptr;
  61. ASSERT_NO_THROW(
  62. ltlFormula = storm::parser::LtlParser(formula);
  63. );
  64. ASSERT_NE(ltlFormula, nullptr);
  65. storm::property::ltl::BoundedEventually<double>* op = static_cast<storm::property::ltl::BoundedEventually<double>*>(ltlFormula);
  66. ASSERT_EQ(static_cast<uint_fast64_t>(5), op->getBound());
  67. ASSERT_EQ(ltlFormula->toString(), "F<=5 a");
  68. delete ltlFormula;
  69. }
  70. TEST(LtlParserTest, parseBoundedUntilFormulaTest) {
  71. std::string formula = "a U<=3 b";
  72. storm::property::ltl::AbstractLtlFormula<double>* ltlFormula = nullptr;
  73. ASSERT_NO_THROW(
  74. ltlFormula = storm::parser::LtlParser(formula);
  75. );
  76. ASSERT_NE(ltlFormula, nullptr);
  77. storm::property::ltl::BoundedUntil<double>* op = static_cast<storm::property::ltl::BoundedUntil<double>*>(ltlFormula);
  78. ASSERT_EQ(static_cast<uint_fast64_t>(3), op->getBound());
  79. ASSERT_EQ(ltlFormula->toString(), "(a U<=3 b)");
  80. delete ltlFormula;
  81. }
  82. TEST(LtlParserTest, parseComplexUntilTest) {
  83. std::string formula = "a U b U<=3 c";
  84. storm::property::ltl::AbstractLtlFormula<double>* ltlFormula = nullptr;
  85. ASSERT_NO_THROW(
  86. ltlFormula = storm::parser::LtlParser(formula);
  87. );
  88. ASSERT_NE(ltlFormula, nullptr);
  89. ASSERT_EQ(ltlFormula->toString(), "((a U b) U<=3 c)");
  90. delete ltlFormula;
  91. }
  92. TEST(LtlParserTest, parseComplexFormulaTest) {
  93. std::string formula = "a U F b | G a & F<=3 a U<=7 b // and a comment";
  94. storm::property::ltl::AbstractLtlFormula<double>* ltlFormula = nullptr;
  95. ASSERT_NO_THROW(
  96. ltlFormula = storm::parser::LtlParser(formula);
  97. );
  98. ASSERT_NE(ltlFormula, nullptr);
  99. ASSERT_EQ(ltlFormula->toString(), "(a U F (b | G (a & F<=3 (a U<=7 b))))");
  100. delete ltlFormula;
  101. }
  102. TEST(LtlParserTest, wrongFormulaTest) {
  103. std::string formula = "(a | c) & +";
  104. storm::property::ltl::AbstractLtlFormula<double>* ltlFormula = nullptr;
  105. ASSERT_THROW(
  106. ltlFormula = storm::parser::LtlParser(formula),
  107. storm::exceptions::WrongFormatException
  108. );
  109. }