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.

64 lines
3.5 KiB

  1. #include "gtest/gtest.h"
  2. #include "storm-config.h"
  3. #include "src/parser/MarkovAutomatonParser.h"
  4. #include "src/models/sparse/StandardRewardModel.h"
  5. #include "src/exceptions/FileIoException.h"
  6. #include "src/exceptions/OutOfRangeException.h"
  7. TEST(MarkovAutomatonParserTest, NonExistingFile) {
  8. // No matter what happens, please do NOT create a file with the name "nonExistingFile.not"!
  9. ASSERT_THROW(storm::parser::MarkovAutomatonParser<>::parseMarkovAutomaton(STORM_CPP_TESTS_BASE_PATH "/nonExistingFile.not", STORM_CPP_TESTS_BASE_PATH "/nonExistingFile.not", STORM_CPP_TESTS_BASE_PATH "/nonExistingFile.not"), storm::exceptions::FileIoException);
  10. }
  11. TEST(MarkovAutomatonParserTest, BasicParsing) {
  12. // Get the parsing result.
  13. storm::models::sparse::MarkovAutomaton<double> result = storm::parser::MarkovAutomatonParser<>::parseMarkovAutomaton(STORM_CPP_TESTS_BASE_PATH "/functional/parser/tra_files/ma_general.tra", STORM_CPP_TESTS_BASE_PATH "/functional/parser/lab_files/ma_general.lab", STORM_CPP_TESTS_BASE_PATH "/functional/parser/rew_files/ma_general.state.rew");
  14. // Test sizes and counts.
  15. ASSERT_EQ(6ul, result.getNumberOfStates());
  16. ASSERT_EQ(7ul, result.getNumberOfChoices());
  17. ASSERT_EQ(12ul, result.getNumberOfTransitions());
  18. // Test the exit rates. These have to be 0 for all non-Markovian states.
  19. std::vector<double> rates = result.getExitRates();
  20. ASSERT_EQ(2, result.getExitRate(0));
  21. ASSERT_FALSE(result.isMarkovianState(1));
  22. ASSERT_EQ(0, result.getExitRate(1));
  23. ASSERT_EQ(15, result.getExitRate(2));
  24. ASSERT_FALSE(result.isMarkovianState(3));
  25. ASSERT_EQ(0, result.getExitRate(3));
  26. ASSERT_FALSE(result.isMarkovianState(4));
  27. ASSERT_EQ(0, result.getExitRate(4));
  28. ASSERT_FALSE(result.isMarkovianState(5));
  29. ASSERT_EQ(0, result.getExitRate(5));
  30. // Test the labeling.
  31. ASSERT_EQ(3ul, result.getStateLabeling().getNumberOfLabels());
  32. ASSERT_EQ(1ul, result.getInitialStates().getNumberOfSetBits());
  33. ASSERT_EQ(0ul, result.getLabelsOfState(4).size());
  34. ASSERT_EQ(1ul, result.getStateLabeling().getStates("goal").getNumberOfSetBits());
  35. // Test the state rewards.
  36. ASSERT_TRUE(result.hasRewardModel());
  37. double rewardSum = 0;
  38. for (uint_fast64_t i = 0; i < result.getRewardModel("").getStateRewardVector().size(); i++) {
  39. rewardSum += result.getRewardModel("").getStateRewardVector()[i];
  40. }
  41. ASSERT_EQ(1015.765099984, rewardSum);
  42. ASSERT_EQ(0, result.getRewardModel("").getStateRewardVector()[0]);
  43. // Test the transition rewards.
  44. ASSERT_FALSE(result.getRewardModel("").hasTransitionRewards());
  45. }
  46. TEST(MarkovAutomatonParserTest, MismatchedFiles) {
  47. // Test file combinations that do not match, i.e. differing number of states, transitions, etc.
  48. // The labeling file contains a label for a non existent state.
  49. ASSERT_THROW(storm::parser::MarkovAutomatonParser<>::parseMarkovAutomaton(STORM_CPP_TESTS_BASE_PATH "/functional/parser/tra_files/ma_general.tra", STORM_CPP_TESTS_BASE_PATH "/functional/parser/lab_files/ma_mismatched.lab"), storm::exceptions::OutOfRangeException);
  50. // The state reward file contains a reward for a non existent state.
  51. ASSERT_THROW(storm::parser::MarkovAutomatonParser<>::parseMarkovAutomaton(STORM_CPP_TESTS_BASE_PATH "/functional/parser/tra_files/ma_general.tra", STORM_CPP_TESTS_BASE_PATH "/functional/parser/lab_files/ma_general.lab", STORM_CPP_TESTS_BASE_PATH "/functional/parser/rew_files/ma_mismatched.state.rew"), storm::exceptions::OutOfRangeException);
  52. }