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.

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