Storm 1.11.1.1
A Modern Probabilistic Model Checker
Loading...
Searching...
No Matches
SparseStateRewardParserTest.cpp
Go to the documentation of this file.
1#include "storm-config.h"
2#include "test/storm_gtest.h"
3
4#include <cmath>
5
10
11TEST(SparseStateRewardParserTest, NonExistingFile) {
12 // No matter what happens, please do NOT create a file with the name "nonExistingFile.not"!
14 storm::exceptions::FileIoException);
15}
16
17double round(double val, int precision) {
18 std::stringstream s;
19 s << std::setprecision(precision) << std::setiosflags(std::ios_base::fixed) << val;
20 s >> val;
21 return val;
22}
23
24TEST(SparseStateRewardParserTest, BasicParsing) {
25 // Get the parsing result.
26 std::vector<double> result =
27 storm::parser::SparseStateRewardParser<>::parseSparseStateReward(100, STORM_TEST_RESOURCES_DIR "/rew/state_reward_parser_basic.state.rew");
28
29 // Now test if the correct value were parsed.
30 for (int i = 0; i < 100; i++) {
31 ASSERT_EQ(std::round(2 * i + 15 / 13 * i * i - 1.5 / (i + 0.1) + 15.7), std::round(result[i]));
32 }
33}
34
35TEST(SparseStateRewardParserTest, Whitespaces) {
36 // Get the parsing result.
37 std::vector<double> result =
38 storm::parser::SparseStateRewardParser<>::parseSparseStateReward(100, STORM_TEST_RESOURCES_DIR "/rew/state_reward_parser_whitespaces.state.rew");
39
40 // Now test if the correct value were parsed.
41 for (int i = 0; i < 100; i++) {
42 ASSERT_EQ(std::round(2 * i + 15 / 13 * i * i - 1.5 / (i + 0.1) + 15.7), std::round(result[i]));
43 }
44}
45
46TEST(SparseStateRewardParserTest, DoubledLines) {
47 // There are multiple lines attributing a reward to the same state.
49 storm::parser::SparseStateRewardParser<>::parseSparseStateReward(11, STORM_TEST_RESOURCES_DIR "/rew/state_reward_parser_doubledLines.state.rew"),
50 storm::exceptions::WrongFormatException);
51
52 // There is a line for a state that has been skipped.
54 storm::parser::SparseStateRewardParser<>::parseSparseStateReward(11, STORM_TEST_RESOURCES_DIR "/rew/state_reward_parser_doubledLinesSkipped.state.rew"),
55 storm::exceptions::WrongFormatException);
56}
57
58TEST(SparseStateRewardParserTest, RewardForNonExistentState) {
59 // The index of one of the state that are to be given rewards is higher than the number of states in the model.
61 storm::parser::SparseStateRewardParser<>::parseSparseStateReward(99, STORM_TEST_RESOURCES_DIR "/rew/state_reward_parser_basic.state.rew"),
62 storm::exceptions::OutOfRangeException);
63}
double round(double val, int precision)
TEST(SparseStateRewardParserTest, NonExistingFile)
A class providing the functionality to parse a the state rewards of a model.
static std::vector< ValueType > parseSparseStateReward(uint_fast64_t stateCount, std::string const &filename)
Reads a state reward file and puts the result in a state reward vector.
#define STORM_SILENT_ASSERT_THROW(statement, expected_exception)
Definition storm_gtest.h:26