Storm 1.11.1.1
A Modern Probabilistic Model Checker
Loading...
Searching...
No Matches
SparseItemLabelingParserTest.cpp
Go to the documentation of this file.
1#include "storm-config.h"
2#include "test/storm_gtest.h"
3
4#include <memory>
5
11
12TEST(SparseItemLabelingParserTest, NonExistingFile) {
13 // No matter what happens, please do NOT create a file with the name "nonExistingFile.not"!
15 storm::exceptions::FileIoException);
16}
17
18TEST(SparseItemLabelingParserTest, BasicDeterministicParsing) {
19 // This test is based on a test case from the original MRMC.
20
21 // Parsing the file
23 storm::parser::SparseItemLabelingParser::parseAtomicPropositionLabeling(12, STORM_TEST_RESOURCES_DIR "/lab/pctl_general.lab");
24
25 // Checking whether all propositions are in the labelling
26
27 char phi[] = "phi", psi[] = "psi", smth[] = "smth";
28
29 ASSERT_TRUE(labeling.containsLabel(phi));
30 ASSERT_TRUE(labeling.containsLabel(psi));
31 ASSERT_TRUE(labeling.containsLabel(smth));
32
33 // Testing whether all and only the correct nodes are labeled with "phi"
34 ASSERT_TRUE(labeling.getStateHasLabel(phi, 0));
35 ASSERT_TRUE(labeling.getStateHasLabel(phi, 1));
36 ASSERT_TRUE(labeling.getStateHasLabel(phi, 2));
37
38 ASSERT_FALSE(labeling.getStateHasLabel(phi, 3));
39 ASSERT_FALSE(labeling.getStateHasLabel(phi, 4));
40 ASSERT_FALSE(labeling.getStateHasLabel(phi, 5));
41 ASSERT_FALSE(labeling.getStateHasLabel(phi, 6));
42 ASSERT_FALSE(labeling.getStateHasLabel(phi, 7));
43 ASSERT_FALSE(labeling.getStateHasLabel(phi, 8));
44 ASSERT_FALSE(labeling.getStateHasLabel(phi, 9));
45 ASSERT_FALSE(labeling.getStateHasLabel(phi, 10));
46 ASSERT_FALSE(labeling.getStateHasLabel(phi, 11));
47
48 // Testing whether all and only the correct nodes are labeled with "psi"
49 ASSERT_FALSE(labeling.getStateHasLabel(psi, 0));
50 ASSERT_FALSE(labeling.getStateHasLabel(psi, 1));
51 ASSERT_FALSE(labeling.getStateHasLabel(psi, 2));
52 ASSERT_FALSE(labeling.getStateHasLabel(psi, 3));
53 ASSERT_FALSE(labeling.getStateHasLabel(psi, 4));
54 ASSERT_FALSE(labeling.getStateHasLabel(psi, 5));
55 ASSERT_FALSE(labeling.getStateHasLabel(psi, 6));
56 ASSERT_FALSE(labeling.getStateHasLabel(psi, 7));
57 ASSERT_FALSE(labeling.getStateHasLabel(psi, 8));
58 ASSERT_FALSE(labeling.getStateHasLabel(psi, 9));
59 ASSERT_FALSE(labeling.getStateHasLabel(psi, 10));
60 ASSERT_FALSE(labeling.getStateHasLabel(psi, 11));
61
62 // Testing whether all and only the correct nodes are labeled with "smth"
63 ASSERT_TRUE(labeling.getStateHasLabel(smth, 2));
64
65 ASSERT_FALSE(labeling.getStateHasLabel(smth, 0));
66 ASSERT_FALSE(labeling.getStateHasLabel(smth, 1));
67 ASSERT_FALSE(labeling.getStateHasLabel(smth, 3));
68 ASSERT_FALSE(labeling.getStateHasLabel(smth, 4));
69 ASSERT_FALSE(labeling.getStateHasLabel(smth, 5));
70 ASSERT_FALSE(labeling.getStateHasLabel(smth, 6));
71 ASSERT_FALSE(labeling.getStateHasLabel(smth, 7));
72 ASSERT_FALSE(labeling.getStateHasLabel(smth, 8));
73 ASSERT_FALSE(labeling.getStateHasLabel(smth, 9));
74 ASSERT_FALSE(labeling.getStateHasLabel(smth, 10));
75 ASSERT_FALSE(labeling.getStateHasLabel(smth, 11));
76}
77
78TEST(SparseItemLabelingParserTest, BasicNondeterministicParsing) {
79 std::vector<uint_fast64_t> choiceIndices{0, 3, 5, 6, 9, 11};
80
81 // Parsing the file
83 storm::parser::SparseItemLabelingParser::parseChoiceLabeling(11, STORM_TEST_RESOURCES_DIR "/lab/nondet.choicelab", choiceIndices);
84
85 // Checking whether the parsed labeling is correct
86 ASSERT_TRUE(labeling.containsLabel("alpha"));
87 EXPECT_EQ(2ull, labeling.getChoices("alpha").getNumberOfSetBits());
88 EXPECT_TRUE(labeling.getChoiceHasLabel("alpha", 0));
89 EXPECT_TRUE(labeling.getChoiceHasLabel("alpha", 1));
90
91 ASSERT_TRUE(labeling.containsLabel("beta"));
92 EXPECT_EQ(3ull, labeling.getChoices("beta").getNumberOfSetBits());
93 EXPECT_TRUE(labeling.getChoiceHasLabel("beta", 1));
94 EXPECT_TRUE(labeling.getChoiceHasLabel("beta", 3));
95 EXPECT_TRUE(labeling.getChoiceHasLabel("beta", 8));
96
97 ASSERT_TRUE(labeling.containsLabel("gamma"));
98 EXPECT_EQ(1ull, labeling.getChoices("gamma").getNumberOfSetBits());
99 EXPECT_TRUE(labeling.getChoiceHasLabel("gamma", 2));
100
101 ASSERT_TRUE(labeling.containsLabel("delta"));
102 EXPECT_TRUE(labeling.getChoices("delta").empty());
103}
104
105TEST(SparseItemLabelingParserTest, NoDeclarationTagHeader) {
106 // No #DECLARATION tag in file
107 STORM_SILENT_ASSERT_THROW(storm::parser::SparseItemLabelingParser::parseAtomicPropositionLabeling(3, STORM_TEST_RESOURCES_DIR "/lab/noDeclarationTag.lab"),
108 storm::exceptions::WrongFormatException);
109}
110
111TEST(SparseItemLabelingParserTest, NoEndTagHeader) {
112 // No #END tag in file.
114 storm::exceptions::WrongFormatException);
115}
116
117TEST(SparseItemLabelingParserTest, MisspelledDeclarationTagHeader) {
118 // The #DECLARATION tag is misspelled.
120 storm::parser::SparseItemLabelingParser::parseAtomicPropositionLabeling(3, STORM_TEST_RESOURCES_DIR "/lab/declarationMisspell.lab"),
121 storm::exceptions::WrongFormatException);
122}
123
124TEST(SparseItemLabelingParserTest, MisspelledEndTagHeader) {
125 // The #END tag is misspelled.
127 storm::exceptions::WrongFormatException);
128}
129
130TEST(SparseItemLabelingParserTest, NoLabelDeclaredNoneGiven) {
131 // No label between #DECLARATION and #END and no labels given.
133 storm::parser::SparseItemLabelingParser::parseAtomicPropositionLabeling(13, STORM_TEST_RESOURCES_DIR "/lab/noLabelsDecNoneGiven.lab");
134 ASSERT_EQ(0ul, labeling.getNumberOfLabels());
135 for (uint_fast64_t i = 0; i < 13; i++) {
136 ASSERT_TRUE(labeling.getLabelsOfState(i).empty());
137 }
138}
139
140TEST(SparseItemLabelingParserTest, UndeclaredLabelsGiven) {
141 // Undeclared labels given.
143 storm::parser::SparseItemLabelingParser::parseAtomicPropositionLabeling(3, STORM_TEST_RESOURCES_DIR "/lab/undeclaredLabelsGiven.lab"),
144 storm::exceptions::WrongFormatException);
145}
146
147TEST(SparseItemLabelingParserTest, LabelForNonExistentState) {
148 // The index of one of the state that are to be labeled is higher than the number of states in the model.
150 storm::parser::SparseItemLabelingParser::parseAtomicPropositionLabeling(3, STORM_TEST_RESOURCES_DIR "/lab/labelForNonexistentState.lab"),
151 storm::exceptions::OutOfRangeException);
152}
153
154// Note: As implemented at the moment, each label given for a state in any line is set to true for that state (logical or over all lines for that state).
155// This behavior might not be ideal as multiple lines for one state are not necessary and might indicate a corrupt or wrong file.
156TEST(SparseItemLabelingParserTest, DoubledLines) {
157 // There are multiple lines attributing labels to the same state.
159 storm::exceptions::WrongFormatException);
160
161 // There is a line for a state that has been skipped.
163 storm::parser::SparseItemLabelingParser::parseAtomicPropositionLabeling(6, STORM_TEST_RESOURCES_DIR "/lab/doubledLinesSkipped.lab"),
164 storm::exceptions::WrongFormatException);
165}
166
167TEST(SparseItemLabelingParserTest, WrongProposition) {
168 // Swapped the state index and the label at one entry.
170 storm::parser::SparseItemLabelingParser::parseAtomicPropositionLabeling(3, STORM_TEST_RESOURCES_DIR "/lab/swappedStateAndProposition.lab"),
171 storm::exceptions::WrongFormatException);
172}
173
174TEST(SparseItemLabelingParserTest, Whitespaces) {
175 // Different configurations of allowed whitespaces are tested.
176
177 // First parse the labeling file without added whitespaces and obtain the hash of its parsed representation.
179 storm::parser::SparseItemLabelingParser::parseAtomicPropositionLabeling(13, STORM_TEST_RESOURCES_DIR "/lab/withoutWhitespaces.lab");
180
181 // Now parse the labeling file with the added whitespaces and compare the hashes.
183 storm::parser::SparseItemLabelingParser::parseAtomicPropositionLabeling(13, STORM_TEST_RESOURCES_DIR "/lab/withWhitespaces.lab");
184 ASSERT_TRUE(labeling == labeling2);
185}
TEST(SparseItemLabelingParserTest, NonExistingFile)
This class manages the labeling of the choice space with a number of (atomic) labels.
storm::storage::BitVector const & getChoices(std::string const &label) const
Returns the labeling of choices associated with the given label.
bool getChoiceHasLabel(std::string const &label, uint64_t choice) const
Checks whether a given choice is labeled with the given label.
bool containsLabel(std::string const &label) const
Checks whether a label is registered within this labeling.
std::size_t getNumberOfLabels() const
Returns the number of labels managed by this object.
This class manages the labeling of the state space with a number of (atomic) labels.
bool getStateHasLabel(std::string const &label, storm::storage::sparse::state_type state) const
Checks whether a given state is labeled with the given label.
std::set< std::string > getLabelsOfState(storm::storage::sparse::state_type state) const
Retrieves the set of labels attached to the given state.
static storm::models::sparse::ChoiceLabeling parseChoiceLabeling(uint_fast64_t choiceCount, std::string const &filename, boost::optional< std::vector< uint_fast64_t > > const &nondeterministicChoiceIndices=boost::none)
Parses the given file and returns the resulting choice labeling.
static storm::models::sparse::StateLabeling parseAtomicPropositionLabeling(uint_fast64_t stateCount, std::string const &filename)
Parses the given file and returns the resulting state labeling.
bool empty() const
Retrieves whether no bits are set to true in this bit vector.
uint64_t getNumberOfSetBits() const
Returns the number of bits that are set to true in this bit vector.
#define STORM_SILENT_ASSERT_THROW(statement, expected_exception)
Definition storm_gtest.h:26