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.

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