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.

101 lines
5.4 KiB

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