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.

99 lines
4.2 KiB

  1. /*
  2. * ReadLabFileTest.cpp
  3. *
  4. * Created on: 12.09.2012
  5. * Author: Thomas Heinemann
  6. */
  7. #include "gtest/gtest.h"
  8. #include "storm-config.h"
  9. #include "src/models/AtomicPropositionsLabeling.h"
  10. #include "src/parser/AtomicPropositionLabelingParser.h"
  11. #include "src/exceptions/FileIoException.h"
  12. #include "src/exceptions/WrongFileFormatException.h"
  13. #include <memory>
  14. TEST(ReadLabFileTest, NonExistingFileTest) {
  15. //No matter what happens, please don't create a file with the name "nonExistingFile.not"! :-)
  16. ASSERT_THROW(storm::parser::AtomicPropositionLabelingParser(0,STORM_CPP_TESTS_BASE_PATH "/nonExistingFile.not"), storm::exceptions::FileIoException);
  17. }
  18. TEST(ReadLabFileTest, ParseTest) {
  19. //This test is based on a test case from the original MRMC.
  20. storm::parser::AtomicPropositionLabelingParser* parser = nullptr;
  21. //Parsing the file
  22. ASSERT_NO_THROW(parser = new storm::parser::AtomicPropositionLabelingParser(12, STORM_CPP_TESTS_BASE_PATH "/parser/lab_files/pctl_general_input_01.lab"));
  23. std::shared_ptr<storm::models::AtomicPropositionsLabeling> labeling(parser->getLabeling());
  24. //Checking whether all propositions are in the labelling
  25. char phi[] = "phi", psi[] = "psi", smth[] = "smth";
  26. if (labeling != nullptr) {
  27. ASSERT_TRUE(labeling->containsAtomicProposition(phi));
  28. ASSERT_TRUE(labeling->containsAtomicProposition(psi));
  29. ASSERT_TRUE(labeling->containsAtomicProposition(smth));
  30. //Testing whether all and only the correct nodes are labeled with "phi"
  31. ASSERT_TRUE(labeling->stateHasAtomicProposition(phi,1));
  32. ASSERT_TRUE(labeling->stateHasAtomicProposition(phi,2));
  33. ASSERT_TRUE(labeling->stateHasAtomicProposition(phi,3));
  34. ASSERT_TRUE(labeling->stateHasAtomicProposition(phi,5));
  35. ASSERT_TRUE(labeling->stateHasAtomicProposition(phi,7));
  36. ASSERT_TRUE(labeling->stateHasAtomicProposition(phi,9));
  37. ASSERT_TRUE(labeling->stateHasAtomicProposition(phi,10));
  38. ASSERT_TRUE(labeling->stateHasAtomicProposition(phi,11));
  39. ASSERT_FALSE(labeling->stateHasAtomicProposition(phi,4));
  40. ASSERT_FALSE(labeling->stateHasAtomicProposition(phi,6));
  41. //Testing whether all and only the correct nodes are labeled with "psi"
  42. ASSERT_TRUE(labeling->stateHasAtomicProposition(psi,6));
  43. ASSERT_TRUE(labeling->stateHasAtomicProposition(psi,7));
  44. ASSERT_TRUE(labeling->stateHasAtomicProposition(psi,8));
  45. ASSERT_FALSE(labeling->stateHasAtomicProposition(psi,1));
  46. ASSERT_FALSE(labeling->stateHasAtomicProposition(psi,2));
  47. ASSERT_FALSE(labeling->stateHasAtomicProposition(psi,3));
  48. ASSERT_FALSE(labeling->stateHasAtomicProposition(psi,4));
  49. ASSERT_FALSE(labeling->stateHasAtomicProposition(psi,5));
  50. ASSERT_FALSE(labeling->stateHasAtomicProposition(psi,9));
  51. ASSERT_FALSE(labeling->stateHasAtomicProposition(psi,10));
  52. ASSERT_FALSE(labeling->stateHasAtomicProposition(psi,11));
  53. //Testing whether all and only the correct nodes are labeled with "smth"
  54. ASSERT_TRUE(labeling->stateHasAtomicProposition(smth,4));
  55. ASSERT_TRUE(labeling->stateHasAtomicProposition(smth,5));
  56. ASSERT_FALSE(labeling->stateHasAtomicProposition(smth,1));
  57. ASSERT_FALSE(labeling->stateHasAtomicProposition(smth,2));
  58. ASSERT_FALSE(labeling->stateHasAtomicProposition(smth,3));
  59. ASSERT_FALSE(labeling->stateHasAtomicProposition(smth,6));
  60. ASSERT_FALSE(labeling->stateHasAtomicProposition(smth,7));
  61. ASSERT_FALSE(labeling->stateHasAtomicProposition(smth,8));
  62. ASSERT_FALSE(labeling->stateHasAtomicProposition(smth,9));
  63. ASSERT_FALSE(labeling->stateHasAtomicProposition(smth,10));
  64. ASSERT_FALSE(labeling->stateHasAtomicProposition(smth,11));
  65. //Deleting the labeling
  66. delete parser;
  67. } else {
  68. FAIL();
  69. }
  70. }
  71. TEST(ReadLabFileTest, WrongHeaderTest1) {
  72. ASSERT_THROW(storm::parser::AtomicPropositionLabelingParser(3, STORM_CPP_TESTS_BASE_PATH "/parser/lab_files/wrong_format_header1.lab"), storm::exceptions::WrongFileFormatException);
  73. }
  74. TEST(ReadLabFileTest, WrongHeaderTest2) {
  75. ASSERT_THROW(storm::parser::AtomicPropositionLabelingParser(3, STORM_CPP_TESTS_BASE_PATH "/parser/lab_files/wrong_format_header2.lab"), storm::exceptions::WrongFileFormatException);
  76. }
  77. TEST(ReadLabFileTest, WrongPropositionTest) {
  78. ASSERT_THROW(storm::parser::AtomicPropositionLabelingParser(3, STORM_CPP_TESTS_BASE_PATH "/parser/lab_files/wrong_format_proposition.lab"), storm::exceptions::WrongFileFormatException);
  79. }