Storm 2.0.0.3
A Modern Probabilistic Model Checker
Loading...
Searching...
No Matches
PropertyTest.cpp
Go to the documentation of this file.
1#include "storm-config.h"
2#include "test/storm_gtest.h"
3
4#include <set>
5#include <sstream>
6#include <vector>
7
13
14namespace {
15
16std::vector<storm::modelchecker::FilterType> const allFilterTypes = {storm::modelchecker::FilterType::MIN, storm::modelchecker::FilterType::MAX,
21
22storm::jani::Property filteredProperty(std::string const& name, std::string const& formula, storm::modelchecker::FilterType ft,
23 std::string const& statesFormula) {
26 return storm::jani::Property(name, fe, {});
27}
28
29storm::jani::Property plainProperty(std::string const& name, std::string const& formula, std::string const& comment = "") {
31 return storm::jani::Property(name, parser.parseSingleFormulaFromString(formula), {}, comment);
32}
33
34} // namespace
35
36TEST(PropertyTest, UnnamedProperty) {
37 std::string const formula = "P=? [F \"target\"]";
38 std::string const expected = formula + ";";
39
40 auto const property = plainProperty("", formula);
41
42 EXPECT_EQ(expected, property.asPrismSyntax());
43}
44
45TEST(PropertyTest, NamedProperty) {
46 std::string const name = "p";
47 std::string const formula = "P=? [F \"target\"]";
48 std::string const expected = "\"" + name + "\": " + formula + ";";
49
50 auto const property = plainProperty(name, formula);
51
52 EXPECT_EQ(expected, property.asPrismSyntax());
53}
54
55TEST(PropertyTest, NamedPropertyWithFilter) {
56 std::string const name = "p";
57 std::string const formula = "P=? [F \"target\"]";
58 std::string const statesFormula = "\"a\"";
59 std::string const expected = "\"" + name + "\": filter(max, " + formula + ", " + statesFormula + ");";
60
61 auto const property = filteredProperty(name, formula, storm::modelchecker::FilterType::MAX, statesFormula);
62
63 EXPECT_EQ(expected, property.asPrismSyntax());
64}
65
66TEST(PropertyTest, NamedPropertyWithFilterInitStates) {
67 std::string const name = "p";
68 std::string const formula = "P=? [F \"target\"]";
69 std::string const statesFormula = "\"init\"";
70 std::string const expected = "\"" + name + "\": filter(max, " + formula + ", " + statesFormula + ");";
71
72 auto const property = filteredProperty(name, formula, storm::modelchecker::FilterType::MAX, statesFormula);
73
74 EXPECT_EQ(expected, property.asPrismSyntax());
75
77 auto const reparsed = parser.parseFromString(expected);
78 ASSERT_EQ(1ull, reparsed.size());
79 EXPECT_EQ(expected, reparsed.front().asPrismSyntax());
80}
81
82TEST(PropertyTest, FilterTypeKeywords) {
83 std::set<std::string> keywords;
84
85 for (auto const& ft : allFilterTypes) {
86 std::string const keyword = storm::modelchecker::toPrismSyntax(ft);
87 EXPECT_FALSE(keyword.empty());
88 keywords.insert(keyword);
89 }
90 EXPECT_EQ(allFilterTypes.size(), keywords.size());
91}
92
93TEST(PropertyTest, FilterTypeKeywordsRoundTrip) {
94 std::string const name = "p";
95 std::string const formula = "P=? [F \"a\"]";
96 std::string const statesFormula = "\"b\"";
97
99
100 for (auto const& ft : allFilterTypes) {
101 std::string const expected = "\"" + name + "\": filter(" + storm::modelchecker::toPrismSyntax(ft) + ", " + formula + ", " + statesFormula + ");";
102
103 auto const properties = parser.parseFromString(expected);
104 ASSERT_EQ(1ull, properties.size()) << expected;
105 EXPECT_EQ(ft, properties.front().getFilter().getFilterType()) << expected;
106 EXPECT_EQ(expected, properties.front().asPrismSyntax());
107 }
108}
109
110// 'values' is accepted along with 'printall' but output as 'printall'
111TEST(PropertyTest, FilterKeywordValuesAlias) {
112 std::string const name = "p";
113 std::string const formula = "P=? [F \"a\"]";
114 std::string const statesFormula = "\"b\"";
115 std::string const input = "\"" + name + "\": filter(values, " + formula + ", " + statesFormula + ");";
116 std::string const expected = "\"" + name + "\": filter(printall, " + formula + ", " + statesFormula + ");";
117
119 auto const properties = parser.parseFromString(input);
120 ASSERT_EQ(1ull, properties.size());
121 EXPECT_EQ(storm::modelchecker::FilterType::VALUES, properties.front().getFilter().getFilterType());
122 EXPECT_EQ(expected, properties.front().asPrismSyntax());
123}
124
125TEST(PropertyTest, CommentIsSeparate) {
126 std::string const name = "p";
127 std::string const formula = "P=? [F \"target\"]";
128 std::string const comment = "very important property";
129 std::string const expected = "\"" + name + "\": " + formula + ";";
130
131 auto const property = plainProperty(name, formula, comment);
132
133 EXPECT_EQ(expected, property.asPrismSyntax());
134 EXPECT_EQ(comment, property.getComment());
135}
136
137TEST(PropertyTest, StreamAndStringEqual) {
138 std::string const name = "p";
139 std::string const formula = "P=? [F \"target\"]";
140 std::string const statesFormula = "\"a\"";
141
142 auto const property = filteredProperty(name, formula, storm::modelchecker::FilterType::MAX, statesFormula);
143
144 std::stringstream stream;
145 property.asPrismSyntax(stream);
146
147 EXPECT_EQ(property.asPrismSyntax(), stream.str());
148}
TEST(PropertyTest, UnnamedProperty)
std::vector< storm::jani::Property > parseFromString(std::string const &propertyString) const
Parses the property given by the provided string.
std::shared_ptr< storm::logic::Formula const > parseSingleFormulaFromString(std::string const &formulaString) const
Parses the formula given by the provided string.
std::string toPrismSyntax(FilterType ft)