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.

74 lines
2.5 KiB

  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 "src/sparse/static_sparse_matrix.h"
  9. #include "src/parser/read_tra_file.h"
  10. #include "src/exceptions/file_IO_exception.h"
  11. #include "src/exceptions/wrong_file_format.h"
  12. #include <pantheios/pantheios.hpp>
  13. TEST(ReadTraFileTest, NonExistingFileTest) {
  14. pantheios::log_INFORMATIONAL("Started NonExistingFileTest");
  15. //No matter what happens, please don't create a file with the name "nonExistingFile.not"! :-)
  16. ASSERT_THROW(mrmc::parser::read_tra_file("nonExistingFile.not"), mrmc::exceptions::file_IO_exception);
  17. }
  18. /* The following test case is based on one of the original MRMC test cases
  19. */
  20. TEST(ReadTraFileTest, ParseFileTest1) {
  21. pantheios::log_INFORMATIONAL("Started ParseFileTest1");
  22. mrmc::sparse::StaticSparseMatrix<double> *result;
  23. ASSERT_NO_THROW(result = mrmc::parser::read_tra_file("test/parser/csl_general_input_01.tra"));
  24. double val = 0;
  25. ASSERT_TRUE(result->getValue(1,1,&val));
  26. ASSERT_EQ(val,0.080645161290322580645161290322581);
  27. ASSERT_TRUE(result->getValue(1,2,&val));
  28. ASSERT_EQ(val,0.080645161290322580645161290322581);
  29. //Transition 1->3 was not set in the file, so it is not to appear in the matrix!
  30. ASSERT_FALSE(result->getValue(1,3,&val));
  31. ASSERT_EQ(val,0);
  32. ASSERT_TRUE(result->getValue(2,1,&val));
  33. ASSERT_EQ(val,0.04032258064516129032258064516129);
  34. ASSERT_TRUE(result->getValue(2,2,&val));
  35. ASSERT_EQ(val,0.04032258064516129032258064516129);
  36. ASSERT_TRUE(result->getValue(2,3,&val));
  37. ASSERT_EQ(val,0.04032258064516129032258064516129);
  38. ASSERT_TRUE(result->getValue(2,4,&val));
  39. ASSERT_EQ(val,0.04032258064516129032258064516129);
  40. ASSERT_TRUE(result->getValue(3,2,&val));
  41. ASSERT_EQ(val,0.0806451612903225806451612903225812);
  42. ASSERT_TRUE(result->getValue(3,3,&val));
  43. ASSERT_EQ(val,0);
  44. ASSERT_TRUE(result->getValue(3,4,&val));
  45. ASSERT_EQ(val,0.080645161290322580645161290322581);
  46. ASSERT_TRUE(result->getValue(4,4,&val));
  47. ASSERT_EQ(val,0);
  48. }
  49. TEST(ReadTraFileTest, WrongFormatTestHeader) {
  50. pantheios::log_INFORMATIONAL("Started WrongFormatTestHeader");
  51. ASSERT_THROW(mrmc::parser::read_tra_file("test/parser/wrong_format_header.tra"), mrmc::exceptions::wrong_file_format);
  52. }
  53. TEST(ReadTraFileTest, WrongFormatTestTransition) {
  54. pantheios::log_INFORMATIONAL("Started WrongFormatTestTransition");
  55. ASSERT_THROW(mrmc::parser::read_tra_file("test/parser/wrong_format_transition.tra"), mrmc::exceptions::wrong_file_format);
  56. }