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.

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