Storm 2.0.0.3
A Modern Probabilistic Model Checker
Loading...
Searching...
No Matches
JaniParserTest.cpp
Go to the documentation of this file.
1#include "storm-config.h"
2
3#include <fstream>
4#include <iterator>
5#include "test/storm_gtest.h"
6
10#include "storm/io/file.h"
16
17TEST(JaniParser, DieExampleTest) {
18 std::ifstream file;
19 storm::io::openFile(STORM_TEST_RESOURCES_DIR "/dtmc/die_janiproperties.jani", file);
20 std::string const testInput{std::istreambuf_iterator<char>(file), std::istreambuf_iterator<char>()};
21 ASSERT_FALSE(testInput.empty());
22
23 std::pair<storm::jani::Model, std::vector<storm::jani::Property>> result;
24 EXPECT_NO_THROW(result = storm::api::parseJaniModelFromString(testInput));
25 EXPECT_EQ(storm::jani::ModelType::DTMC, result.first.getModelType());
26 EXPECT_TRUE(result.first.hasGlobalVariable("s"));
27 EXPECT_EQ(1ul, result.first.getNumberOfAutomata());
28
29 ASSERT_EQ(12ul, result.second.size());
30
31 // Parse from file vs parse from string
32 EXPECT_EQ(storm::api::parseJaniModel(STORM_TEST_RESOURCES_DIR "/dtmc/die_janiproperties.jani").second.size(), result.second.size());
33
34 auto const& conjunction = result.second[2].getRawFormula()->asProbabilityOperatorFormula().getSubformula();
35 ASSERT_TRUE(conjunction.isBinaryBooleanPathFormula());
36
37 auto const& disjunction = result.second[3].getRawFormula()->asProbabilityOperatorFormula().getSubformula();
38 ASSERT_TRUE(disjunction.isBinaryBooleanPathFormula());
39
40 auto const& negation = result.second[4].getRawFormula()->asProbabilityOperatorFormula().getSubformula();
41 ASSERT_TRUE(negation.isUnaryBooleanPathFormula());
42
43 auto const& implication = result.second[5].getRawFormula()->asProbabilityOperatorFormula().getSubformula();
44 ASSERT_TRUE(implication.isBinaryBooleanPathFormula());
45
46 auto const& stateConjunction = *result.second[6].getRawFormula();
47 ASSERT_TRUE(stateConjunction.isBinaryBooleanStateFormula());
48
49 auto const& weakUntil = result.second[7].getRawFormula()->asProbabilityOperatorFormula().getSubformula();
50 ASSERT_TRUE(weakUntil.isWeakUntilFormula());
51
52 auto const& release = result.second[8].getRawFormula()->asProbabilityOperatorFormula().getSubformula();
53 ASSERT_TRUE(release.isReleaseFormula());
54}
55
56TEST(JaniParser, DieExampleFragmentTest) {
57 std::pair<storm::jani::Model, std::vector<storm::jani::Property>> result;
58 EXPECT_NO_THROW(result = storm::api::parseJaniModel(STORM_TEST_RESOURCES_DIR "/dtmc/die_janiproperties.jani"));
59 ASSERT_EQ(12ul, result.second.size());
60
61 auto const& weakUntil = result.second[7].getRawFormula()->asProbabilityOperatorFormula().getSubformula();
62 auto const& release = result.second[8].getRawFormula()->asProbabilityOperatorFormula().getSubformula();
63 auto const& until = result.second[9].getRawFormula()->asProbabilityOperatorFormula().getSubformula();
64
65 // Weak until
66 ASSERT_TRUE(weakUntil.isWeakUntilFormula());
67 EXPECT_FALSE(weakUntil.isInFragment(storm::logic::pctl()));
68 EXPECT_TRUE(weakUntil.isInFragment(storm::logic::pctlstar()));
69
70 // Release
71 ASSERT_TRUE(release.isReleaseFormula());
72 EXPECT_FALSE(release.isInFragment(storm::logic::pctl()));
73 EXPECT_TRUE(release.isInFragment(storm::logic::pctlstar()));
74
75 // Until
76 ASSERT_TRUE(until.isUntilFormula());
77 EXPECT_TRUE(until.isInFragment(storm::logic::pctl()));
78 EXPECT_TRUE(until.isInFragment(storm::logic::pctlstar()));
79}
80
81TEST(JaniParser, DieArrayExampleTest) {
82 std::pair<storm::jani::Model, std::vector<storm::jani::Property>> result;
83 EXPECT_NO_THROW(result = storm::api::parseJaniModel(STORM_TEST_RESOURCES_DIR "/dtmc/die_array.jani"));
84 EXPECT_EQ(storm::jani::ModelType::DTMC, result.first.getModelType());
85 EXPECT_TRUE(result.first.containsArrayVariables());
86 EXPECT_TRUE(result.first.hasGlobalVariable("sd"));
87 EXPECT_EQ(1ul, result.first.getNumberOfAutomata());
88}
89
90TEST(JaniParser, FTWCTest) {
91 std::pair<storm::jani::Model, std::vector<storm::jani::Property>> result;
92 EXPECT_NO_THROW(result = storm::api::parseJaniModel(STORM_TEST_RESOURCES_DIR "/ma/ftwc.jani"));
93 EXPECT_EQ(storm::jani::ModelType::MA, result.first.getModelType());
94 EXPECT_TRUE(result.first.containsArrayVariables());
95 EXPECT_TRUE(result.first.hasGlobalVariable("workstations_up"));
96 EXPECT_TRUE(result.first.hasGlobalVariable("workstations_up"));
97 EXPECT_EQ(6ul, result.first.getNumberOfAutomata());
98 EXPECT_TRUE(result.first.getAutomaton("Switch").hasVariable("id"));
99 EXPECT_TRUE(result.first.getAutomaton("Switch_1").hasVariable("id"));
100 EXPECT_TRUE(result.first.getAutomaton("Workstation").hasVariable("id"));
101 EXPECT_TRUE(result.first.getAutomaton("Workstation_1").hasVariable("id"));
102 EXPECT_TRUE(result.first.getAutomaton(1).hasVariable("id"));
103}
104
105TEST(JaniParser, DieArrayNestedExampleTest) {
106 std::pair<storm::jani::Model, std::vector<storm::jani::Property>> result;
107 EXPECT_NO_THROW(result = storm::api::parseJaniModel(STORM_TEST_RESOURCES_DIR "/dtmc/die_array_nested.jani"));
108 EXPECT_EQ(storm::jani::ModelType::DTMC, result.first.getModelType());
109 EXPECT_TRUE(result.first.containsArrayVariables());
110 EXPECT_TRUE(result.first.hasGlobalVariable("sd"));
111 EXPECT_EQ(1ul, result.first.getNumberOfAutomata());
112}
113
114TEST(JaniParser, UnassignedVariablesTest) {
115 std::pair<storm::jani::Model, std::vector<storm::jani::Property>> result;
116 EXPECT_NO_THROW(result = storm::api::parseJaniModel(STORM_TEST_RESOURCES_DIR "/mdp/unassigned-variables.jani"));
117 EXPECT_EQ(storm::jani::ModelType::MDP, result.first.getModelType());
118 EXPECT_TRUE(result.first.hasConstant("c"));
119 EXPECT_EQ(2ul, result.first.getNumberOfAutomata());
120}
121
122TEST(JaniParser, TrigonometryAndTranscendentalNumbersTest) {
123 std::pair<storm::jani::Model, std::vector<storm::jani::Property>> result;
124 EXPECT_NO_THROW(result = storm::api::parseJaniModel(STORM_TEST_RESOURCES_DIR "/dtmc/test_trigonometry.jani"));
125 auto& model = result.first;
126 auto& properties = result.second;
127 EXPECT_EQ(storm::jani::ModelType::DTMC, model.getModelType());
128 EXPECT_EQ(model.getNumberOfAutomata(), 1U);
129 EXPECT_EQ(properties.size(), 2U);
130 EXPECT_NO_THROW(model.substitute({}, true));
131}
132
133TEST(JaniParser, MultiobjectiveTest) {
134 std::pair<storm::jani::Model, std::vector<storm::jani::Property>> result;
135 EXPECT_NO_THROW(result = storm::api::parseJaniModel(STORM_TEST_RESOURCES_DIR "/mdp/multiobj_consensus2_3_2.jani"));
136 auto& model = result.first;
137 EXPECT_EQ(storm::jani::ModelType::MDP, model.getModelType());
138 auto& properties = result.second;
139 ASSERT_EQ(properties.size(), 6U);
140 for (size_t i = 0; i < properties.size(); ++i) {
141 auto const& f = properties[i].getRawFormula();
142 ASSERT_TRUE(f->isMultiObjectiveFormula()) << "Property #" << i << ": " << *f;
143 // First three formulas are tradeoff, last three are lexicographic
144 EXPECT_EQ(i < 3, f->asMultiObjectiveFormula().isTradeoff()) << "Property #" << i << ": " << *f;
145 EXPECT_EQ(i >= 3, f->asMultiObjectiveFormula().isLexicographic()) << "Property #" << i << ": " << *f;
146 // Formulas #0 and #3 have Boolean results
147 EXPECT_EQ(i == 0 || i == 3, f->asMultiObjectiveFormula().hasQualitativeResult()) << "Property #" << i << ": " << *f;
148 // Formulas #2 and #5 have multi-dimensional results
149 EXPECT_EQ(i == 2 || i == 5, f->asMultiObjectiveFormula().hasMultiDimensionalResult()) << "Property #" << i << ": " << *f;
150 }
151}
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)
void openFile(std::string const &filepath, std::ofstream &filestream, bool append=false, bool silent=false)
Open the given file for writing.
Definition file.h:18
FragmentSpecification pctlstar()
FragmentSpecification pctl()