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.

169 lines
6.8 KiB

  1. #include "gtest/gtest.h"
  2. #include "storm-config.h"
  3. #include "src/parser/PrismParser.h"
  4. TEST(PrismParser, SimpleParsingOnlyTest) {
  5. std::string testInput =
  6. R"(dtmc
  7. module mod1
  8. b : bool;
  9. [a] true -> 1: (b'=true);
  10. endmodule)";
  11. storm::prism::Program result;
  12. EXPECT_NO_THROW(result = storm::parser::PrismParser::parseFromString(testInput, "testfile", false));
  13. EXPECT_EQ(1, result.getNumberOfModules());
  14. EXPECT_EQ(storm::prism::Program::ModelType::DTMC, result.getModelType());
  15. }
  16. TEST(PrismParser, StandardModelParsingTest) {
  17. storm::prism::Program result;
  18. EXPECT_NO_THROW(result = storm::parser::PrismParser::parse(STORM_CPP_TESTS_BASE_PATH "/functional/parser/prism/coin2.nm", false));
  19. EXPECT_NO_THROW(result = storm::parser::PrismParser::parse(STORM_CPP_TESTS_BASE_PATH "/functional/parser/prism/crowds5_5.pm", false));
  20. EXPECT_NO_THROW(result = storm::parser::PrismParser::parse(STORM_CPP_TESTS_BASE_PATH "/functional/parser/prism/csma2_2.nm", false));
  21. EXPECT_NO_THROW(result = storm::parser::PrismParser::parse(STORM_CPP_TESTS_BASE_PATH "/functional/parser/prism/die.pm", false));
  22. EXPECT_NO_THROW(result = storm::parser::PrismParser::parse(STORM_CPP_TESTS_BASE_PATH "/functional/parser/prism/firewire.nm", false));
  23. EXPECT_NO_THROW(result = storm::parser::PrismParser::parse(STORM_CPP_TESTS_BASE_PATH "/functional/parser/prism/leader3.nm", false));
  24. EXPECT_NO_THROW(result = storm::parser::PrismParser::parse(STORM_CPP_TESTS_BASE_PATH "/functional/parser/prism/leader3_5.pm", false));
  25. EXPECT_NO_THROW(result = storm::parser::PrismParser::parse(STORM_CPP_TESTS_BASE_PATH "/functional/parser/prism/two_dice.nm", false));
  26. EXPECT_NO_THROW(result = storm::parser::PrismParser::parse(STORM_CPP_TESTS_BASE_PATH "/functional/parser/prism/wlan0_collide.nm", false));
  27. }
  28. TEST(PrismParser, StandardModelFullTest) {
  29. storm::prism::Program result;
  30. EXPECT_NO_THROW(result = storm::parser::PrismParser::parse(STORM_CPP_TESTS_BASE_PATH "/functional/parser/prism/coin2.nm", true));
  31. EXPECT_NO_THROW(result = storm::parser::PrismParser::parse(STORM_CPP_TESTS_BASE_PATH "/functional/parser/prism/crowds5_5.pm", true));
  32. EXPECT_NO_THROW(result = storm::parser::PrismParser::parse(STORM_CPP_TESTS_BASE_PATH "/functional/parser/prism/csma2_2.nm", true));
  33. EXPECT_NO_THROW(result = storm::parser::PrismParser::parse(STORM_CPP_TESTS_BASE_PATH "/functional/parser/prism/die.pm", true));
  34. EXPECT_NO_THROW(result = storm::parser::PrismParser::parse(STORM_CPP_TESTS_BASE_PATH "/functional/parser/prism/firewire.nm", true));
  35. EXPECT_NO_THROW(result = storm::parser::PrismParser::parse(STORM_CPP_TESTS_BASE_PATH "/functional/parser/prism/leader3.nm", true));
  36. EXPECT_NO_THROW(result = storm::parser::PrismParser::parse(STORM_CPP_TESTS_BASE_PATH "/functional/parser/prism/leader3_5.pm", true));
  37. EXPECT_NO_THROW(result = storm::parser::PrismParser::parse(STORM_CPP_TESTS_BASE_PATH "/functional/parser/prism/two_dice.nm", true));
  38. EXPECT_NO_THROW(result = storm::parser::PrismParser::parse(STORM_CPP_TESTS_BASE_PATH "/functional/parser/prism/wlan0_collide.nm", true));
  39. }
  40. TEST(PrismParser, SimpleFullTest) {
  41. std::string testInput =
  42. R"(dtmc
  43. module mod1
  44. b : bool;
  45. [a] true -> 1: (b'=true != false = b => false);
  46. endmodule)";
  47. storm::prism::Program result;
  48. EXPECT_NO_THROW(result = storm::parser::PrismParser::parseFromString(testInput, "testfile", true));
  49. EXPECT_EQ(1, result.getNumberOfModules());
  50. EXPECT_EQ(storm::prism::Program::ModelType::DTMC, result.getModelType());
  51. }
  52. TEST(PrismParser, ComplexFullTest) {
  53. std::string testInput =
  54. R"(ma
  55. const int a;
  56. const int b = 10;
  57. const bool c;
  58. const bool d = true | false;
  59. const double e;
  60. const double f = 9;
  61. formula test = a >= 10 & (max(a,b) > floor(e));
  62. formula test2 = a+b;
  63. formula test3 = (a + b > 10 ? floor(a) : h) + a;
  64. global g : bool init false;
  65. global h : [0 .. b];
  66. module mod1
  67. i : bool;
  68. j : bool init c;
  69. k : [125..a] init a;
  70. [a] test&false -> (i'=true)&(k'=1+1) + 1 : (k'=floor(a) <= max(k, b) - 1 + k);
  71. endmodule
  72. module mod2
  73. [b] (k > 3) & false & (min(a, 0) < max(h, k)) -> 1-e: (j'=(1-a) * 2 + floor(f));
  74. endmodule
  75. module mod3 = mod1 [ i = i1, j = j1, k = k1 ] endmodule
  76. label "mal" = max(a, 10) > 0;
  77. init
  78. true
  79. endinit
  80. rewards "testrewards"
  81. [stateRew] true : a + 7;
  82. max(f, a) <= 8 : 2*b;
  83. endrewards
  84. rewards "testrewards2"
  85. [stateRew] true : a + 7;
  86. max(f, a) <= 8 : 2*b;
  87. endrewards)";
  88. storm::prism::Program result;
  89. result = storm::parser::PrismParser::parseFromString(testInput, "testfile", true);
  90. EXPECT_EQ(storm::prism::Program::ModelType::MA, result.getModelType());
  91. EXPECT_EQ(3, result.getNumberOfModules());
  92. EXPECT_EQ(2, result.getNumberOfRewardModels());
  93. EXPECT_EQ(1, result.getNumberOfLabels());
  94. EXPECT_TRUE(result.definesInitialStatesExpression());
  95. }
  96. TEST(PrismParser, ComplexParsingTest) {
  97. std::string testInput =
  98. R"(ma
  99. const int a;
  100. const int b = 10;
  101. const bool c;
  102. const bool d = true | false;
  103. const double e;
  104. const double f = 9;
  105. formula test = (a >= 10 & (max(a, b) > floor(e)));
  106. global g : bool init false;
  107. global h : [0 .. b];
  108. module mod1
  109. i : bool;
  110. j : bool init c;
  111. k : [125..a] init a;
  112. [a] true -> (i'=true)&(h'=1+1) + 1 : (j'=floor(a) <= max(k, b) - 1 + k);
  113. endmodule
  114. module mod2
  115. [b] (x > 3) & false & (min(a, b0) < max(as8, b)) -> y: (x'=(1-g) * 2 + a);
  116. [] s=1 -> (a'=a);
  117. [read] c<N-1 -> 1 : (c'=floor(c) + 1);
  118. endmodule
  119. module mod3 = mod2 [ x = y ] endmodule
  120. label "mal" = max(x, i) > 0;
  121. init
  122. true
  123. endinit
  124. rewards "testrewards"
  125. [stateRew] true : a + 7;
  126. max(z, f) <= 8 : 2*b;
  127. endrewards
  128. rewards "testrewards2"
  129. [stateRew] true : a + 7;
  130. max(z, f) <= 8 : 2*b;
  131. endrewards)";
  132. storm::prism::Program result;
  133. result = storm::parser::PrismParser::parseFromString(testInput, "testfile", false);
  134. EXPECT_EQ(storm::prism::Program::ModelType::MA, result.getModelType());
  135. EXPECT_EQ(3, result.getNumberOfModules());
  136. EXPECT_EQ(2, result.getNumberOfRewardModels());
  137. EXPECT_EQ(1, result.getNumberOfLabels());
  138. EXPECT_TRUE(result.definesInitialStatesExpression());
  139. }