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.

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