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.

66 lines
3.8 KiB

  1. #include "gtest/gtest.h"
  2. #include "storm-config.h"
  3. #include "src/models/sparse/StandardRewardModel.h"
  4. #include "src/parser/AutoParser.h"
  5. #include "src/exceptions/FileIoException.h"
  6. #include "src/exceptions/WrongFormatException.h"
  7. TEST(AutoParserTest, NonExistingFile) {
  8. // No matter what happens, please do NOT create a file with the name "nonExistingFile.not"!
  9. ASSERT_THROW(storm::parser::AutoParser<>::parseModel(STORM_CPP_TESTS_BASE_PATH "/nonExistingFile.not", STORM_CPP_TESTS_BASE_PATH "/nonExistingFile.not"), storm::exceptions::FileIoException);
  10. }
  11. TEST(AutoParserTest, BasicParsing) {
  12. // Parse model, which is a Dtmc.
  13. std::shared_ptr<storm::models::sparse::Model<double>> modelPtr = storm::parser::AutoParser<>::parseModel(STORM_CPP_TESTS_BASE_PATH "/functional/parser/tra_files/autoParser/dtmc.tra", STORM_CPP_TESTS_BASE_PATH "/functional/parser/lab_files/autoParser.lab");
  14. // Test if parsed correctly.
  15. ASSERT_EQ(storm::models::ModelType::Dtmc, modelPtr->getType());
  16. ASSERT_EQ(12ul, modelPtr->getNumberOfStates());
  17. ASSERT_EQ(26ul, modelPtr->getNumberOfTransitions());
  18. ASSERT_EQ(1ul, modelPtr->getInitialStates().getNumberOfSetBits());
  19. ASSERT_TRUE(modelPtr->hasLabel("three"));
  20. ASSERT_FALSE(modelPtr->hasRewardModel());
  21. }
  22. TEST(AutoParserTest, WrongHint) {
  23. // The hint given describes the content but does not conform to the format.
  24. ASSERT_THROW(storm::parser::AutoParser<>::parseModel(STORM_CPP_TESTS_BASE_PATH "/functional/parser/tra_files/autoParser/wrongHint.tra", STORM_CPP_TESTS_BASE_PATH "/functional/parser/lab_files/autoParser.lab"), storm::exceptions::WrongFormatException);
  25. }
  26. TEST(AutoParserTest, NoHint) {
  27. // There is no hint contained in the given file, so the parser cannot decide which kind of model it is.
  28. ASSERT_THROW(storm::parser::AutoParser<>::parseModel(STORM_CPP_TESTS_BASE_PATH "/functional/parser/tra_files/autoParser/noHint.tra", STORM_CPP_TESTS_BASE_PATH "/functional/parser/lab_files/autoParser.lab"), storm::exceptions::WrongFormatException);
  29. }
  30. TEST(AutoParserTest, Decision) {
  31. // Test if the AutoParser recognizes each model kind and correctly parses it.
  32. // Dtmc
  33. std::shared_ptr<storm::models::sparse::Model<double>> modelPtr = storm::parser::AutoParser<>::parseModel(STORM_CPP_TESTS_BASE_PATH "/functional/parser/tra_files/autoParser/dtmc.tra", STORM_CPP_TESTS_BASE_PATH "/functional/parser/lab_files/autoParser.lab");
  34. ASSERT_EQ(storm::models::ModelType::Dtmc, modelPtr->getType());
  35. ASSERT_EQ(12ul, modelPtr->getNumberOfStates());
  36. ASSERT_EQ(26ul, modelPtr->getNumberOfTransitions());
  37. // Ctmc
  38. modelPtr.reset();
  39. modelPtr = storm::parser::AutoParser<>::parseModel(STORM_CPP_TESTS_BASE_PATH "/functional/parser/tra_files/autoParser/ctmc.tra", STORM_CPP_TESTS_BASE_PATH "/functional/parser/lab_files/autoParser.lab");
  40. ASSERT_EQ(storm::models::ModelType::Ctmc, modelPtr->getType());
  41. ASSERT_EQ(12ul, modelPtr->getNumberOfStates());
  42. ASSERT_EQ(26ul, modelPtr->getNumberOfTransitions());
  43. // Mdp
  44. modelPtr.reset();
  45. modelPtr = storm::parser::AutoParser<>::parseModel(STORM_CPP_TESTS_BASE_PATH "/functional/parser/tra_files/autoParser/mdp.tra", STORM_CPP_TESTS_BASE_PATH "/functional/parser/lab_files/autoParser.lab");
  46. ASSERT_EQ(storm::models::ModelType::Mdp, modelPtr->getType());
  47. ASSERT_EQ(12ul, modelPtr->getNumberOfStates());
  48. ASSERT_EQ(28ul, modelPtr->getNumberOfTransitions());
  49. // MA
  50. modelPtr.reset();
  51. modelPtr = storm::parser::AutoParser<>::parseModel(STORM_CPP_TESTS_BASE_PATH "/functional/parser/tra_files/autoParser/ma.tra", STORM_CPP_TESTS_BASE_PATH "/functional/parser/lab_files/autoParser.lab");
  52. ASSERT_EQ(storm::models::ModelType::MarkovAutomaton, modelPtr->getType());
  53. ASSERT_EQ(12ul, modelPtr->getNumberOfStates());
  54. ASSERT_EQ(27ul, modelPtr->getNumberOfTransitions());
  55. }