Storm 1.14.0.1
A Modern Probabilistic Model Checker
Loading...
Searching...
No Matches
SolutionBoundsTest.cpp
Go to the documentation of this file.
1#include "storm-config.h"
2#include "test/storm_gtest.h"
3
5
6TEST(SolutionBoundsTest, PrecisionNeedsBothSides) {
8 bounds.lower = std::vector<double>{0.5};
9 EXPECT_FALSE(bounds.isWithinPrecision({0.5}, 1.0, false));
10 EXPECT_FALSE(bounds.isWithinPrecision({0.5}, 1.0, true));
11}
12
13TEST(SolutionBoundsTest, PrecisionRejectsMismatchingSizes) {
15 bounds.setExact(std::vector<double>{0.5});
16 STORM_SILENT_EXPECT_THROW(bounds.isWithinPrecision({0.5, 0.5}, 1.0, false), storm::exceptions::InvalidArgumentException);
17}
18
19TEST(SolutionBoundsTest, AbsolutePrecisionComparesTheDistanceToTheValue) {
21 bounds.lower = std::vector<double>{0.0, 1.0};
22 bounds.upper = std::vector<double>{0.1, 1.05};
23 // Both values sit at the midpoint, so the distance is half of the width.
24 EXPECT_TRUE(bounds.isWithinPrecision({0.05, 1.025}, 0.05, false));
25 EXPECT_FALSE(bounds.isWithinPrecision({0.05, 1.025}, 0.04, false));
26 // A value off center is only as precise as its farther side allows.
27 EXPECT_FALSE(bounds.isWithinPrecision({0.1, 1.025}, 0.05, false));
28}
29
30TEST(SolutionBoundsTest, RelativePrecisionScalesWithTheValue) {
32 bounds.lower = std::vector<double>{10.0};
33 bounds.upper = std::vector<double>{10.1};
34 EXPECT_TRUE(bounds.isWithinPrecision({10.05}, 0.01, true));
35 EXPECT_FALSE(bounds.isWithinPrecision({10.05}, 0.004, true));
36 // The same distance is far too large to be a relative statement about a value this small.
37 bounds.lower = std::vector<double>{0.001};
38 bounds.upper = std::vector<double>{0.101};
39 EXPECT_FALSE(bounds.isWithinPrecision({0.051}, 0.005, true));
40}
41
42TEST(SolutionBoundsTest, RelativePrecisionRejectsBoundsAroundZero) {
44 bounds.lower = std::vector<double>{-0.001};
45 bounds.upper = std::vector<double>{0.001};
46 // The enclosed value may be zero, which no distance but zero is within a relative precision of.
47 EXPECT_FALSE(bounds.isWithinPrecision({0.0}, 0.5, true));
48 EXPECT_TRUE(bounds.isWithinPrecision({0.0}, 0.01, false));
49 bounds.setExact(std::vector<double>{0.0});
50 EXPECT_TRUE(bounds.isWithinPrecision({0.0}, 0.5, true));
51}
TEST(SolutionBoundsTest, PrecisionNeedsBothSides)
#define STORM_SILENT_EXPECT_THROW(statement, expected_exception)
Definition storm_gtest.h:21
Sound lower and upper bounds on a solution vector.
std::optional< std::vector< ValueType > > lower
std::optional< std::vector< ValueType > > upper
bool isWithinPrecision(std::vector< ValueType > const &values, ValueType const &precision, bool relative) const
Returns true if both bounds are set and neither is further from its value than the given precision al...
void setExact(std::vector< ValueType > const &values)
Sets both bounds to the given values, i.e.