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.

140 lines
4.2 KiB

  1. /*
  2. * CslParserTest.cpp
  3. *
  4. * Created on: 09.04.2013
  5. * Author: Thomas Heinemann
  6. */
  7. #include "gtest/gtest.h"
  8. #include "storm-config.h"
  9. #include "src/parser/CslParser.h"
  10. #include "src/exceptions/WrongFormatException.h"
  11. TEST(CslParserTest, parseApOnlyTest) {
  12. std::string formula = "ap";
  13. storm::property::csl::AbstractCslFormula<double>* cslFormula = nullptr;
  14. ASSERT_NO_THROW(
  15. cslFormula = storm::parser::CslParser(formula);
  16. );
  17. ASSERT_NE(cslFormula, nullptr);
  18. ASSERT_EQ(cslFormula->toString(), formula);
  19. delete cslFormula;
  20. }
  21. TEST(CslParserTest, parsePropositionalFormulaTest) {
  22. std::string formula = "!(a & b) | a & ! c";
  23. storm::property::csl::AbstractCslFormula<double>* cslFormula = nullptr;
  24. ASSERT_NO_THROW(
  25. cslFormula = storm::parser::CslParser(formula);
  26. );
  27. ASSERT_NE(cslFormula, nullptr);
  28. ASSERT_EQ(cslFormula->toString(), "(!(a & b) | (a & !c))");
  29. delete cslFormula;
  30. }
  31. TEST(CslParserTest, parseProbabilisticFormulaTest) {
  32. std::string formula = "P > 0.5 [ F a ]";
  33. storm::property::csl::AbstractCslFormula<double>* cslFormula = nullptr;
  34. ASSERT_NO_THROW(
  35. cslFormula = storm::parser::CslParser(formula);
  36. );
  37. ASSERT_NE(cslFormula, nullptr);
  38. storm::property::csl::ProbabilisticBoundOperator<double>* op = static_cast<storm::property::csl::ProbabilisticBoundOperator<double>*>(cslFormula);
  39. ASSERT_EQ(storm::property::GREATER, op->getComparisonOperator());
  40. ASSERT_EQ(0.5, op->getBound());
  41. ASSERT_EQ(cslFormula->toString(), "P > 0.500000 [F a]");
  42. delete cslFormula;
  43. }
  44. TEST(CslParserTest, parseSteadyStateBoundFormulaTest) {
  45. std::string formula = "S >= 15 [ P < 0.2 [ a U<=3 b ] ]";
  46. storm::property::csl::AbstractCslFormula<double>* cslFormula = nullptr;
  47. ASSERT_NO_THROW(
  48. cslFormula = storm::parser::CslParser(formula);
  49. );
  50. ASSERT_NE(cslFormula, nullptr);
  51. storm::property::csl::SteadyStateBoundOperator<double>* op = static_cast<storm::property::csl::SteadyStateBoundOperator<double>*>(cslFormula);
  52. ASSERT_EQ(storm::property::GREATER_EQUAL, op->getComparisonOperator());
  53. ASSERT_EQ(15.0, op->getBound());
  54. ASSERT_EQ(cslFormula->toString(), "S >= 15.000000 [P < 0.200000 [a U[0.000000,3.000000] b]]");
  55. delete cslFormula;
  56. }
  57. TEST(CslParserTest, parseSteadyStateNoBoundFormulaTest) {
  58. std::string formula = "S = ? [ P <= 0.5 [ F<=3 a ] ]";
  59. storm::property::csl::AbstractCslFormula<double>* cslFormula = nullptr;
  60. ASSERT_NO_THROW(
  61. cslFormula = storm::parser::CslParser(formula);
  62. );
  63. ASSERT_NE(cslFormula, nullptr);
  64. ASSERT_EQ(cslFormula->toString(), "S = ? [P <= 0.500000 [F[0.000000,3.000000] a]]");
  65. delete cslFormula;
  66. }
  67. TEST(CslParserTest, parseProbabilisticNoBoundFormulaTest) {
  68. std::string formula = "P = ? [ a U [3,4] b & (!c) ]";
  69. storm::property::csl::AbstractCslFormula<double>* cslFormula = nullptr;
  70. ASSERT_NO_THROW(
  71. cslFormula = storm::parser::CslParser(formula);
  72. );
  73. ASSERT_NE(cslFormula, nullptr);
  74. ASSERT_EQ(cslFormula->toString(), "P = ? [a U[3.000000,4.000000] (b & !c)]");
  75. delete cslFormula;
  76. }
  77. TEST(CslParserTest, parseComplexFormulaTest) {
  78. std::string formula = "S<=0.5 [ P <= 0.5 [ a U c ] ] & (P > 0.5 [ G b] | !P < 0.4 [ G P>0.9 [F >=7 a & b] ]) //and a comment";
  79. storm::property::csl::AbstractCslFormula<double>* cslFormula = nullptr;
  80. ASSERT_NO_THROW(
  81. cslFormula = storm::parser::CslParser(formula);
  82. );
  83. ASSERT_NE(cslFormula, nullptr);
  84. ASSERT_EQ(cslFormula->toString(), "(S <= 0.500000 [P <= 0.500000 [a U c]] & (P > 0.500000 [G b] | !P < 0.400000 [G P > 0.900000 [F>=7.000000 (a & b)]]))");
  85. delete cslFormula;
  86. }
  87. TEST(CslParserTest, wrongProbabilisticFormulaTest) {
  88. std::string formula = "P > 0.5 [ a ]";
  89. storm::property::csl::AbstractCslFormula<double>* cslFormula = nullptr;
  90. ASSERT_THROW(
  91. cslFormula = storm::parser::CslParser(formula),
  92. storm::exceptions::WrongFormatException
  93. );
  94. }
  95. TEST(CslParserTest, wrongFormulaTest) {
  96. std::string formula = "(a | b) & +";
  97. storm::property::csl::AbstractCslFormula<double>* cslFormula = nullptr;
  98. ASSERT_THROW(
  99. cslFormula = storm::parser::CslParser(formula),
  100. storm::exceptions::WrongFormatException
  101. );
  102. }
  103. TEST(CslParserTest, wrongFormulaTest2) {
  104. std::string formula = "P>0 [ F & a ]";
  105. storm::property::csl::AbstractCslFormula<double>* cslFormula = nullptr;
  106. ASSERT_THROW(
  107. cslFormula = storm::parser::CslParser(formula),
  108. storm::exceptions::WrongFormatException
  109. );
  110. }