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.

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