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