Storm
A Modern Probabilistic Model Checker
Loading...
Searching...
No Matches
NondeterministicModelParserTest.cpp
Go to the documentation of this file.
1#include "storm-config.h"
2#include "test/storm_gtest.h"
3
8
11
12TEST(NondeterministicModelParserTest, NonExistingFile) {
13 // No matter what happens, please do NOT create a file with the name "nonExistingFile.not"!
14 STORM_SILENT_ASSERT_THROW(storm::parser::NondeterministicModelParser<>::parseMdp(STORM_TEST_RESOURCES_DIR "/nonExistingFile.not",
15 STORM_TEST_RESOURCES_DIR "/nonExistingFile.not"),
16 storm::exceptions::FileIoException);
17}
18
19TEST(NondeterministicModelParserTest, BasicMdpParsing) {
20 // Parse a Mdp and check the result.
22 STORM_TEST_RESOURCES_DIR "/tra/mdp_general.tra", STORM_TEST_RESOURCES_DIR "/lab/mdp_general.lab", STORM_TEST_RESOURCES_DIR "/rew/mdp_general.state.rew",
23 STORM_TEST_RESOURCES_DIR "/rew/mdp_general.trans.rew"));
24
25 ASSERT_EQ(6ul, mdp.getNumberOfStates());
26 ASSERT_EQ(22ul, mdp.getNumberOfTransitions());
27 ASSERT_EQ(11ul, mdp.getNumberOfChoices());
28
29 ASSERT_EQ(2ul, mdp.getInitialStates().getNumberOfSetBits());
30 ASSERT_TRUE(mdp.getInitialStates().get(0));
31 ASSERT_TRUE(mdp.getInitialStates().get(4));
32 ASSERT_EQ(4ul, mdp.getStateLabeling().getNumberOfLabels());
33 ASSERT_EQ(3ul, mdp.getLabelsOfState(0).size());
34
35 ASSERT_TRUE(mdp.hasRewardModel());
36 ASSERT_EQ(0, mdp.getRewardModel("").getStateRewardVector()[0]);
37 ASSERT_EQ(42, mdp.getRewardModel("").getStateRewardVector()[4]);
38 double rewardSum = 0;
39 for (uint_fast64_t i = 0; i < mdp.getRewardModel("").getStateRewardVector().size(); i++) {
40 rewardSum += mdp.getRewardModel("").getStateRewardVector()[i];
41 }
42 ASSERT_EQ(158.32, rewardSum);
43
44 ASSERT_TRUE(mdp.getRewardModel("").hasTransitionRewards());
45 ASSERT_EQ(17ul, mdp.getRewardModel("").getTransitionRewardMatrix().getEntryCount());
46 rewardSum = 0;
47 for (uint_fast64_t i = 0; i < mdp.getRewardModel("").getTransitionRewardMatrix().getRowCount(); i++) {
48 rewardSum += mdp.getRewardModel("").getTransitionRewardMatrix().getRowSum(i);
49 }
50 ASSERT_EQ(1376.864, rewardSum);
51}
52
53TEST(NondeterministicModelParserTest, MismatchedFiles) {
54 // Test file combinations that do not match, i.e. differing number of states, transitions, etc.
55
56 // The labeling file contains a label for a non existent state.
57 STORM_SILENT_ASSERT_THROW(storm::parser::NondeterministicModelParser<>::parseMdp(STORM_TEST_RESOURCES_DIR "/tra/mdp_mismatched.tra",
58 STORM_TEST_RESOURCES_DIR "/lab/mdp_general.lab"),
59 storm::exceptions::OutOfRangeException);
60
61 // The state reward file contains a reward for a non existent state.
62 STORM_SILENT_ASSERT_THROW(storm::parser::NondeterministicModelParser<>::parseMdp(STORM_TEST_RESOURCES_DIR "/tra/mdp_mismatched.tra",
63 STORM_TEST_RESOURCES_DIR "/lab/mdp_mismatched.lab",
64 STORM_TEST_RESOURCES_DIR "/rew/mdp_general.state.rew"),
65 storm::exceptions::OutOfRangeException);
66
67 // The transition reward file contains rewards for a non existent state.
68 STORM_SILENT_ASSERT_THROW(storm::parser::NondeterministicModelParser<>::parseMdp(STORM_TEST_RESOURCES_DIR "/tra/mdp_mismatched.tra",
69 STORM_TEST_RESOURCES_DIR "/lab/mdp_mismatched.lab", "",
70 STORM_TEST_RESOURCES_DIR "/rew/mdp_general.trans.rew"),
71 storm::exceptions::OutOfRangeException);
72
73 // The transition reward file contains rewards for a non existent transition
74 STORM_SILENT_ASSERT_THROW(storm::parser::NondeterministicModelParser<>::parseMdp(STORM_TEST_RESOURCES_DIR "/tra/mdp_mismatched.tra",
75 STORM_TEST_RESOURCES_DIR "/lab/mdp_mismatched.lab", "",
76 STORM_TEST_RESOURCES_DIR "/rew/mdp_mismatched.trans.rew"),
77 storm::exceptions::OutOfRangeException);
78}
TEST(NondeterministicModelParserTest, NonExistingFile)
std::size_t getNumberOfLabels() const
Returns the number of labels managed by this object.
This class represents a (discrete-time) Markov decision process.
Definition Mdp.h:14
std::set< std::string > getLabelsOfState(storm::storage::sparse::state_type state) const
Retrieves the set of labels attached to the given state.
Definition Model.cpp:616
virtual bool hasRewardModel(std::string const &rewardModelName) const override
Retrieves whether the model has a reward model with the given name.
Definition Model.cpp:207
storm::models::sparse::StateLabeling const & getStateLabeling() const
Returns the state labeling associated with this model.
Definition Model.cpp:319
virtual uint_fast64_t getNumberOfTransitions() const override
Returns the number of (non-zero) transitions of the model.
Definition Model.cpp:167
virtual uint_fast64_t getNumberOfStates() const override
Returns the number of states of the model.
Definition Model.cpp:162
RewardModelType const & getRewardModel(std::string const &rewardModelName) const
Retrieves the reward model with the given name, if one exists.
Definition Model.cpp:218
storm::storage::BitVector const & getInitialStates() const
Retrieves the initial states of the model.
Definition Model.cpp:177
uint_fast64_t getNumberOfChoices(uint_fast64_t state) const
Loads a nondeterministic model (Mdp or Ctmdp) from files.
uint_fast64_t getNumberOfSetBits() const
Returns the number of bits that are set to true in this bit vector.
bool get(uint_fast64_t index) const
Retrieves the truth value of the bit at the given index and performs a bound check.
#define STORM_SILENT_ASSERT_THROW(statement, expected_exception)
Definition storm_gtest.h:99