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.

87 lines
3.1 KiB

12 years ago
  1. /*
  2. * ReadTraFileTest.cpp
  3. *
  4. * Created on: 16.08.2012
  5. * Author: Thomas Heinemann
  6. */
  7. #include "gtest/gtest.h"
  8. #include "storm-config.h"
  9. #include "src/storage/SparseMatrix.h"
  10. #include "src/parser/DeterministicSparseTransitionParser.h"
  11. #include "src/exceptions/FileIoException.h"
  12. #include "src/exceptions/WrongFileFormatException.h"
  13. #include "src/utility/IoUtility.h"
  14. TEST(ReadTraFileTest, NonExistingFileTest) {
  15. //No matter what happens, please don't create a file with the name "nonExistingFile.not"! :-)
  16. ASSERT_THROW(storm::parser::DeterministicSparseTransitionParser(STORM_CPP_TESTS_BASE_PATH "/nonExistingFile.not"), storm::exceptions::FileIoException);
  17. }
  18. /* The following test case is based on one of the original STORM test cases
  19. */
  20. TEST(ReadTraFileTest, ParseFileTest1) {
  21. storm::parser::DeterministicSparseTransitionParser* parser = nullptr;
  22. ASSERT_NO_THROW(parser = new storm::parser::DeterministicSparseTransitionParser(STORM_CPP_TESTS_BASE_PATH "/parser/tra_files/csl_general_input_01.tra"));
  23. std::shared_ptr<storm::storage::SparseMatrix<double>> result = parser->getMatrix();
  24. if (result != nullptr) {
  25. double val = 0;
  26. ASSERT_TRUE(result->getValue(0, 0, &val));
  27. ASSERT_EQ(val, 0.0);
  28. ASSERT_TRUE(result->getValue(0, 1, &val));
  29. ASSERT_EQ(val, 1.0);
  30. ASSERT_TRUE(result->getValue(1, 1, &val));
  31. ASSERT_EQ(val, 0.080645161290322580645161290322581);
  32. ASSERT_TRUE(result->getValue(1, 2, &val));
  33. ASSERT_EQ(val, 0.080645161290322580645161290322581);
  34. //Transition 1->3 was not set in the file, so it is not to appear in the matrix!
  35. ASSERT_FALSE(result->getValue(1, 3, &val));
  36. ASSERT_EQ(val, 0);
  37. ASSERT_TRUE(result->getValue(2, 1, &val));
  38. ASSERT_EQ(val, 0.04032258064516129032258064516129);
  39. ASSERT_TRUE(result->getValue(2, 2, &val));
  40. ASSERT_EQ(val, 0.04032258064516129032258064516129);
  41. ASSERT_TRUE(result->getValue(2, 3, &val));
  42. ASSERT_EQ(val, 0.04032258064516129032258064516129);
  43. ASSERT_TRUE(result->getValue(2, 4, &val));
  44. ASSERT_EQ(val, 0.04032258064516129032258064516129);
  45. ASSERT_TRUE(result->getValue(3, 2, &val));
  46. ASSERT_EQ(val, 0.0806451612903225806451612903225812);
  47. ASSERT_TRUE(result->getValue(3, 3, &val));
  48. ASSERT_EQ(val, 0.0);
  49. ASSERT_TRUE(result->getValue(3, 4, &val));
  50. ASSERT_EQ(val, 0.080645161290322580645161290322581);
  51. ASSERT_TRUE(result->getValue(4, 4, &val));
  52. ASSERT_EQ(val, 0.0);
  53. delete parser;
  54. } else {
  55. FAIL();
  56. }
  57. }
  58. TEST(ReadTraFileTest, WrongFormatTestHeader1) {
  59. ASSERT_THROW(storm::parser::DeterministicSparseTransitionParser(STORM_CPP_TESTS_BASE_PATH "/parser/tra_files/wrong_format_header1.tra"), storm::exceptions::WrongFileFormatException);
  60. }
  61. TEST(ReadTraFileTest, WrongFormatTestHeader2) {
  62. ASSERT_THROW(storm::parser::DeterministicSparseTransitionParser(STORM_CPP_TESTS_BASE_PATH "/parser/tra_files/wrong_format_header2.tra"), storm::exceptions::WrongFileFormatException);
  63. }
  64. TEST(ReadTraFileTest, WrongFormatTestTransition) {
  65. ASSERT_THROW(storm::parser::DeterministicSparseTransitionParser(STORM_CPP_TESTS_BASE_PATH "/parser/tra_files/wrong_format_transition.tra"), storm::exceptions::WrongFileFormatException);
  66. }