Storm
1.13.0.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
6
#include "
storm-parsers/parser/SparseStateRewardParser.h
"
7
#include "
storm/exceptions/FileIoException.h
"
8
#include "
storm/exceptions/OutOfRangeException.h
"
9
#include "
storm/exceptions/WrongFormatException.h
"
10
11
TEST
(SparseStateRewardParserTest, NonExistingFile) {
12
// No matter what happens, please do NOT create a file with the name "nonExistingFile.not"!
13
STORM_SILENT_ASSERT_THROW
(
storm::parser::SparseStateRewardParser<>::parseSparseStateReward
(42, STORM_TEST_RESOURCES_DIR
"/nonExistingFile.not"
),
14
storm::exceptions::FileIoException);
15
}
16
17
double
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
24
TEST
(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
35
TEST
(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
46
TEST
(SparseStateRewardParserTest, DoubledLines) {
47
// There are multiple lines attributing a reward to the same state.
48
STORM_SILENT_ASSERT_THROW
(
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.
53
STORM_SILENT_ASSERT_THROW
(
54
storm::parser::SparseStateRewardParser<>::parseSparseStateReward
(11, STORM_TEST_RESOURCES_DIR
"/rew/state_reward_parser_doubledLinesSkipped.state.rew"
),
55
storm::exceptions::WrongFormatException);
56
}
57
58
TEST
(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.
60
STORM_SILENT_ASSERT_THROW
(
61
storm::parser::SparseStateRewardParser<>::parseSparseStateReward
(99, STORM_TEST_RESOURCES_DIR
"/rew/state_reward_parser_basic.state.rew"
),
62
storm::exceptions::OutOfRangeException);
63
}
FileIoException.h
OutOfRangeException.h
SparseStateRewardParser.h
round
double round(double val, int precision)
Definition
SparseStateRewardParserTest.cpp:17
TEST
TEST(SparseStateRewardParserTest, NonExistingFile)
Definition
SparseStateRewardParserTest.cpp:11
WrongFormatException.h
storm::parser::SparseStateRewardParser::parseSparseStateReward
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.
Definition
SparseStateRewardParser.cpp:18
storm_gtest.h
STORM_SILENT_ASSERT_THROW
#define STORM_SILENT_ASSERT_THROW(statement, expected_exception)
Definition
storm_gtest.h:26
src
test
storm
parser
SparseStateRewardParserTest.cpp
Generated by
1.15.0