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.

145 lines
7.8 KiB

  1. /*
  2. * AtomicPropositionLabelingParserTest.cpp
  3. *
  4. * Created on: 03.03.2014
  5. * Author: Manuel Sascha Weiand
  6. */
  7. #include "gtest/gtest.h"
  8. #include "storm-config.h"
  9. #include "src/models/sparse/StateLabeling.h"
  10. #include "src/parser/AtomicPropositionLabelingParser.h"
  11. #include "src/exceptions/FileIoException.h"
  12. #include "src/exceptions/WrongFormatException.h"
  13. #include "src/exceptions/OutOfRangeException.h"
  14. #include <memory>
  15. TEST(AtomicPropositionLabelingParserTest, NonExistingFile) {
  16. // No matter what happens, please do NOT create a file with the name "nonExistingFile.not"!
  17. ASSERT_THROW(storm::parser::AtomicPropositionLabelingParser::parseAtomicPropositionLabeling(0,STORM_CPP_TESTS_BASE_PATH "/nonExistingFile.not"), storm::exceptions::FileIoException);
  18. }
  19. TEST(AtomicPropositionLabelingParserTest, BasicParsing) {
  20. // This test is based on a test case from the original MRMC.
  21. // Parsing the file
  22. storm::models::sparse::StateLabeling labeling = storm::parser::AtomicPropositionLabelingParser::parseAtomicPropositionLabeling(12, STORM_CPP_TESTS_BASE_PATH "/functional/parser/lab_files/pctl_general.lab");
  23. // Checking whether all propositions are in the labelling
  24. char phi[] = "phi", psi[] = "psi", smth[] = "smth";
  25. ASSERT_TRUE(labeling.containsLabel(phi));
  26. ASSERT_TRUE(labeling.containsLabel(psi));
  27. ASSERT_TRUE(labeling.containsLabel(smth));
  28. // Testing whether all and only the correct nodes are labeled with "phi"
  29. ASSERT_TRUE(labeling.getStateHasLabel(phi,0));
  30. ASSERT_TRUE(labeling.getStateHasLabel(phi,1));
  31. ASSERT_TRUE(labeling.getStateHasLabel(phi,2));
  32. ASSERT_FALSE(labeling.getStateHasLabel(phi,3));
  33. ASSERT_FALSE(labeling.getStateHasLabel(phi,4));
  34. ASSERT_FALSE(labeling.getStateHasLabel(phi,5));
  35. ASSERT_FALSE(labeling.getStateHasLabel(phi,6));
  36. ASSERT_FALSE(labeling.getStateHasLabel(phi,7));
  37. ASSERT_FALSE(labeling.getStateHasLabel(phi,8));
  38. ASSERT_FALSE(labeling.getStateHasLabel(phi,9));
  39. ASSERT_FALSE(labeling.getStateHasLabel(phi,10));
  40. ASSERT_FALSE(labeling.getStateHasLabel(phi,11));
  41. //Testing whether all and only the correct nodes are labeled with "psi"
  42. ASSERT_FALSE(labeling.getStateHasLabel(psi,0));
  43. ASSERT_FALSE(labeling.getStateHasLabel(psi,1));
  44. ASSERT_FALSE(labeling.getStateHasLabel(psi,2));
  45. ASSERT_FALSE(labeling.getStateHasLabel(psi,3));
  46. ASSERT_FALSE(labeling.getStateHasLabel(psi,4));
  47. ASSERT_FALSE(labeling.getStateHasLabel(psi,5));
  48. ASSERT_FALSE(labeling.getStateHasLabel(psi,6));
  49. ASSERT_FALSE(labeling.getStateHasLabel(psi,7));
  50. ASSERT_FALSE(labeling.getStateHasLabel(psi,8));
  51. ASSERT_FALSE(labeling.getStateHasLabel(psi,9));
  52. ASSERT_FALSE(labeling.getStateHasLabel(psi,10));
  53. ASSERT_FALSE(labeling.getStateHasLabel(psi,11));
  54. //Testing whether all and only the correct nodes are labeled with "smth"
  55. ASSERT_TRUE(labeling.getStateHasLabel(smth,2));
  56. ASSERT_FALSE(labeling.getStateHasLabel(smth,0));
  57. ASSERT_FALSE(labeling.getStateHasLabel(smth,1));
  58. ASSERT_FALSE(labeling.getStateHasLabel(smth,3));
  59. ASSERT_FALSE(labeling.getStateHasLabel(smth,4));
  60. ASSERT_FALSE(labeling.getStateHasLabel(smth,5));
  61. ASSERT_FALSE(labeling.getStateHasLabel(smth,6));
  62. ASSERT_FALSE(labeling.getStateHasLabel(smth,7));
  63. ASSERT_FALSE(labeling.getStateHasLabel(smth,8));
  64. ASSERT_FALSE(labeling.getStateHasLabel(smth,9));
  65. ASSERT_FALSE(labeling.getStateHasLabel(smth,10));
  66. ASSERT_FALSE(labeling.getStateHasLabel(smth,11));
  67. }
  68. TEST(AtomicPropositionLabelingParserTest, NoDeclarationTagHeader) {
  69. // No #DECLARATION tag in file
  70. ASSERT_THROW(storm::parser::AtomicPropositionLabelingParser::parseAtomicPropositionLabeling(3, STORM_CPP_TESTS_BASE_PATH "/functional/parser/lab_files/labParser/noDeclarationTag.lab"), storm::exceptions::WrongFormatException);
  71. }
  72. TEST(AtomicPropositionLabelingParserTest, NoEndTagHeader) {
  73. // No #END tag in file.
  74. ASSERT_THROW(storm::parser::AtomicPropositionLabelingParser::parseAtomicPropositionLabeling(3, STORM_CPP_TESTS_BASE_PATH "/functional/parser/lab_files/labParser/noEndTag.lab"), storm::exceptions::WrongFormatException);
  75. }
  76. TEST(AtomicPropositionLabelingParserTest, MisspelledDeclarationTagHeader) {
  77. // The #DECLARATION tag is misspelled.
  78. ASSERT_THROW(storm::parser::AtomicPropositionLabelingParser::parseAtomicPropositionLabeling(3, STORM_CPP_TESTS_BASE_PATH "/functional/parser/lab_files/labParser/declarationMisspell.lab"), storm::exceptions::WrongFormatException);
  79. }
  80. TEST(AtomicPropositionLabelingParserTest, MisspelledEndTagHeader) {
  81. // The #END tag is misspelled.
  82. ASSERT_THROW(storm::parser::AtomicPropositionLabelingParser::parseAtomicPropositionLabeling(3, STORM_CPP_TESTS_BASE_PATH "/functional/parser/lab_files/labParser/endMisspell.lab"), storm::exceptions::WrongFormatException);
  83. }
  84. TEST(AtomicPropositionLabelingParserTest, NoLabelDeclaredNoneGiven) {
  85. // No label between #DECLARATION and #END and no labels given.
  86. storm::models::sparse::StateLabeling labeling = storm::parser::AtomicPropositionLabelingParser::parseAtomicPropositionLabeling(13, STORM_CPP_TESTS_BASE_PATH "/functional/parser/lab_files/labParser/noLabelsDecNoneGiven.lab");
  87. ASSERT_EQ(0ul, labeling.getNumberOfLabels());
  88. for(uint_fast64_t i = 0; i < 13; i++) {
  89. ASSERT_TRUE(labeling.getLabelsOfState(i).empty());
  90. }
  91. }
  92. TEST(AtomicPropositionLabelingParserTest, UndeclaredLabelsGiven) {
  93. // Undeclared labels given.
  94. ASSERT_THROW(storm::parser::AtomicPropositionLabelingParser::parseAtomicPropositionLabeling(3, STORM_CPP_TESTS_BASE_PATH "/functional/parser/lab_files/labParser/undeclaredLabelsGiven.lab"), storm::exceptions::WrongFormatException);
  95. }
  96. TEST(AtomicPropositionLabelingParserTest, LabelForNonExistentState) {
  97. // The index of one of the state that are to be labeled is higher than the number of states in the model.
  98. ASSERT_THROW(storm::parser::AtomicPropositionLabelingParser::parseAtomicPropositionLabeling(3, STORM_CPP_TESTS_BASE_PATH "/functional/parser/lab_files/labParser/labelForNonexistentState.lab"), storm::exceptions::OutOfRangeException);
  99. }
  100. // Note: As implemented at the moment, each label given for a state in any line is set to true for that state (logical or over all lines for that state).
  101. // This behavior might not be ideal as multiple lines for one state are not necessary and might indicate a corrupt or wrong file.
  102. TEST(AtomicPropositionLabelingParserTest, DoubledLines) {
  103. // There are multiple lines attributing labels to the same state.
  104. ASSERT_THROW(storm::parser::AtomicPropositionLabelingParser::parseAtomicPropositionLabeling(6, STORM_CPP_TESTS_BASE_PATH "/functional/parser/lab_files/labParser/doubledLines.lab"), storm::exceptions::WrongFormatException);
  105. // There is a line for a state that has been skipped.
  106. ASSERT_THROW(storm::parser::AtomicPropositionLabelingParser::parseAtomicPropositionLabeling(6, STORM_CPP_TESTS_BASE_PATH "/functional/parser/lab_files/labParser/doubledLinesSkipped.lab"), storm::exceptions::WrongFormatException);
  107. }
  108. TEST(AtomicPropositionLabelingParserTest, WrongProposition) {
  109. // Swapped the state index and the label at one entry.
  110. ASSERT_THROW(storm::parser::AtomicPropositionLabelingParser::parseAtomicPropositionLabeling(3, STORM_CPP_TESTS_BASE_PATH "/functional/parser/lab_files/labParser/swappedStateAndProposition.lab"), storm::exceptions::WrongFormatException);
  111. }
  112. TEST(AtomicPropositionLabelingParserTest, Whitespaces) {
  113. // Different configurations of allowed whitespaces are tested.
  114. // First parse the labeling file without added whitespaces and obtain the hash of its parsed representation.
  115. storm::models::sparse::StateLabeling labeling = storm::parser::AtomicPropositionLabelingParser::parseAtomicPropositionLabeling(13, STORM_CPP_TESTS_BASE_PATH "/functional/parser/lab_files/labParser/withoutWhitespaces.lab");
  116. // Now parse the labeling file with the added whitespaces and compare the hashes.
  117. storm::models::sparse::StateLabeling labeling2 = storm::parser::AtomicPropositionLabelingParser::parseAtomicPropositionLabeling(13, STORM_CPP_TESTS_BASE_PATH "/functional/parser/lab_files/labParser/withWhitespaces.lab");
  118. ASSERT_TRUE(labeling == labeling2);
  119. }