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.2 KiB

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