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.

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