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.

89 lines
3.1 KiB

12 years ago
  1. /*
  2. * read_tra_file_test.cpp
  3. *
  4. * Created on: 16.08.2012
  5. * Author: Thomas Heinemann
  6. */
  7. #include "gtest/gtest.h"
  8. #include "MRMCConfig.h"
  9. #include "src/sparse/static_sparse_matrix.h"
  10. #include "src/parser/read_tra_file.h"
  11. #include "src/exceptions/file_IO_exception.h"
  12. #include "src/exceptions/wrong_file_format.h"
  13. #include <pantheios/pantheios.hpp>
  14. TEST(ReadTraFileTest, NonExistingFileTest) {
  15. pantheios::log_INFORMATIONAL("Started NonExistingFileTest");
  16. //No matter what happens, please don't create a file with the name "nonExistingFile.not"! :-)
  17. ASSERT_THROW(mrmc::parser::read_tra_file(MRMC_CPP_TESTS_BASE_PATH "/nonExistingFile.not"), mrmc::exceptions::file_IO_exception);
  18. }
  19. /* The following test case is based on one of the original MRMC test cases
  20. */
  21. TEST(ReadTraFileTest, ParseFileTest1) {
  22. pantheios::log_INFORMATIONAL("Started ParseFileTest1");
  23. mrmc::sparse::StaticSparseMatrix<double> *result = NULL;
  24. ASSERT_NO_THROW(result = mrmc::parser::read_tra_file(MRMC_CPP_TESTS_BASE_PATH "/parser/tra_files/csl_general_input_01.tra"));
  25. if (result != NULL) {
  26. double val = 0;
  27. ASSERT_TRUE(result->getValue(1,1,&val));
  28. ASSERT_EQ(val,0.080645161290322580645161290322581);
  29. ASSERT_TRUE(result->getValue(1,2,&val));
  30. ASSERT_EQ(val,0.080645161290322580645161290322581);
  31. //Transition 1->3 was not set in the file, so it is not to appear in the matrix!
  32. ASSERT_FALSE(result->getValue(1,3,&val));
  33. ASSERT_EQ(val,0);
  34. ASSERT_TRUE(result->getValue(2,1,&val));
  35. ASSERT_EQ(val,0.04032258064516129032258064516129);
  36. ASSERT_TRUE(result->getValue(2,2,&val));
  37. ASSERT_EQ(val,0.04032258064516129032258064516129);
  38. ASSERT_TRUE(result->getValue(2,3,&val));
  39. ASSERT_EQ(val,0.04032258064516129032258064516129);
  40. ASSERT_TRUE(result->getValue(2,4,&val));
  41. ASSERT_EQ(val,0.04032258064516129032258064516129);
  42. ASSERT_TRUE(result->getValue(3,2,&val));
  43. ASSERT_EQ(val,0.0806451612903225806451612903225812);
  44. ASSERT_TRUE(result->getValue(3,3,&val));
  45. ASSERT_EQ(val,0);
  46. ASSERT_TRUE(result->getValue(3,4,&val));
  47. ASSERT_EQ(val,0.080645161290322580645161290322581);
  48. ASSERT_TRUE(result->getValue(4,4,&val));
  49. ASSERT_EQ(val,0);
  50. // FIXME: adapt this test case to the new dot-output routines
  51. /* result->toDOTFile("output.dot"); */
  52. delete result;
  53. } else {
  54. FAIL();
  55. }
  56. }
  57. TEST(ReadTraFileTest, WrongFormatTestHeader1) {
  58. pantheios::log_INFORMATIONAL("Started WrongFormatTestHeader1");
  59. ASSERT_THROW(mrmc::parser::read_tra_file(MRMC_CPP_TESTS_BASE_PATH "/parser/tra_files/wrong_format_header1.tra"), mrmc::exceptions::wrong_file_format);
  60. }
  61. TEST(ReadTraFileTest, WrongFormatTestHeader2) {
  62. pantheios::log_INFORMATIONAL("Started WrongFormatTestHeader2");
  63. ASSERT_THROW(mrmc::parser::read_tra_file(MRMC_CPP_TESTS_BASE_PATH "/parser/tra_files/wrong_format_header2.tra"), mrmc::exceptions::wrong_file_format);
  64. }
  65. TEST(ReadTraFileTest, WrongFormatTestTransition) {
  66. pantheios::log_INFORMATIONAL("Started WrongFormatTestTransition");
  67. ASSERT_THROW(mrmc::parser::read_tra_file(MRMC_CPP_TESTS_BASE_PATH "/parser/tra_files/wrong_format_transition.tra"), mrmc::exceptions::wrong_file_format);
  68. }