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.

220 lines
6.7 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. rewards "testrewards"
  69. [a] true : a + 7;
  70. max(f, a) <= 8 : 2*b;
  71. endrewards
  72. rewards "testrewards2"
  73. [b] true : a + 7;
  74. max(f, a) <= 8 : 2*b;
  75. endrewards)";
  76. storm::prism::Program result;
  77. EXPECT_NO_THROW(result = storm::parser::PrismParser::parseFromString(testInput, "testfile"));
  78. EXPECT_EQ(storm::prism::Program::ModelType::MA, result.getModelType());
  79. EXPECT_EQ(3ul, result.getNumberOfModules());
  80. EXPECT_EQ(2ul, result.getNumberOfRewardModels());
  81. EXPECT_EQ(1ul, result.getNumberOfLabels());
  82. }
  83. TEST(PrismParser, IllegalInputTest) {
  84. std::string testInput =
  85. R"(ctmc
  86. const int a;
  87. const bool a = true;
  88. module mod1
  89. c : [0 .. 8] init 1;
  90. [] c < 3 -> 2: (c' = c+1);
  91. endmodule
  92. )";
  93. storm::prism::Program result;
  94. EXPECT_THROW(result = storm::parser::PrismParser::parseFromString(testInput, "testfile"), storm::exceptions::WrongFormatException);
  95. testInput =
  96. R"(dtmc
  97. const int a;
  98. module mod1
  99. a : [0 .. 8] init 1;
  100. [] a < 3 -> 1: (a' = a+1);
  101. endmodule)";
  102. EXPECT_THROW(result = storm::parser::PrismParser::parseFromString(testInput, "testfile"), storm::exceptions::WrongFormatException);
  103. testInput =
  104. R"(dtmc
  105. const int a = 2;
  106. formula a = 41;
  107. module mod1
  108. c : [0 .. 8] init 1;
  109. [] c < 3 -> 1: (c' = c+1);
  110. endmodule)";
  111. EXPECT_THROW(result = storm::parser::PrismParser::parseFromString(testInput, "testfile"), storm::exceptions::WrongFormatException);
  112. testInput =
  113. R"(dtmc
  114. const int a = 2;
  115. init
  116. c > 3
  117. endinit
  118. module mod1
  119. c : [0 .. 8] init 1;
  120. [] c < 3 -> 1: (c' = c+1);
  121. endmodule
  122. init
  123. c > 3
  124. endinit
  125. )";
  126. EXPECT_THROW(result = storm::parser::PrismParser::parseFromString(testInput, "testfile"), storm::exceptions::WrongFormatException);
  127. testInput =
  128. R"(dtmc
  129. module mod1
  130. c : [0 .. 8] init 1;
  131. [] c < 3 -> 1: (c' = c+1);
  132. endmodule
  133. module mod2
  134. [] c < 3 -> 1: (c' = c+1);
  135. endmodule)";
  136. EXPECT_THROW(result = storm::parser::PrismParser::parseFromString(testInput, "testfile"), storm::exceptions::WrongFormatException);
  137. testInput =
  138. R"(dtmc
  139. module mod1
  140. c : [0 .. 8] init 1;
  141. [] c < 3 -> 1: (c' = c+1)&(c'=c-1);
  142. endmodule)";
  143. EXPECT_THROW(result = storm::parser::PrismParser::parseFromString(testInput, "testfile"), storm::exceptions::WrongFormatException);
  144. testInput =
  145. R"(dtmc
  146. module mod1
  147. c : [0 .. 8] init 1;
  148. [] c < 3 -> 1: (c' = true || false);
  149. endmodule)";
  150. EXPECT_THROW(result = storm::parser::PrismParser::parseFromString(testInput, "testfile"), storm::exceptions::WrongFormatException);
  151. testInput =
  152. R"(dtmc
  153. module mod1
  154. c : [0 .. 8] init 1;
  155. [] c + 3 -> 1: (c' = 1);
  156. endmodule)";
  157. EXPECT_THROW(result = storm::parser::PrismParser::parseFromString(testInput, "testfile"), storm::exceptions::WrongFormatException);
  158. testInput =
  159. R"(dtmc
  160. module mod1
  161. c : [0 .. 8] init 1;
  162. [] c + 3 -> 1: (c' = 1);
  163. endmodule
  164. label "test" = c + 1;
  165. )";
  166. EXPECT_THROW(result = storm::parser::PrismParser::parseFromString(testInput, "testfile"), storm::exceptions::WrongFormatException);
  167. }