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.

351 lines
22 KiB

  1. #include <map>
  2. #include <string>
  3. #include "gtest/gtest.h"
  4. #include "src/storage/expressions/Expression.h"
  5. #include "src/storage/expressions/LinearityCheckVisitor.h"
  6. #include "src/storage/expressions/SimpleValuation.h"
  7. #include "src/exceptions/InvalidTypeException.h"
  8. TEST(Expression, FactoryMethodTest) {
  9. EXPECT_NO_THROW(storm::expressions::Expression::createBooleanLiteral(true));
  10. EXPECT_NO_THROW(storm::expressions::Expression::createTrue());
  11. EXPECT_NO_THROW(storm::expressions::Expression::createFalse());
  12. EXPECT_NO_THROW(storm::expressions::Expression::createIntegerLiteral(3));
  13. EXPECT_NO_THROW(storm::expressions::Expression::createDoubleLiteral(3.14));
  14. EXPECT_NO_THROW(storm::expressions::Expression::createBooleanVariable("x"));
  15. EXPECT_NO_THROW(storm::expressions::Expression::createIntegerVariable("y"));
  16. EXPECT_NO_THROW(storm::expressions::Expression::createDoubleVariable("z"));
  17. }
  18. TEST(Expression, AccessorTest) {
  19. storm::expressions::Expression trueExpression;
  20. storm::expressions::Expression falseExpression;
  21. storm::expressions::Expression threeExpression;
  22. storm::expressions::Expression piExpression;
  23. storm::expressions::Expression boolVarExpression;
  24. storm::expressions::Expression intVarExpression;
  25. storm::expressions::Expression doubleVarExpression;
  26. ASSERT_NO_THROW(trueExpression = storm::expressions::Expression::createTrue());
  27. ASSERT_NO_THROW(falseExpression = storm::expressions::Expression::createFalse());
  28. ASSERT_NO_THROW(threeExpression = storm::expressions::Expression::createIntegerLiteral(3));
  29. ASSERT_NO_THROW(piExpression = storm::expressions::Expression::createDoubleLiteral(3.14));
  30. ASSERT_NO_THROW(boolVarExpression = storm::expressions::Expression::createBooleanVariable("x"));
  31. ASSERT_NO_THROW(intVarExpression = storm::expressions::Expression::createIntegerVariable("y"));
  32. ASSERT_NO_THROW(doubleVarExpression = storm::expressions::Expression::createDoubleVariable("z"));
  33. EXPECT_TRUE(trueExpression.getReturnType() == storm::expressions::ExpressionReturnType::Bool);
  34. EXPECT_TRUE(trueExpression.isLiteral());
  35. EXPECT_TRUE(trueExpression.isTrue());
  36. EXPECT_FALSE(trueExpression.isFalse());
  37. EXPECT_TRUE(trueExpression.getVariables() == std::set<std::string>());
  38. EXPECT_TRUE(falseExpression.getReturnType() == storm::expressions::ExpressionReturnType::Bool);
  39. EXPECT_TRUE(falseExpression.isLiteral());
  40. EXPECT_FALSE(falseExpression.isTrue());
  41. EXPECT_TRUE(falseExpression.isFalse());
  42. EXPECT_TRUE(falseExpression.getVariables() == std::set<std::string>());
  43. EXPECT_TRUE(threeExpression.getReturnType() == storm::expressions::ExpressionReturnType::Int);
  44. EXPECT_TRUE(threeExpression.isLiteral());
  45. EXPECT_FALSE(threeExpression.isTrue());
  46. EXPECT_FALSE(threeExpression.isFalse());
  47. EXPECT_TRUE(threeExpression.getVariables() == std::set<std::string>());
  48. EXPECT_TRUE(piExpression.getReturnType() == storm::expressions::ExpressionReturnType::Double);
  49. EXPECT_TRUE(piExpression.isLiteral());
  50. EXPECT_FALSE(piExpression.isTrue());
  51. EXPECT_FALSE(piExpression.isFalse());
  52. EXPECT_TRUE(piExpression.getVariables() == std::set<std::string>());
  53. EXPECT_TRUE(boolVarExpression.getReturnType() == storm::expressions::ExpressionReturnType::Bool);
  54. EXPECT_FALSE(boolVarExpression.isLiteral());
  55. EXPECT_FALSE(boolVarExpression.isTrue());
  56. EXPECT_FALSE(boolVarExpression.isFalse());
  57. EXPECT_TRUE(boolVarExpression.getVariables() == std::set<std::string>({"x"}));
  58. EXPECT_TRUE(intVarExpression.getReturnType() == storm::expressions::ExpressionReturnType::Int);
  59. EXPECT_FALSE(intVarExpression.isLiteral());
  60. EXPECT_FALSE(intVarExpression.isTrue());
  61. EXPECT_FALSE(intVarExpression.isFalse());
  62. EXPECT_TRUE(intVarExpression.getVariables() == std::set<std::string>({"y"}));
  63. EXPECT_TRUE(doubleVarExpression.getReturnType() == storm::expressions::ExpressionReturnType::Double);
  64. EXPECT_FALSE(doubleVarExpression.isLiteral());
  65. EXPECT_FALSE(doubleVarExpression.isTrue());
  66. EXPECT_FALSE(doubleVarExpression.isFalse());
  67. EXPECT_TRUE(doubleVarExpression.getVariables() == std::set<std::string>({"z"}));
  68. }
  69. TEST(Expression, OperatorTest) {
  70. storm::expressions::Expression trueExpression;
  71. storm::expressions::Expression falseExpression;
  72. storm::expressions::Expression threeExpression;
  73. storm::expressions::Expression piExpression;
  74. storm::expressions::Expression boolVarExpression;
  75. storm::expressions::Expression intVarExpression;
  76. storm::expressions::Expression doubleVarExpression;
  77. ASSERT_NO_THROW(trueExpression = storm::expressions::Expression::createTrue());
  78. ASSERT_NO_THROW(falseExpression = storm::expressions::Expression::createFalse());
  79. ASSERT_NO_THROW(threeExpression = storm::expressions::Expression::createIntegerLiteral(3));
  80. ASSERT_NO_THROW(piExpression = storm::expressions::Expression::createDoubleLiteral(3.14));
  81. ASSERT_NO_THROW(boolVarExpression = storm::expressions::Expression::createBooleanVariable("x"));
  82. ASSERT_NO_THROW(intVarExpression = storm::expressions::Expression::createIntegerVariable("y"));
  83. ASSERT_NO_THROW(doubleVarExpression = storm::expressions::Expression::createDoubleVariable("z"));
  84. storm::expressions::Expression tempExpression;
  85. ASSERT_THROW(tempExpression = trueExpression.ite(falseExpression, piExpression), storm::exceptions::InvalidTypeException);
  86. ASSERT_NO_THROW(tempExpression = boolVarExpression.ite(threeExpression, doubleVarExpression));
  87. EXPECT_TRUE(tempExpression.getReturnType() == storm::expressions::ExpressionReturnType::Double);
  88. ASSERT_NO_THROW(tempExpression = boolVarExpression.ite(threeExpression, intVarExpression));
  89. EXPECT_TRUE(tempExpression.getReturnType() == storm::expressions::ExpressionReturnType::Int);
  90. ASSERT_NO_THROW(tempExpression = boolVarExpression.ite(trueExpression, falseExpression));
  91. EXPECT_TRUE(tempExpression.getReturnType() == storm::expressions::ExpressionReturnType::Bool);
  92. ASSERT_THROW(tempExpression = trueExpression + piExpression, storm::exceptions::InvalidTypeException);
  93. ASSERT_NO_THROW(tempExpression = threeExpression + threeExpression);
  94. EXPECT_TRUE(tempExpression.getReturnType() == storm::expressions::ExpressionReturnType::Int);
  95. ASSERT_NO_THROW(tempExpression = threeExpression + piExpression);
  96. EXPECT_TRUE(tempExpression.getReturnType() == storm::expressions::ExpressionReturnType::Double);
  97. ASSERT_NO_THROW(tempExpression = doubleVarExpression + doubleVarExpression);
  98. EXPECT_TRUE(tempExpression.getReturnType() == storm::expressions::ExpressionReturnType::Double);
  99. ASSERT_THROW(tempExpression = trueExpression - piExpression, storm::exceptions::InvalidTypeException);
  100. ASSERT_NO_THROW(tempExpression = threeExpression - threeExpression);
  101. EXPECT_TRUE(tempExpression.getReturnType() == storm::expressions::ExpressionReturnType::Int);
  102. ASSERT_NO_THROW(tempExpression = threeExpression - piExpression);
  103. EXPECT_TRUE(tempExpression.getReturnType() == storm::expressions::ExpressionReturnType::Double);
  104. ASSERT_NO_THROW(tempExpression = doubleVarExpression - doubleVarExpression);
  105. EXPECT_TRUE(tempExpression.getReturnType() == storm::expressions::ExpressionReturnType::Double);
  106. ASSERT_THROW(tempExpression = -trueExpression, storm::exceptions::InvalidTypeException);
  107. ASSERT_NO_THROW(tempExpression = -threeExpression);
  108. EXPECT_TRUE(tempExpression.getReturnType() == storm::expressions::ExpressionReturnType::Int);
  109. ASSERT_NO_THROW(tempExpression = -piExpression);
  110. EXPECT_TRUE(tempExpression.getReturnType() == storm::expressions::ExpressionReturnType::Double);
  111. ASSERT_NO_THROW(tempExpression = -doubleVarExpression);
  112. EXPECT_TRUE(tempExpression.getReturnType() == storm::expressions::ExpressionReturnType::Double);
  113. ASSERT_THROW(tempExpression = trueExpression * piExpression, storm::exceptions::InvalidTypeException);
  114. ASSERT_NO_THROW(tempExpression = threeExpression * threeExpression);
  115. EXPECT_TRUE(tempExpression.getReturnType() == storm::expressions::ExpressionReturnType::Int);
  116. ASSERT_NO_THROW(tempExpression = threeExpression * piExpression);
  117. EXPECT_TRUE(tempExpression.getReturnType() == storm::expressions::ExpressionReturnType::Double);
  118. ASSERT_NO_THROW(tempExpression = intVarExpression * intVarExpression);
  119. EXPECT_TRUE(tempExpression.getReturnType() == storm::expressions::ExpressionReturnType::Int);
  120. ASSERT_THROW(tempExpression = trueExpression / piExpression, storm::exceptions::InvalidTypeException);
  121. ASSERT_NO_THROW(tempExpression = threeExpression / threeExpression);
  122. EXPECT_TRUE(tempExpression.getReturnType() == storm::expressions::ExpressionReturnType::Int);
  123. ASSERT_NO_THROW(tempExpression = threeExpression / piExpression);
  124. EXPECT_TRUE(tempExpression.getReturnType() == storm::expressions::ExpressionReturnType::Double);
  125. ASSERT_NO_THROW(tempExpression = doubleVarExpression / intVarExpression);
  126. EXPECT_TRUE(tempExpression.getReturnType() == storm::expressions::ExpressionReturnType::Double);
  127. ASSERT_THROW(tempExpression = trueExpression && piExpression, storm::exceptions::InvalidTypeException);
  128. ASSERT_NO_THROW(tempExpression = trueExpression && falseExpression);
  129. EXPECT_TRUE(tempExpression.getReturnType() == storm::expressions::ExpressionReturnType::Bool);
  130. ASSERT_NO_THROW(tempExpression = boolVarExpression && boolVarExpression);
  131. EXPECT_TRUE(tempExpression.getReturnType() == storm::expressions::ExpressionReturnType::Bool);
  132. ASSERT_THROW(tempExpression = trueExpression || piExpression, storm::exceptions::InvalidTypeException);
  133. ASSERT_NO_THROW(tempExpression = trueExpression || falseExpression);
  134. EXPECT_TRUE(tempExpression.getReturnType() == storm::expressions::ExpressionReturnType::Bool);
  135. ASSERT_NO_THROW(tempExpression = boolVarExpression || boolVarExpression);
  136. EXPECT_TRUE(tempExpression.getReturnType() == storm::expressions::ExpressionReturnType::Bool);
  137. ASSERT_THROW(tempExpression = !threeExpression, storm::exceptions::InvalidTypeException);
  138. ASSERT_NO_THROW(tempExpression = !trueExpression);
  139. EXPECT_TRUE(tempExpression.getReturnType() == storm::expressions::ExpressionReturnType::Bool);
  140. ASSERT_NO_THROW(tempExpression = !boolVarExpression);
  141. EXPECT_TRUE(tempExpression.getReturnType() == storm::expressions::ExpressionReturnType::Bool);
  142. ASSERT_THROW(tempExpression = trueExpression == piExpression, storm::exceptions::InvalidTypeException);
  143. ASSERT_NO_THROW(tempExpression = threeExpression == threeExpression);
  144. EXPECT_TRUE(tempExpression.getReturnType() == storm::expressions::ExpressionReturnType::Bool);
  145. ASSERT_NO_THROW(tempExpression = intVarExpression == doubleVarExpression);
  146. EXPECT_TRUE(tempExpression.getReturnType() == storm::expressions::ExpressionReturnType::Bool);
  147. ASSERT_THROW(tempExpression = trueExpression != piExpression, storm::exceptions::InvalidTypeException);
  148. ASSERT_NO_THROW(tempExpression = threeExpression != threeExpression);
  149. EXPECT_TRUE(tempExpression.getReturnType() == storm::expressions::ExpressionReturnType::Bool);
  150. ASSERT_NO_THROW(tempExpression = intVarExpression != doubleVarExpression);
  151. EXPECT_TRUE(tempExpression.getReturnType() == storm::expressions::ExpressionReturnType::Bool);
  152. ASSERT_THROW(tempExpression = trueExpression > piExpression, storm::exceptions::InvalidTypeException);
  153. ASSERT_NO_THROW(tempExpression = threeExpression > threeExpression);
  154. EXPECT_TRUE(tempExpression.getReturnType() == storm::expressions::ExpressionReturnType::Bool);
  155. ASSERT_NO_THROW(tempExpression = intVarExpression > doubleVarExpression);
  156. EXPECT_TRUE(tempExpression.getReturnType() == storm::expressions::ExpressionReturnType::Bool);
  157. ASSERT_THROW(tempExpression = trueExpression >= piExpression, storm::exceptions::InvalidTypeException);
  158. ASSERT_NO_THROW(tempExpression = threeExpression >= threeExpression);
  159. EXPECT_TRUE(tempExpression.getReturnType() == storm::expressions::ExpressionReturnType::Bool);
  160. ASSERT_NO_THROW(tempExpression = intVarExpression >= doubleVarExpression);
  161. EXPECT_TRUE(tempExpression.getReturnType() == storm::expressions::ExpressionReturnType::Bool);
  162. ASSERT_THROW(tempExpression = trueExpression < piExpression, storm::exceptions::InvalidTypeException);
  163. ASSERT_NO_THROW(tempExpression = threeExpression < threeExpression);
  164. EXPECT_TRUE(tempExpression.getReturnType() == storm::expressions::ExpressionReturnType::Bool);
  165. ASSERT_NO_THROW(tempExpression = intVarExpression < doubleVarExpression);
  166. EXPECT_TRUE(tempExpression.getReturnType() == storm::expressions::ExpressionReturnType::Bool);
  167. ASSERT_THROW(tempExpression = trueExpression <= piExpression, storm::exceptions::InvalidTypeException);
  168. ASSERT_NO_THROW(tempExpression = threeExpression <= threeExpression);
  169. EXPECT_TRUE(tempExpression.getReturnType() == storm::expressions::ExpressionReturnType::Bool);
  170. ASSERT_NO_THROW(tempExpression = intVarExpression <= doubleVarExpression);
  171. EXPECT_TRUE(tempExpression.getReturnType() == storm::expressions::ExpressionReturnType::Bool);
  172. ASSERT_THROW(tempExpression = storm::expressions::Expression::minimum(trueExpression, piExpression), storm::exceptions::InvalidTypeException);
  173. ASSERT_NO_THROW(tempExpression = storm::expressions::Expression::minimum(threeExpression, threeExpression));
  174. EXPECT_TRUE(tempExpression.getReturnType() == storm::expressions::ExpressionReturnType::Int);
  175. ASSERT_NO_THROW(tempExpression = storm::expressions::Expression::minimum(intVarExpression, doubleVarExpression));
  176. EXPECT_TRUE(tempExpression.getReturnType() == storm::expressions::ExpressionReturnType::Double);
  177. ASSERT_THROW(tempExpression = storm::expressions::Expression::maximum(trueExpression, piExpression), storm::exceptions::InvalidTypeException);
  178. ASSERT_NO_THROW(tempExpression = storm::expressions::Expression::maximum(threeExpression, threeExpression));
  179. EXPECT_TRUE(tempExpression.getReturnType() == storm::expressions::ExpressionReturnType::Int);
  180. ASSERT_NO_THROW(tempExpression = storm::expressions::Expression::maximum(intVarExpression, doubleVarExpression));
  181. EXPECT_TRUE(tempExpression.getReturnType() == storm::expressions::ExpressionReturnType::Double);
  182. ASSERT_THROW(tempExpression = trueExpression.implies(piExpression), storm::exceptions::InvalidTypeException);
  183. ASSERT_NO_THROW(tempExpression = trueExpression.implies(falseExpression));
  184. EXPECT_TRUE(tempExpression.getReturnType() == storm::expressions::ExpressionReturnType::Bool);
  185. ASSERT_NO_THROW(tempExpression = boolVarExpression.implies(boolVarExpression));
  186. EXPECT_TRUE(tempExpression.getReturnType() == storm::expressions::ExpressionReturnType::Bool);
  187. ASSERT_THROW(tempExpression = trueExpression.iff(piExpression), storm::exceptions::InvalidTypeException);
  188. ASSERT_NO_THROW(tempExpression = trueExpression.iff(falseExpression));
  189. EXPECT_TRUE(tempExpression.getReturnType() == storm::expressions::ExpressionReturnType::Bool);
  190. ASSERT_NO_THROW(tempExpression = boolVarExpression.iff(boolVarExpression));
  191. EXPECT_TRUE(tempExpression.getReturnType() == storm::expressions::ExpressionReturnType::Bool);
  192. ASSERT_THROW(tempExpression = trueExpression ^ piExpression, storm::exceptions::InvalidTypeException);
  193. ASSERT_NO_THROW(tempExpression = trueExpression ^ falseExpression);
  194. EXPECT_TRUE(tempExpression.getReturnType() == storm::expressions::ExpressionReturnType::Bool);
  195. ASSERT_NO_THROW(tempExpression = boolVarExpression ^ boolVarExpression);
  196. EXPECT_TRUE(tempExpression.getReturnType() == storm::expressions::ExpressionReturnType::Bool);
  197. ASSERT_THROW(tempExpression = trueExpression.floor(), storm::exceptions::InvalidTypeException);
  198. ASSERT_NO_THROW(tempExpression = threeExpression.floor());
  199. EXPECT_TRUE(tempExpression.getReturnType() == storm::expressions::ExpressionReturnType::Int);
  200. ASSERT_NO_THROW(tempExpression = doubleVarExpression.floor());
  201. EXPECT_TRUE(tempExpression.getReturnType() == storm::expressions::ExpressionReturnType::Int);
  202. ASSERT_THROW(tempExpression = trueExpression.ceil(), storm::exceptions::InvalidTypeException);
  203. ASSERT_NO_THROW(tempExpression = threeExpression.ceil());
  204. EXPECT_TRUE(tempExpression.getReturnType() == storm::expressions::ExpressionReturnType::Int);
  205. ASSERT_NO_THROW(tempExpression = doubleVarExpression.ceil());
  206. EXPECT_TRUE(tempExpression.getReturnType() == storm::expressions::ExpressionReturnType::Int);
  207. }
  208. TEST(Expression, SubstitutionTest) {
  209. storm::expressions::Expression trueExpression;
  210. storm::expressions::Expression falseExpression;
  211. storm::expressions::Expression threeExpression;
  212. storm::expressions::Expression piExpression;
  213. storm::expressions::Expression boolVarExpression;
  214. storm::expressions::Expression intVarExpression;
  215. storm::expressions::Expression doubleVarExpression;
  216. ASSERT_NO_THROW(trueExpression = storm::expressions::Expression::createTrue());
  217. ASSERT_NO_THROW(falseExpression = storm::expressions::Expression::createFalse());
  218. ASSERT_NO_THROW(threeExpression = storm::expressions::Expression::createIntegerLiteral(3));
  219. ASSERT_NO_THROW(piExpression = storm::expressions::Expression::createDoubleLiteral(3.14));
  220. ASSERT_NO_THROW(boolVarExpression = storm::expressions::Expression::createBooleanVariable("x"));
  221. ASSERT_NO_THROW(intVarExpression = storm::expressions::Expression::createIntegerVariable("y"));
  222. ASSERT_NO_THROW(doubleVarExpression = storm::expressions::Expression::createDoubleVariable("z"));
  223. storm::expressions::Expression tempExpression;
  224. ASSERT_NO_THROW(tempExpression = (intVarExpression < threeExpression || boolVarExpression) && boolVarExpression);
  225. std::map<std::string, storm::expressions::Expression> substution = { std::make_pair("y", doubleVarExpression), std::make_pair("x", storm::expressions::Expression::createTrue()), std::make_pair("a", storm::expressions::Expression::createTrue()) };
  226. storm::expressions::Expression substitutedExpression;
  227. ASSERT_NO_THROW(substitutedExpression = tempExpression.substitute(substution));
  228. EXPECT_TRUE(substitutedExpression.simplify().isTrue());
  229. }
  230. TEST(Expression, SimplificationTest) {
  231. storm::expressions::Expression trueExpression;
  232. storm::expressions::Expression falseExpression;
  233. storm::expressions::Expression threeExpression;
  234. storm::expressions::Expression intVarExpression;
  235. ASSERT_NO_THROW(trueExpression = storm::expressions::Expression::createTrue());
  236. ASSERT_NO_THROW(falseExpression = storm::expressions::Expression::createFalse());
  237. ASSERT_NO_THROW(threeExpression = storm::expressions::Expression::createIntegerLiteral(3));
  238. ASSERT_NO_THROW(intVarExpression = storm::expressions::Expression::createIntegerVariable("y"));
  239. storm::expressions::Expression tempExpression;
  240. storm::expressions::Expression simplifiedExpression;
  241. ASSERT_NO_THROW(tempExpression = trueExpression || intVarExpression > threeExpression);
  242. ASSERT_NO_THROW(simplifiedExpression = tempExpression.simplify());
  243. EXPECT_TRUE(simplifiedExpression.isTrue());
  244. ASSERT_NO_THROW(tempExpression = falseExpression && intVarExpression > threeExpression);
  245. ASSERT_NO_THROW(simplifiedExpression = tempExpression.simplify());
  246. EXPECT_TRUE(simplifiedExpression.isFalse());
  247. }
  248. TEST(Expression, SimpleEvaluationTest) {
  249. storm::expressions::Expression trueExpression;
  250. storm::expressions::Expression falseExpression;
  251. storm::expressions::Expression threeExpression;
  252. storm::expressions::Expression piExpression;
  253. storm::expressions::Expression boolVarExpression;
  254. storm::expressions::Expression intVarExpression;
  255. storm::expressions::Expression doubleVarExpression;
  256. ASSERT_NO_THROW(trueExpression = storm::expressions::Expression::createTrue());
  257. ASSERT_NO_THROW(falseExpression = storm::expressions::Expression::createFalse());
  258. ASSERT_NO_THROW(threeExpression = storm::expressions::Expression::createIntegerLiteral(3));
  259. ASSERT_NO_THROW(piExpression = storm::expressions::Expression::createDoubleLiteral(3.14));
  260. ASSERT_NO_THROW(boolVarExpression = storm::expressions::Expression::createBooleanVariable("x"));
  261. ASSERT_NO_THROW(intVarExpression = storm::expressions::Expression::createIntegerVariable("y"));
  262. ASSERT_NO_THROW(doubleVarExpression = storm::expressions::Expression::createDoubleVariable("z"));
  263. storm::expressions::Expression tempExpression;
  264. ASSERT_NO_THROW(tempExpression = (intVarExpression < threeExpression || boolVarExpression) && boolVarExpression);
  265. ASSERT_NO_THROW(storm::expressions::SimpleValuation valuation);
  266. storm::expressions::SimpleValuation valuation;
  267. ASSERT_NO_THROW(valuation.addBooleanIdentifier("x"));
  268. ASSERT_NO_THROW(valuation.addBooleanIdentifier("a"));
  269. ASSERT_NO_THROW(valuation.addIntegerIdentifier("y"));
  270. ASSERT_NO_THROW(valuation.addIntegerIdentifier("b"));
  271. ASSERT_NO_THROW(valuation.addDoubleIdentifier("z"));
  272. ASSERT_NO_THROW(valuation.addDoubleIdentifier("c"));
  273. ASSERT_THROW(tempExpression.evaluateAsDouble(&valuation), storm::exceptions::InvalidTypeException);
  274. ASSERT_THROW(tempExpression.evaluateAsInt(&valuation), storm::exceptions::InvalidTypeException);
  275. EXPECT_FALSE(tempExpression.evaluateAsBool(&valuation));
  276. ASSERT_NO_THROW(valuation.setBooleanValue("a", true));
  277. EXPECT_FALSE(tempExpression.evaluateAsBool(&valuation));
  278. ASSERT_NO_THROW(valuation.setIntegerValue("y", 3));
  279. EXPECT_FALSE(tempExpression.evaluateAsBool(&valuation));
  280. ASSERT_NO_THROW(tempExpression = ((intVarExpression < threeExpression).ite(trueExpression, falseExpression)));
  281. ASSERT_THROW(tempExpression.evaluateAsDouble(&valuation), storm::exceptions::InvalidTypeException);
  282. ASSERT_THROW(tempExpression.evaluateAsInt(&valuation), storm::exceptions::InvalidTypeException);
  283. EXPECT_FALSE(tempExpression.evaluateAsBool(&valuation));
  284. }
  285. TEST(Expression, VisitorTest) {
  286. storm::expressions::Expression threeExpression;
  287. storm::expressions::Expression piExpression;
  288. storm::expressions::Expression intVarExpression;
  289. storm::expressions::Expression doubleVarExpression;
  290. ASSERT_NO_THROW(threeExpression = storm::expressions::Expression::createIntegerLiteral(3));
  291. ASSERT_NO_THROW(piExpression = storm::expressions::Expression::createDoubleLiteral(3.14));
  292. ASSERT_NO_THROW(intVarExpression = storm::expressions::Expression::createIntegerVariable("y"));
  293. ASSERT_NO_THROW(doubleVarExpression = storm::expressions::Expression::createDoubleVariable("z"));
  294. storm::expressions::Expression tempExpression = intVarExpression + doubleVarExpression * threeExpression;
  295. storm::expressions::LinearityCheckVisitor visitor;
  296. EXPECT_TRUE(visitor.check(tempExpression));
  297. }