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.

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