Storm
A Modern Probabilistic Model Checker
Loading...
Searching...
No Matches
SparseStateRewardParserTest.cpp
Go to the documentation of this file.
1/*
2 * SparseStateRewardParserTest.cpp
3 *
4 * Created on: 26.02.2014
5 * Author: Manuel Sascha Weiand
6 */
7
8#include "storm-config.h"
9#include "test/storm_gtest.h"
10
11#include <cmath>
12
17
18TEST(SparseStateRewardParserTest, NonExistingFile) {
19 // No matter what happens, please do NOT create a file with the name "nonExistingFile.not"!
21 storm::exceptions::FileIoException);
22}
23
24double round(double val, int precision) {
25 std::stringstream s;
26 s << std::setprecision(precision) << std::setiosflags(std::ios_base::fixed) << val;
27 s >> val;
28 return val;
29}
30
31TEST(SparseStateRewardParserTest, BasicParsing) {
32 // Get the parsing result.
33 std::vector<double> result =
34 storm::parser::SparseStateRewardParser<>::parseSparseStateReward(100, STORM_TEST_RESOURCES_DIR "/rew/state_reward_parser_basic.state.rew");
35
36 // Now test if the correct value were parsed.
37 for (int i = 0; i < 100; i++) {
38 ASSERT_EQ(std::round(2 * i + 15 / 13 * i * i - 1.5 / (i + 0.1) + 15.7), std::round(result[i]));
39 }
40}
41
42TEST(SparseStateRewardParserTest, Whitespaces) {
43 // Get the parsing result.
44 std::vector<double> result =
45 storm::parser::SparseStateRewardParser<>::parseSparseStateReward(100, STORM_TEST_RESOURCES_DIR "/rew/state_reward_parser_whitespaces.state.rew");
46
47 // Now test if the correct value were parsed.
48 for (int i = 0; i < 100; i++) {
49 ASSERT_EQ(std::round(2 * i + 15 / 13 * i * i - 1.5 / (i + 0.1) + 15.7), std::round(result[i]));
50 }
51}
52
53TEST(SparseStateRewardParserTest, DoubledLines) {
54 // There are multiple lines attributing a reward to the same state.
56 storm::parser::SparseStateRewardParser<>::parseSparseStateReward(11, STORM_TEST_RESOURCES_DIR "/rew/state_reward_parser_doubledLines.state.rew"),
57 storm::exceptions::WrongFormatException);
58
59 // There is a line for a state that has been skipped.
61 storm::parser::SparseStateRewardParser<>::parseSparseStateReward(11, STORM_TEST_RESOURCES_DIR "/rew/state_reward_parser_doubledLinesSkipped.state.rew"),
62 storm::exceptions::WrongFormatException);
63}
64
65TEST(SparseStateRewardParserTest, RewardForNonExistentState) {
66 // The index of one of the state that are to be given rewards is higher than the number of states in the model.
68 storm::parser::SparseStateRewardParser<>::parseSparseStateReward(99, STORM_TEST_RESOURCES_DIR "/rew/state_reward_parser_basic.state.rew"),
69 storm::exceptions::OutOfRangeException);
70}
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:99