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