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.

98 lines
5.4 KiB

  1. #include "gtest/gtest.h"
  2. #include "storm-config.h"
  3. #include "src/parser/DeterministicModelParser.h"
  4. #include "src/models/sparse/Dtmc.h"
  5. #include "src/models/sparse/Ctmc.h"
  6. #include "src/exceptions/FileIoException.h"
  7. #include "src/exceptions/InvalidArgumentException.h"
  8. #include "src/exceptions/OutOfRangeException.h"
  9. TEST(DeterministicModelParserTest, NonExistingFile) {
  10. // No matter what happens, please do NOT create a file with the name "nonExistingFile.not"!
  11. ASSERT_THROW(storm::parser::DeterministicModelParser::parseDtmc(STORM_CPP_TESTS_BASE_PATH "/nonExistingFile.not", STORM_CPP_TESTS_BASE_PATH "/nonExistingFile.not"), storm::exceptions::FileIoException);
  12. ASSERT_THROW(storm::parser::DeterministicModelParser::parseCtmc(STORM_CPP_TESTS_BASE_PATH "/nonExistingFile.not", STORM_CPP_TESTS_BASE_PATH "/nonExistingFile.not"), storm::exceptions::FileIoException);
  13. }
  14. TEST(DeterministicModelParserTest, BasicDtmcParsing) {
  15. // Parse a Dtmc and check the result.
  16. storm::models::sparse::Dtmc<double> dtmc(storm::parser::DeterministicModelParser::parseDtmc(STORM_CPP_TESTS_BASE_PATH "/functional/parser/tra_files/dtmc_general.tra", STORM_CPP_TESTS_BASE_PATH "/functional/parser/lab_files/dtmc_general.lab", STORM_CPP_TESTS_BASE_PATH "/functional/parser/rew_files/dtmc_general.state.rew", STORM_CPP_TESTS_BASE_PATH "/functional/parser/rew_files/dtmc_general.trans.rew"));
  17. ASSERT_EQ(8ul, dtmc.getNumberOfStates());
  18. ASSERT_EQ(16ul, dtmc.getNumberOfTransitions());
  19. ASSERT_EQ(2ul, dtmc.getInitialStates().getNumberOfSetBits());
  20. ASSERT_TRUE(dtmc.getInitialStates().get(0));
  21. ASSERT_TRUE(dtmc.getInitialStates().get(7));
  22. ASSERT_EQ(5ul, dtmc.getStateLabeling().getNumberOfLabels());
  23. ASSERT_EQ(2ul, dtmc.getLabelsOfState(6).size());
  24. ASSERT_TRUE(dtmc.hasStateRewards());
  25. ASSERT_EQ(42, dtmc.getStateRewardVector()[7]);
  26. double rewardSum = 0;
  27. for(uint_fast64_t i = 0; i < dtmc.getStateRewardVector().size(); i++) {
  28. rewardSum += dtmc.getStateRewardVector()[i];
  29. }
  30. ASSERT_EQ(263.32, rewardSum);
  31. ASSERT_TRUE(dtmc.hasTransitionRewards());
  32. ASSERT_EQ(17ul, dtmc.getTransitionRewardMatrix().getEntryCount());
  33. rewardSum = 0;
  34. for(uint_fast64_t i = 0; i < dtmc.getTransitionRewardMatrix().getRowCount(); i++) {
  35. rewardSum += dtmc.getTransitionRewardMatrix().getRowSum(i);
  36. }
  37. ASSERT_EQ(125.4, rewardSum);
  38. }
  39. TEST(DeterministicModelParserTest, BasicCtmcParsing) {
  40. // Parse a Ctmc and check the result.
  41. storm::models::sparse::Ctmc<double> ctmc(storm::parser::DeterministicModelParser::parseCtmc(STORM_CPP_TESTS_BASE_PATH "/functional/parser/tra_files/dtmc_general.tra", STORM_CPP_TESTS_BASE_PATH "/functional/parser/lab_files/dtmc_general.lab", STORM_CPP_TESTS_BASE_PATH "/functional/parser/rew_files/dtmc_general.state.rew", STORM_CPP_TESTS_BASE_PATH "/functional/parser/rew_files/dtmc_general.trans.rew"));
  42. ASSERT_EQ(8ul, ctmc.getNumberOfStates());
  43. ASSERT_EQ(16ul, ctmc.getNumberOfTransitions());
  44. ASSERT_EQ(2ul, ctmc.getInitialStates().getNumberOfSetBits());
  45. ASSERT_TRUE(ctmc.getInitialStates().get(0));
  46. ASSERT_TRUE(ctmc.getInitialStates().get(7));
  47. ASSERT_EQ(5ul, ctmc.getStateLabeling().getNumberOfLabels());
  48. ASSERT_EQ(2ul, ctmc.getLabelsOfState(6).size());
  49. ASSERT_TRUE(ctmc.hasStateRewards());
  50. ASSERT_EQ(42, ctmc.getStateRewardVector()[7]);
  51. double rewardSum = 0;
  52. for(uint_fast64_t i = 0; i < ctmc.getStateRewardVector().size(); i++) {
  53. rewardSum += ctmc.getStateRewardVector()[i];
  54. }
  55. ASSERT_EQ(263.32, rewardSum);
  56. ASSERT_TRUE(ctmc.hasTransitionRewards());
  57. ASSERT_EQ(17ul, ctmc.getTransitionRewardMatrix().getEntryCount());
  58. rewardSum = 0;
  59. for(uint_fast64_t i = 0; i < ctmc.getTransitionRewardMatrix().getRowCount(); i++) {
  60. rewardSum += ctmc.getTransitionRewardMatrix().getRowSum(i);
  61. }
  62. ASSERT_EQ(125.4, rewardSum);
  63. }
  64. TEST(DeterministicModelParserTest, MismatchedFiles) {
  65. // Test file combinations that do not match, i.e. differing number of states, transitions, etc.
  66. // The labeling file contains a label for a non existent state.
  67. ASSERT_THROW(storm::parser::DeterministicModelParser::parseDtmc(STORM_CPP_TESTS_BASE_PATH "/functional/parser/tra_files/dtmc_mismatched.tra", STORM_CPP_TESTS_BASE_PATH "/functional/parser/lab_files/dtmc_general.lab"), storm::exceptions::OutOfRangeException);
  68. // The state reward file contains a reward for a non existent state.
  69. ASSERT_THROW(storm::parser::DeterministicModelParser::parseDtmc(STORM_CPP_TESTS_BASE_PATH "/functional/parser/tra_files/dtmc_mismatched.tra", STORM_CPP_TESTS_BASE_PATH "/functional/parser/lab_files/dtmc_mismatched.lab", STORM_CPP_TESTS_BASE_PATH "/functional/parser/rew_files/dtmc_general.state.rew"), storm::exceptions::OutOfRangeException);
  70. // The transition reward file contains rewards for a non existent state.
  71. ASSERT_THROW(storm::parser::DeterministicModelParser::parseDtmc(STORM_CPP_TESTS_BASE_PATH "/functional/parser/tra_files/dtmc_mismatched.tra", STORM_CPP_TESTS_BASE_PATH "/functional/parser/lab_files/dtmc_mismatched.lab", "", STORM_CPP_TESTS_BASE_PATH "/functional/parser/rew_files/dtmc_general.trans.rew"), storm::exceptions::OutOfRangeException);
  72. // The transition reward file contains rewards for a non existent transition
  73. ASSERT_THROW(storm::parser::DeterministicModelParser::parseDtmc(STORM_CPP_TESTS_BASE_PATH "/functional/parser/tra_files/dtmc_mismatched.tra", STORM_CPP_TESTS_BASE_PATH "/functional/parser/lab_files/dtmc_mismatched.lab", "", STORM_CPP_TESTS_BASE_PATH "/functional/parser/rew_files/dtmc_mismatched.trans.rew"), storm::exceptions::OutOfRangeException);
  74. }