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