Storm
A Modern Probabilistic Model Checker
Loading...
Searching...
No Matches
JaniParserTest.cpp
Go to the documentation of this file.
2#include "storm-config.h"
8#include "test/storm_gtest.h"
9
10TEST(JaniParser, DieExampleTest) {
11 std::string testInput = R"({
12 "jani-version": 1,
13 "name": "die.jani",
14 "type": "dtmc",
15 "features": [ "derived-operators" ],
16 "variables": [
17 {
18 "name": "s",
19 "type": {
20 "base": "int",
21 "kind": "bounded",
22 "lower-bound": 0,
23 "upper-bound": 7
24 },
25 "initial-value": 0
26 },
27 {
28 "name": "d",
29 "type": {
30 "base": "int",
31 "kind": "bounded",
32 "lower-bound": 0,
33 "upper-bound": 6
34 },
35 "initial-value": 0
36 }
37 ],
38 "properties": [
39 {
40 "name": "Probability to throw a six",
41 "expression": {
42 "op": "filter",
43 "fun": "max",
44 "states": { "op": "initial" },
45 "values": {
46 "op": "Pmin",
47 "exp": {
48 "op": "U",
49 "left": true,
50 "right": {
51 "op": "∧",
52 "left": {
53 "op": "=",
54 "left": "s",
55 "right": 7
56 },
57 "right": {
58 "op": "=",
59 "left": "d",
60 "right": 6
61 }
62 }
63 }
64 }
65 }
66 },
67 {
68 "name": "Expected number of coin flips",
69 "expression": {
70 "op": "filter",
71 "fun": "max",
72 "states": { "op": "initial" },
73 "values": {
74 "op": "Emin",
75 "accumulate": [ "steps" ],
76 "exp": 1,
77 "reach": {
78 "op": "=",
79 "left": "s",
80 "right": 7
81 }
82 }
83 }
84 }
85 ],
86 "automata": [
87 {
88 "name": "die",
89 "locations": [{ "name": "l" }],
90 "initial-locations": ["l"],
91 "edges": [
92 {
93 "location": "l",
94 "guard": {
95 "exp": {
96 "op": "=",
97 "left": "s",
98 "right": 0
99 }
100 },
101 "destinations": [
102 {
103 "location": "l",
104 "probability": { "exp": 0.5 },
105 "assignments": [
106 {
107 "ref": "s",
108 "value": 1
109 }
110 ]
111 },
112 {
113 "location": "l",
114 "probability": { "exp": 0.5 },
115 "assignments": [
116 {
117 "ref": "s",
118 "value": 2
119 }
120 ]
121 }
122 ]
123 },
124 {
125 "location": "l",
126 "guard": {
127 "exp": {
128 "left": "s",
129 "op": "=",
130 "right": 1
131 }
132 },
133 "destinations": [
134 {
135 "location": "l",
136 "probability": { "exp": 0.5 },
137 "assignments": [
138 {
139 "ref": "s",
140 "value": 3
141 }
142 ]
143 },
144 {
145 "location": "l",
146 "probability": { "exp": 0.5 },
147 "assignments": [
148 {
149 "ref": "s",
150 "value": 4
151 }
152 ]
153 }
154 ]
155 },
156 {
157 "location": "l",
158 "guard": {
159 "exp": {
160 "left": "s",
161 "op": "=",
162 "right": 2
163 }
164 },
165 "destinations": [
166 {
167 "location": "l",
168 "probability": { "exp": 0.5 },
169 "assignments": [
170 {
171 "ref": "s",
172 "value": 5
173 }
174 ]
175 },
176 {
177 "location": "l",
178 "probability": { "exp": 0.5 },
179 "assignments": [
180 {
181 "ref": "s",
182 "value": 6
183 }
184 ]
185 }
186 ]
187 },
188 {
189 "location": "l",
190 "guard": {
191 "exp": {
192 "left": "s",
193 "op": "=",
194 "right": 3
195 }
196 },
197 "destinations": [
198 {
199 "location": "l",
200 "probability": { "exp": 0.5 },
201 "assignments": [
202 {
203 "ref": "s",
204 "value": 1
205 }
206 ]
207 },
208 {
209 "location": "l",
210 "probability": { "exp": 0.5 },
211 "assignments": [
212 {
213 "ref": "s",
214 "value": 7
215 },
216 {
217 "ref": "d",
218 "value": 1
219 }
220 ]
221 }
222 ]
223 },
224 {
225 "location": "l",
226 "guard": {
227 "exp": {
228 "left": "s",
229 "op": "=",
230 "right": 4
231 }
232 },
233 "destinations": [
234 {
235 "location": "l",
236 "probability": { "exp": 0.5 },
237 "assignments": [
238 {
239 "ref": "s",
240 "value": 7
241 },
242 {
243 "ref": "d",
244 "value": 2
245 }
246 ]
247 },
248 {
249 "location": "l",
250 "probability": { "exp": 0.5 },
251 "assignments": [
252 {
253 "ref": "s",
254 "value": 7
255 },
256 {
257 "ref": "d",
258 "value": 3
259 }
260 ]
261 }
262 ]
263 },
264 {
265 "location": "l",
266 "guard": {
267 "exp": {
268 "left": "s",
269 "op": "=",
270 "right": 5
271 }
272 },
273 "destinations": [
274 {
275 "location": "l",
276 "probability": { "exp": 0.5 },
277 "assignments": [
278 {
279 "ref": "s",
280 "value": 7
281 },
282 {
283 "ref": "d",
284 "value": 4
285 }
286 ]
287 },
288 {
289 "location": "l",
290 "probability": { "exp": 0.5 },
291 "assignments": [
292 {
293 "ref": "s",
294 "value": 7
295 },
296 {
297 "ref": "d",
298 "value": 5
299 }
300 ]
301 }
302 ]
303 },
304 {
305 "location": "l",
306 "guard": {
307 "exp": {
308 "left": "s",
309 "op": "=",
310 "right": 6
311 }
312 },
313 "destinations": [
314 {
315 "location": "l",
316 "probability": { "exp": 0.5 },
317 "assignments": [
318 {
319 "ref": "s",
320 "value": 2
321 }
322 ]
323 },
324 {
325 "location": "l",
326 "probability": { "exp": 0.5 },
327 "assignments": [
328 {
329 "ref": "s",
330 "value": 7
331 },
332 {
333 "ref": "d",
334 "value": 6
335 }
336 ]
337 }
338 ]
339 },
340 {
341 "location": "l",
342 "guard": {
343 "exp": {
344 "left": "s",
345 "op": "=",
346 "right": 7
347 }
348 },
349 "destinations": [
350 {
351 "location": "l",
352 "assignments": [
353 {
354 "ref": "s",
355 "value": 7
356 }
357 ]
358 }
359 ]
360 }
361 ]
362
363 }
364 ],
365 "system": {
366 "elements": [ { "automaton": "die" } ]
367 }
368 })";
369
370 std::pair<storm::jani::Model, std::vector<storm::jani::Property>> result;
371 EXPECT_NO_THROW(result = storm::api::parseJaniModelFromString(testInput));
372 EXPECT_EQ(storm::jani::ModelType::DTMC, result.first.getModelType());
373 EXPECT_TRUE(result.first.hasGlobalVariable("s"));
374 EXPECT_EQ(1ul, result.first.getNumberOfAutomata());
375}
376
377TEST(JaniParser, DieArrayExampleTest) {
378 std::pair<storm::jani::Model, std::vector<storm::jani::Property>> result;
379 EXPECT_NO_THROW(result = storm::api::parseJaniModel(STORM_TEST_RESOURCES_DIR "/dtmc/die_array.jani"));
380 EXPECT_EQ(storm::jani::ModelType::DTMC, result.first.getModelType());
381 EXPECT_TRUE(result.first.containsArrayVariables());
382 EXPECT_TRUE(result.first.hasGlobalVariable("sd"));
383 EXPECT_EQ(1ul, result.first.getNumberOfAutomata());
384}
385
386TEST(JaniParser, FTWCTest) {
387 std::pair<storm::jani::Model, std::vector<storm::jani::Property>> result;
388 EXPECT_NO_THROW(result = storm::api::parseJaniModel(STORM_TEST_RESOURCES_DIR "/ma/ftwc.jani"));
389 EXPECT_EQ(storm::jani::ModelType::MA, result.first.getModelType());
390 EXPECT_TRUE(result.first.containsArrayVariables());
391 EXPECT_TRUE(result.first.hasGlobalVariable("workstations_up"));
392 EXPECT_TRUE(result.first.hasGlobalVariable("workstations_up"));
393 EXPECT_EQ(6ul, result.first.getNumberOfAutomata());
394 EXPECT_TRUE(result.first.getAutomaton("Switch").hasVariable("id"));
395 EXPECT_TRUE(result.first.getAutomaton("Switch_1").hasVariable("id"));
396 EXPECT_TRUE(result.first.getAutomaton("Workstation").hasVariable("id"));
397 EXPECT_TRUE(result.first.getAutomaton("Workstation_1").hasVariable("id"));
398 EXPECT_TRUE(result.first.getAutomaton(1).hasVariable("id"));
399}
400
401TEST(JaniParser, DieArrayNestedExampleTest) {
402 std::pair<storm::jani::Model, std::vector<storm::jani::Property>> result;
403 EXPECT_NO_THROW(result = storm::api::parseJaniModel(STORM_TEST_RESOURCES_DIR "/dtmc/die_array_nested.jani"));
404 EXPECT_EQ(storm::jani::ModelType::DTMC, result.first.getModelType());
405 EXPECT_TRUE(result.first.containsArrayVariables());
406 EXPECT_TRUE(result.first.hasGlobalVariable("sd"));
407 EXPECT_EQ(1ul, result.first.getNumberOfAutomata());
408}
409
410TEST(JaniParser, UnassignedVariablesTest) {
411 std::pair<storm::jani::Model, std::vector<storm::jani::Property>> result;
412 EXPECT_NO_THROW(result = storm::api::parseJaniModel(STORM_TEST_RESOURCES_DIR "/mdp/unassigned-variables.jani"));
413 EXPECT_EQ(storm::jani::ModelType::MDP, result.first.getModelType());
414 EXPECT_TRUE(result.first.hasConstant("c"));
415 EXPECT_EQ(2ul, result.first.getNumberOfAutomata());
416}
417
418TEST(JaniParser, TrigonometryAndTranscendentalNumbersTest) {
419 std::pair<storm::jani::Model, std::vector<storm::jani::Property>> result;
420 EXPECT_NO_THROW(result = storm::api::parseJaniModel(STORM_TEST_RESOURCES_DIR "/dtmc/test_trigonometry.jani"));
421 auto& model = result.first;
422 auto& properties = result.second;
423 EXPECT_EQ(storm::jani::ModelType::DTMC, model.getModelType());
424 EXPECT_EQ(model.getNumberOfAutomata(), 1U);
425 EXPECT_EQ(properties.size(), 2U);
426 EXPECT_NO_THROW(model.substitute({}, true));
427}
TEST(JaniParser, DieExampleTest)
std::pair< storm::jani::Model, std::vector< storm::jani::Property > > parseJaniModel(std::string const &filename, boost::optional< std::vector< std::string > > const &propertyFilter)
std::pair< storm::jani::Model, std::vector< storm::jani::Property > > parseJaniModelFromString(std::string const &jsonstring, boost::optional< std::vector< std::string > > const &propertyFilter)