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.

226 lines
7.0 KiB

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