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.

225 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. endmodule)";
  39. EXPECT_NO_THROW(result = storm::parser::PrismParser::parseFromString(testInput, "testfile"));
  40. EXPECT_EQ(1, result.getNumberOfModules());
  41. EXPECT_EQ(storm::prism::Program::ModelType::MDP, result.getModelType());
  42. }
  43. TEST(PrismParser, ComplexTest) {
  44. std::string testInput =
  45. R"(ma
  46. const int a;
  47. const int b = 10;
  48. const bool c;
  49. const bool d = true | false;
  50. const double e;
  51. const double f = 9;
  52. formula test = a >= 10 & (max(a,b) > floor(e));
  53. formula test2 = a+b;
  54. formula test3 = (a + b > 10 ? floor(e) : h) + a;
  55. global g : bool init false;
  56. global h : [0 .. b];
  57. module mod1
  58. i : bool;
  59. j : bool init c;
  60. k : [125..a] init a;
  61. [a] test&false -> (i'=true)&(k'=1+1) + 1 : (k'=floor(e) + max(k, b) - 1 + k);
  62. [b] true -> (i'=i);
  63. endmodule
  64. module mod2
  65. [] (k > 3) & false & (min(a, 0) < max(h, k)) -> 1-e: (g'=(1-a) * 2 + floor(f) > 2);
  66. endmodule
  67. module mod3 = mod1 [ i = i1, j = j1, k = k1 ] endmodule
  68. label "mal" = max(a, 10) > 0;
  69. init
  70. true
  71. endinit
  72. rewards "testrewards"
  73. [a] true : a + 7;
  74. max(f, a) <= 8 : 2*b;
  75. endrewards
  76. rewards "testrewards2"
  77. [b] true : a + 7;
  78. max(f, a) <= 8 : 2*b;
  79. endrewards)";
  80. storm::prism::Program result;
  81. EXPECT_NO_THROW(result = storm::parser::PrismParser::parseFromString(testInput, "testfile"));
  82. EXPECT_EQ(storm::prism::Program::ModelType::MA, result.getModelType());
  83. EXPECT_EQ(3, result.getNumberOfModules());
  84. EXPECT_EQ(2, result.getNumberOfRewardModels());
  85. EXPECT_EQ(1, result.getNumberOfLabels());
  86. }
  87. TEST(PrismParser, IllegalInputTest) {
  88. std::string testInput =
  89. R"(ctmc
  90. const int a;
  91. const bool a = true;
  92. module mod1
  93. c : [0 .. 8] init 1;
  94. [] c < 3 -> 2: (c' = c+1);
  95. endmodule
  96. )";
  97. storm::prism::Program result;
  98. EXPECT_THROW(result = storm::parser::PrismParser::parseFromString(testInput, "testfile"), storm::exceptions::WrongFormatException);
  99. testInput =
  100. R"(dtmc
  101. const int a;
  102. module mod1
  103. a : [0 .. 8] init 1;
  104. [] a < 3 -> 1: (a' = a+1);
  105. endmodule)";
  106. EXPECT_THROW(result = storm::parser::PrismParser::parseFromString(testInput, "testfile"), storm::exceptions::WrongFormatException);
  107. testInput =
  108. R"(dtmc
  109. const int a = 2;
  110. formula a = 41;
  111. module mod1
  112. c : [0 .. 8] init 1;
  113. [] c < 3 -> 1: (c' = c+1);
  114. endmodule)";
  115. EXPECT_THROW(result = storm::parser::PrismParser::parseFromString(testInput, "testfile"), storm::exceptions::WrongFormatException);
  116. testInput =
  117. R"(dtmc
  118. const int a = 2;
  119. init
  120. c > 3
  121. endinit
  122. module mod1
  123. c : [0 .. 8] init 1;
  124. [] c < 3 -> 1: (c' = c+1);
  125. endmodule
  126. init
  127. c > 3
  128. endinit
  129. )";
  130. EXPECT_THROW(result = storm::parser::PrismParser::parseFromString(testInput, "testfile"), storm::exceptions::WrongFormatException);
  131. testInput =
  132. R"(dtmc
  133. module mod1
  134. c : [0 .. 8] init 1;
  135. [] c < 3 -> 1: (c' = c+1);
  136. endmodule
  137. module mod2
  138. [] c < 3 -> 1: (c' = c+1);
  139. endmodule)";
  140. EXPECT_THROW(result = storm::parser::PrismParser::parseFromString(testInput, "testfile"), storm::exceptions::WrongFormatException);
  141. testInput =
  142. R"(dtmc
  143. module mod1
  144. c : [0 .. 8] init 1;
  145. [] c < 3 -> 1: (c' = c+1)&(c'=c-1);
  146. endmodule)";
  147. EXPECT_THROW(result = storm::parser::PrismParser::parseFromString(testInput, "testfile"), storm::exceptions::WrongFormatException);
  148. testInput =
  149. R"(dtmc
  150. module mod1
  151. c : [0 .. 8] init 1;
  152. [] c < 3 -> 1: (c' = true || false);
  153. endmodule)";
  154. EXPECT_THROW(result = storm::parser::PrismParser::parseFromString(testInput, "testfile"), storm::exceptions::WrongFormatException);
  155. testInput =
  156. R"(dtmc
  157. module mod1
  158. c : [0 .. 8] init 1;
  159. [] c + 3 -> 1: (c' = 1);
  160. endmodule)";
  161. EXPECT_THROW(result = storm::parser::PrismParser::parseFromString(testInput, "testfile"), storm::exceptions::WrongFormatException);
  162. testInput =
  163. R"(dtmc
  164. module mod1
  165. c : [0 .. 8] init 1;
  166. [] c + 3 -> 1: (c' = 1);
  167. endmodule
  168. label "test" = c + 1;
  169. )";
  170. EXPECT_THROW(result = storm::parser::PrismParser::parseFromString(testInput, "testfile"), storm::exceptions::WrongFormatException);
  171. }