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.

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