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.

159 lines
4.2 KiB

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