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

  1. #include "gtest/gtest.h"
  2. #include "storm-config.h"
  3. #include "src/parser/AutoParser.h"
  4. #include "src/exceptions/FileIoException.h"
  5. #include "src/exceptions/WrongFormatException.h"
  6. TEST(AutoParserTest, NonExistingFile) {
  7. // No matter what happens, please do NOT create a file with the name "nonExistingFile.not"!
  8. ASSERT_THROW(storm::parser::AutoParser::parseModel(STORM_CPP_TESTS_BASE_PATH "/nonExistingFile.not", STORM_CPP_TESTS_BASE_PATH "/nonExistingFile.not"), storm::exceptions::FileIoException);
  9. }
  10. TEST(AutoParserTest, BasicParsing) {
  11. // Parse model, which is a Dtmc.
  12. 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");
  13. // Test if parsed correctly.
  14. ASSERT_EQ(storm::models::ModelType::Dtmc, modelPtr->getType());
  15. ASSERT_EQ(12, modelPtr->getNumberOfStates());
  16. ASSERT_EQ(26, modelPtr->getNumberOfTransitions());
  17. ASSERT_EQ(1, modelPtr->getInitialStates().getNumberOfSetBits());
  18. ASSERT_TRUE(modelPtr->hasLabel("three"));
  19. ASSERT_FALSE(modelPtr->hasStateRewards());
  20. ASSERT_FALSE(modelPtr->hasTransitionRewards());
  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(12, modelPtr->getNumberOfStates());
  36. ASSERT_EQ(26, 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(12, modelPtr->getNumberOfStates());
  42. ASSERT_EQ(26, 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(12, modelPtr->getNumberOfStates());
  48. ASSERT_EQ(28, 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(12, modelPtr->getNumberOfStates());
  54. ASSERT_EQ(27, modelPtr->getNumberOfTransitions());
  55. }