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.

369 lines
24 KiB

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