Storm 1.11.1.1
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
10
11TEST(NondeterministicModelParserTest, NonExistingFile) {
12 // No matter what happens, please do NOT create a file with the name "nonExistingFile.not"!
13 STORM_SILENT_ASSERT_THROW(storm::parser::NondeterministicModelParser<>::parseMdp(STORM_TEST_RESOURCES_DIR "/nonExistingFile.not",
14 STORM_TEST_RESOURCES_DIR "/nonExistingFile.not"),
15 storm::exceptions::FileIoException);
16}
17
18TEST(NondeterministicModelParserTest, BasicMdpParsing) {
19 // Parse a Mdp and check the result.
21 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",
22 STORM_TEST_RESOURCES_DIR "/rew/mdp_general.trans.rew"));
23
24 ASSERT_EQ(6ul, mdp.getNumberOfStates());
25 ASSERT_EQ(22ul, mdp.getNumberOfTransitions());
26 ASSERT_EQ(11ul, mdp.getNumberOfChoices());
27
28 ASSERT_EQ(2ul, mdp.getInitialStates().getNumberOfSetBits());
29 ASSERT_TRUE(mdp.getInitialStates().get(0));
30 ASSERT_TRUE(mdp.getInitialStates().get(4));
31 ASSERT_EQ(4ul, mdp.getStateLabeling().getNumberOfLabels());
32 ASSERT_EQ(3ul, mdp.getLabelsOfState(0).size());
33
34 ASSERT_TRUE(mdp.hasRewardModel());
35 ASSERT_EQ(0, mdp.getRewardModel("").getStateRewardVector()[0]);
36 ASSERT_EQ(42, mdp.getRewardModel("").getStateRewardVector()[4]);
37 double rewardSum = 0;
38 for (uint_fast64_t i = 0; i < mdp.getRewardModel("").getStateRewardVector().size(); i++) {
39 rewardSum += mdp.getRewardModel("").getStateRewardVector()[i];
40 }
41 ASSERT_EQ(158.32, rewardSum);
42
43 ASSERT_TRUE(mdp.getRewardModel("").hasTransitionRewards());
44 ASSERT_EQ(17ul, mdp.getRewardModel("").getTransitionRewardMatrix().getEntryCount());
45 rewardSum = 0;
46 for (uint_fast64_t i = 0; i < mdp.getRewardModel("").getTransitionRewardMatrix().getRowCount(); i++) {
47 rewardSum += mdp.getRewardModel("").getTransitionRewardMatrix().getRowSum(i);
48 }
49 ASSERT_EQ(1376.864, rewardSum);
50}
51
52TEST(NondeterministicModelParserTest, MismatchedFiles) {
53 // Test file combinations that do not match, i.e. differing number of states, transitions, etc.
54
55 // The labeling file contains a label for a non existent state.
56 STORM_SILENT_ASSERT_THROW(storm::parser::NondeterministicModelParser<>::parseMdp(STORM_TEST_RESOURCES_DIR "/tra/mdp_mismatched.tra",
57 STORM_TEST_RESOURCES_DIR "/lab/mdp_general.lab"),
58 storm::exceptions::OutOfRangeException);
59
60 // The state reward file contains a reward for a non existent state.
61 STORM_SILENT_ASSERT_THROW(storm::parser::NondeterministicModelParser<>::parseMdp(STORM_TEST_RESOURCES_DIR "/tra/mdp_mismatched.tra",
62 STORM_TEST_RESOURCES_DIR "/lab/mdp_mismatched.lab",
63 STORM_TEST_RESOURCES_DIR "/rew/mdp_general.state.rew"),
64 storm::exceptions::OutOfRangeException);
65
66 // The transition reward file contains rewards for a non existent state.
67 STORM_SILENT_ASSERT_THROW(storm::parser::NondeterministicModelParser<>::parseMdp(STORM_TEST_RESOURCES_DIR "/tra/mdp_mismatched.tra",
68 STORM_TEST_RESOURCES_DIR "/lab/mdp_mismatched.lab", "",
69 STORM_TEST_RESOURCES_DIR "/rew/mdp_general.trans.rew"),
70 storm::exceptions::OutOfRangeException);
71
72 // The transition reward file contains rewards for a non existent transition
73 STORM_SILENT_ASSERT_THROW(storm::parser::NondeterministicModelParser<>::parseMdp(STORM_TEST_RESOURCES_DIR "/tra/mdp_mismatched.tra",
74 STORM_TEST_RESOURCES_DIR "/lab/mdp_mismatched.lab", "",
75 STORM_TEST_RESOURCES_DIR "/rew/mdp_mismatched.trans.rew"),
76 storm::exceptions::OutOfRangeException);
77}
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:13
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:618
virtual bool hasRewardModel(std::string const &rewardModelName) const override
Retrieves whether the model has a reward model with the given name.
Definition Model.cpp:209
storm::models::sparse::StateLabeling const & getStateLabeling() const
Returns the state labeling associated with this model.
Definition Model.cpp:321
virtual uint_fast64_t getNumberOfTransitions() const override
Returns the number of (non-zero) transitions of the model.
Definition Model.cpp:169
virtual uint_fast64_t getNumberOfStates() const override
Returns the number of states of the model.
Definition Model.cpp:164
RewardModelType const & getRewardModel(std::string const &rewardModelName) const
Retrieves the reward model with the given name, if one exists.
Definition Model.cpp:220
storm::storage::BitVector const & getInitialStates() const
Retrieves the initial states of the model.
Definition Model.cpp:179
uint_fast64_t getNumberOfChoices(uint_fast64_t state) const
Loads a nondeterministic model (Mdp or Ctmdp) from files.
uint64_t getNumberOfSetBits() const
Returns the number of bits that are set to true in this bit vector.
bool get(uint64_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:26