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.

49 lines
1.6 KiB

  1. /*
  2. * SparseStateRewardParserTest.cpp
  3. *
  4. * Created on: 26.02.2014
  5. * Author: Manuel Sascha Weiand
  6. */
  7. #include "gtest/gtest.h"
  8. #include "storm-config.h"
  9. #include <cmath>
  10. #include "src/parser/SparseStateRewardParser.h"
  11. TEST(SparseStateRewardParserTest, NonExistingFile) {
  12. // No matter what happens, please do NOT create a file with the name "nonExistingFile.not"!
  13. ASSERT_THROW(storm::parser::SparseStateRewardParser::parseSparseStateReward(42, STORM_CPP_TESTS_BASE_PATH "/nonExistingFile.not"), storm::exceptions::FileIoException);
  14. }
  15. double round(double val, int precision)
  16. {
  17. std::stringstream s;
  18. s << std::setprecision(precision) << std::setiosflags(std::ios_base::fixed) << val;
  19. s >> val;
  20. return val;
  21. }
  22. TEST(SparseStateRewardParserTest, BasicParsing) {
  23. // Get the parsing result.
  24. std::vector<double> result = storm::parser::SparseStateRewardParser::parseSparseStateReward(100, STORM_CPP_TESTS_BASE_PATH "/functional/parser/rew_files/state_reward_parser_basic.state.rew");
  25. // Now test if the correct value were parsed.
  26. for(int i = 0; i < 100; i++) {
  27. ASSERT_EQ(std::round(result[i]) , std::round(2*i + 15/13*i*i - 1.5/(i+0.1) + 15.7));
  28. }
  29. }
  30. TEST(SparseStateRewardParserTest, Whitespaces) {
  31. // Get the parsing result.
  32. std::vector<double> result = storm::parser::SparseStateRewardParser::parseSparseStateReward(100, STORM_CPP_TESTS_BASE_PATH "/functional/parser/rew_files/state_reward_parser_whitespaces.state.rew");
  33. // Now test if the correct value were parsed.
  34. for(int i = 0; i < 100; i++) {
  35. ASSERT_EQ(std::round(result[i]) , std::round(2*i + 15/13*i*i - 1.5/(i+0.1) + 15.7));
  36. }
  37. }