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.

91 lines
5.3 KiB

  1. /*
  2. * AutoParserTest.cpp
  3. *
  4. * Created on: Feb 10, 2014
  5. * Author: Manuel Sascha Weiand
  6. */
  7. #include "gtest/gtest.h"
  8. #include "storm-config.h"
  9. #include "src/parser/AutoParser.h"
  10. #include "src/exceptions/FileIoException.h"
  11. #include "src/exceptions/WrongFormatException.h"
  12. TEST(AutoParserTest, NonExistingFile) {
  13. // No matter what happens, please do NOT create a file with the name "nonExistingFile.not"!
  14. ASSERT_THROW(storm::parser::AutoParser::parseModel(STORM_CPP_TESTS_BASE_PATH "/nonExistingFile.not", STORM_CPP_TESTS_BASE_PATH "/nonExistingFile.not"), storm::exceptions::FileIoException);
  15. }
  16. TEST(AutoParserTest, BasicParsing) {
  17. // Parse model, which is a Dtmc.
  18. std::shared_ptr<storm::models::AbstractModel<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");
  19. // Test if parsed correctly.
  20. ASSERT_EQ(storm::models::DTMC, modelPtr->getType());
  21. ASSERT_EQ(12, modelPtr->getNumberOfStates());
  22. ASSERT_EQ(26, modelPtr->getNumberOfTransitions());
  23. ASSERT_EQ(1, modelPtr->getInitialStates().getNumberOfSetBits());
  24. ASSERT_TRUE(modelPtr->hasAtomicProposition("three"));
  25. ASSERT_FALSE(modelPtr->hasStateRewards());
  26. ASSERT_FALSE(modelPtr->hasTransitionRewards());
  27. }
  28. TEST(AutoParserTest, Whitespaces) {
  29. // Test different whitespace combinations by comparing the hash of the model parsed from files without whitespaces with the hash of the models parsed from files with whitespaces.
  30. uint_fast64_t correctHash = 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")->getHash();
  31. ASSERT_EQ(correctHash, storm::parser::AutoParser::parseModel(STORM_CPP_TESTS_BASE_PATH "/functional/parser/tra_files/autoParser/dtmcWhitespaces1.tra", STORM_CPP_TESTS_BASE_PATH "/functional/parser/lab_files/autoParser.lab")->getHash());
  32. ASSERT_EQ(correctHash, storm::parser::AutoParser::parseModel(STORM_CPP_TESTS_BASE_PATH "/functional/parser/tra_files/autoParser/dtmcWhitespaces2.tra", STORM_CPP_TESTS_BASE_PATH "/functional/parser/lab_files/autoParser.lab")->getHash());
  33. }
  34. TEST(AutoParserTest, WrongHint) {
  35. // The hint given describes the content but does not conform to the format.
  36. 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);
  37. }
  38. TEST(AutoParserTest, NoHint) {
  39. // There is no hint contained in the given file, so the parser cannot decide which kind of model it is.
  40. 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);
  41. }
  42. TEST(AutoParserTest, Decision) {
  43. // Test if the AutoParser recognizes each model kind and correctly parses it.
  44. // Dtmc
  45. std::shared_ptr<storm::models::AbstractModel<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");
  46. ASSERT_EQ(storm::models::DTMC, modelPtr->getType());
  47. ASSERT_EQ(12, modelPtr->getNumberOfStates());
  48. ASSERT_EQ(26, modelPtr->getNumberOfTransitions());
  49. // Ctmc
  50. modelPtr.reset();
  51. 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");
  52. ASSERT_EQ(storm::models::CTMC, modelPtr->getType());
  53. ASSERT_EQ(12, modelPtr->getNumberOfStates());
  54. ASSERT_EQ(26, modelPtr->getNumberOfTransitions());
  55. // Mdp
  56. modelPtr.reset();
  57. 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");
  58. ASSERT_EQ(storm::models::MDP, modelPtr->getType());
  59. ASSERT_EQ(12, modelPtr->getNumberOfStates());
  60. ASSERT_EQ(28, modelPtr->getNumberOfTransitions());
  61. // Ctmdp
  62. // Note: For now we use the Mdp from above just given the ctmdp hint, since the implementation of the Ctmdp model seems not Quite right yet.
  63. // We still do this test so that the code responsible for Ctmdps is executed at least once during testing.
  64. // TODO: Fix the Ctmdp implementation and use an actual Ctmdp for testing.
  65. modelPtr.reset();
  66. modelPtr = storm::parser::AutoParser::parseModel(STORM_CPP_TESTS_BASE_PATH "/functional/parser/tra_files/autoParser/ctmdp.tra", STORM_CPP_TESTS_BASE_PATH "/functional/parser/lab_files/autoParser.lab");
  67. ASSERT_EQ(storm::models::CTMDP, modelPtr->getType());
  68. ASSERT_EQ(12, modelPtr->getNumberOfStates());
  69. ASSERT_EQ(28, modelPtr->getNumberOfTransitions());
  70. // MA
  71. modelPtr.reset();
  72. 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");
  73. ASSERT_EQ(storm::models::MA, modelPtr->getType());
  74. ASSERT_EQ(12, modelPtr->getNumberOfStates());
  75. ASSERT_EQ(27, modelPtr->getNumberOfTransitions());
  76. }