You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

64 lines
4.0 KiB

  1. #include "gtest/gtest.h"
  2. #include "storm-config.h"
  3. #include "src/parser/NondeterministicModelParser.h"
  4. #include "src/models/sparse/Mdp.h"
  5. #include "src/models/sparse/StandardRewardModel.h"
  6. #include "src/exceptions/FileIoException.h"
  7. #include "src/exceptions/OutOfRangeException.h"
  8. #include "src/exceptions/InvalidArgumentException.h"
  9. TEST(NondeterministicModelParserTest, NonExistingFile) {
  10. // No matter what happens, please do NOT create a file with the name "nonExistingFile.not"!
  11. ASSERT_THROW(storm::parser::NondeterministicModelParser::parseMdp(STORM_CPP_TESTS_BASE_PATH "/nonExistingFile.not", STORM_CPP_TESTS_BASE_PATH "/nonExistingFile.not"), storm::exceptions::FileIoException);
  12. }
  13. TEST(NondeterministicModelParserTest, BasicMdpParsing) {
  14. // Parse a Mdp and check the result.
  15. storm::models::sparse::Mdp<double> mdp(storm::parser::NondeterministicModelParser::parseMdp(STORM_CPP_TESTS_BASE_PATH "/functional/parser/tra_files/mdp_general.tra", STORM_CPP_TESTS_BASE_PATH "/functional/parser/lab_files/mdp_general.lab", STORM_CPP_TESTS_BASE_PATH "/functional/parser/rew_files/mdp_general.state.rew", STORM_CPP_TESTS_BASE_PATH "/functional/parser/rew_files/mdp_general.trans.rew"));
  16. ASSERT_EQ(6ul, mdp.getNumberOfStates());
  17. ASSERT_EQ(22ul, mdp.getNumberOfTransitions());
  18. ASSERT_EQ(11ul, mdp.getNumberOfChoices());
  19. ASSERT_EQ(2ul, mdp.getInitialStates().getNumberOfSetBits());
  20. ASSERT_TRUE(mdp.getInitialStates().get(0));
  21. ASSERT_TRUE(mdp.getInitialStates().get(4));
  22. ASSERT_EQ(4ul, mdp.getStateLabeling().getNumberOfLabels());
  23. ASSERT_EQ(3ul, mdp.getLabelsOfState(0).size());
  24. ASSERT_TRUE(mdp.hasRewardModel());
  25. ASSERT_EQ(0, mdp.getRewardModel("").getStateRewardVector()[0]);
  26. ASSERT_EQ(42, mdp.getRewardModel("").getStateRewardVector()[4]);
  27. double rewardSum = 0;
  28. for(uint_fast64_t i = 0; i < mdp.getRewardModel("").getStateRewardVector().size(); i++) {
  29. rewardSum += mdp.getRewardModel("").getStateRewardVector()[i];
  30. }
  31. ASSERT_EQ(158.32, rewardSum);
  32. ASSERT_TRUE(mdp.getRewardModel("").hasTransitionRewards());
  33. ASSERT_EQ(17ul, mdp.getRewardModel("").getTransitionRewardMatrix().getEntryCount());
  34. rewardSum = 0;
  35. for(uint_fast64_t i = 0; i < mdp.getRewardModel("").getTransitionRewardMatrix().getRowCount(); i++) {
  36. rewardSum += mdp.getRewardModel("").getTransitionRewardMatrix().getRowSum(i);
  37. }
  38. ASSERT_EQ(1376.864, rewardSum);
  39. }
  40. TEST(NondeterministicModelParserTest, MismatchedFiles) {
  41. // Test file combinations that do not match, i.e. differing number of states, transitions, etc.
  42. // The labeling file contains a label for a non existent state.
  43. ASSERT_THROW(storm::parser::NondeterministicModelParser::parseMdp(STORM_CPP_TESTS_BASE_PATH "/functional/parser/tra_files/mdp_mismatched.tra", STORM_CPP_TESTS_BASE_PATH "/functional/parser/lab_files/mdp_general.lab"), storm::exceptions::OutOfRangeException);
  44. // The state reward file contains a reward for a non existent state.
  45. ASSERT_THROW(storm::parser::NondeterministicModelParser::parseMdp(STORM_CPP_TESTS_BASE_PATH "/functional/parser/tra_files/mdp_mismatched.tra", STORM_CPP_TESTS_BASE_PATH "/functional/parser/lab_files/mdp_mismatched.lab", STORM_CPP_TESTS_BASE_PATH "/functional/parser/rew_files/mdp_general.state.rew"), storm::exceptions::OutOfRangeException);
  46. // The transition reward file contains rewards for a non existent state.
  47. ASSERT_THROW(storm::parser::NondeterministicModelParser::parseMdp(STORM_CPP_TESTS_BASE_PATH "/functional/parser/tra_files/mdp_mismatched.tra", STORM_CPP_TESTS_BASE_PATH "/functional/parser/lab_files/mdp_mismatched.lab", "", STORM_CPP_TESTS_BASE_PATH "/functional/parser/rew_files/mdp_general.trans.rew"), storm::exceptions::OutOfRangeException);
  48. // The transition reward file contains rewards for a non existent transition
  49. ASSERT_THROW(storm::parser::NondeterministicModelParser::parseMdp(STORM_CPP_TESTS_BASE_PATH "/functional/parser/tra_files/mdp_mismatched.tra", STORM_CPP_TESTS_BASE_PATH "/functional/parser/lab_files/mdp_mismatched.lab", "", STORM_CPP_TESTS_BASE_PATH "/functional/parser/rew_files/mdp_mismatched.trans.rew"), storm::exceptions::OutOfRangeException);
  50. }