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.

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