20#include <boost/test/unit_test.hpp>
21#include <boost/test/data/test_case.hpp>
26#include <oret/toplevelfixture.hpp>
28#include <ql/time/date.hpp>
29#include <ql/tuple.hpp>
37BOOST_FIXTURE_TEST_SUITE(OREDataTestSuite, ore::test::TopLevelFixture)
39BOOST_AUTO_TEST_SUITE(ValueTypeTest)
42 BOOST_TEST_MESSAGE(
"Testing Value RandomVariable binary ops...");
46 BOOST_REQUIRE_EQUAL(x.which(), 0);
47 BOOST_REQUIRE_EQUAL(y.which(), 0);
49 BOOST_REQUIRE_EQUAL(z.which(), 0);
50 BOOST_CHECK_EQUAL(QuantLib::ext::get<RandomVariable>(z), a + b);
52 BOOST_REQUIRE_EQUAL(z.which(), 0);
53 BOOST_CHECK_EQUAL(QuantLib::ext::get<RandomVariable>(z), a - b);
55 BOOST_REQUIRE_EQUAL(z.which(), 0);
56 BOOST_CHECK_EQUAL(QuantLib::ext::get<RandomVariable>(z), a * b);
58 BOOST_REQUIRE_EQUAL(z.which(), 0);
59 BOOST_CHECK_EQUAL(QuantLib::ext::get<RandomVariable>(z), a / b);
61 BOOST_REQUIRE_EQUAL(z.which(), 0);
62 BOOST_CHECK_EQUAL(QuantLib::ext::get<RandomVariable>(z),
min(a, b));
64 BOOST_REQUIRE_EQUAL(z.which(), 0);
65 BOOST_CHECK_EQUAL(QuantLib::ext::get<RandomVariable>(z),
max(a, b));
67 BOOST_REQUIRE_EQUAL(z.which(), 0);
68 BOOST_CHECK_EQUAL(QuantLib::ext::get<RandomVariable>(z),
pow(a, b));
72 BOOST_TEST_MESSAGE(
"Testing Value RandomVariable unary ops...");
76 BOOST_REQUIRE_EQUAL(x.which(), 0);
78 BOOST_REQUIRE_EQUAL(z.which(), 0);
79 BOOST_CHECK_EQUAL(QuantLib::ext::get<RandomVariable>(z), -a);
81 BOOST_REQUIRE_EQUAL(z.which(), 0);
82 BOOST_CHECK_EQUAL(QuantLib::ext::get<RandomVariable>(z),
abs(a));
84 BOOST_REQUIRE_EQUAL(z.which(), 0);
85 BOOST_CHECK_EQUAL(QuantLib::ext::get<RandomVariable>(z),
exp(a));
87 BOOST_REQUIRE_EQUAL(z.which(), 0);
88 BOOST_CHECK_EQUAL(QuantLib::ext::get<RandomVariable>(z),
log(a));
90 BOOST_REQUIRE_EQUAL(z.which(), 0);
91 BOOST_CHECK_EQUAL(QuantLib::ext::get<RandomVariable>(z),
sqrt(a));
93 BOOST_REQUIRE_EQUAL(z.which(), 0);
94 BOOST_CHECK_EQUAL(QuantLib::ext::get<RandomVariable>(z),
normalCdf(a));
96 BOOST_REQUIRE_EQUAL(z.which(), 0);
97 BOOST_CHECK_EQUAL(QuantLib::ext::get<RandomVariable>(z),
normalPdf(a));
101 BOOST_TEST_MESSAGE(
"Testing Value illegal ops...");
102 constexpr Size n = 1;
107 BOOST_CHECK_THROW(a + c, QuantLib::Error);
108 BOOST_CHECK_THROW(a + d, QuantLib::Error);
109 BOOST_CHECK_THROW(a + e, QuantLib::Error);
110 BOOST_CHECK_THROW(a - c, QuantLib::Error);
111 BOOST_CHECK_THROW(a - d, QuantLib::Error);
112 BOOST_CHECK_THROW(a - e, QuantLib::Error);
113 BOOST_CHECK_THROW(a * c, QuantLib::Error);
114 BOOST_CHECK_THROW(a * d, QuantLib::Error);
115 BOOST_CHECK_THROW(a * e, QuantLib::Error);
116 BOOST_CHECK_THROW(a / c, QuantLib::Error);
117 BOOST_CHECK_THROW(a / d, QuantLib::Error);
118 BOOST_CHECK_THROW(a / e, QuantLib::Error);
119 BOOST_CHECK_THROW(
min(a, c), QuantLib::Error);
120 BOOST_CHECK_THROW(
min(a, d), QuantLib::Error);
121 BOOST_CHECK_THROW(
min(a, e), QuantLib::Error);
122 BOOST_CHECK_THROW(
max(a, c), QuantLib::Error);
123 BOOST_CHECK_THROW(
max(a, d), QuantLib::Error);
124 BOOST_CHECK_THROW(
max(a, e), QuantLib::Error);
125 BOOST_CHECK_THROW(
pow(a, c), QuantLib::Error);
126 BOOST_CHECK_THROW(
pow(a, d), QuantLib::Error);
127 BOOST_CHECK_THROW(
pow(a, e), QuantLib::Error);
128 BOOST_CHECK_THROW(-c, QuantLib::Error);
129 BOOST_CHECK_THROW(-d, QuantLib::Error);
130 BOOST_CHECK_THROW(-e, QuantLib::Error);
131 BOOST_CHECK_THROW(
abs(c), QuantLib::Error);
132 BOOST_CHECK_THROW(
abs(d), QuantLib::Error);
133 BOOST_CHECK_THROW(
abs(e), QuantLib::Error);
134 BOOST_CHECK_THROW(
exp(c), QuantLib::Error);
135 BOOST_CHECK_THROW(
exp(d), QuantLib::Error);
136 BOOST_CHECK_THROW(
exp(e), QuantLib::Error);
137 BOOST_CHECK_THROW(
log(c), QuantLib::Error);
138 BOOST_CHECK_THROW(
log(d), QuantLib::Error);
139 BOOST_CHECK_THROW(
log(e), QuantLib::Error);
143 BOOST_TEST_MESSAGE(
"Testing Value assignments...");
144 constexpr Size n = 1;
158 }
catch (
const std::exception& e) {
159 BOOST_FAIL(e.what());
170 BOOST_TEST_MESSAGE(
"Testing Value illegal assignments...");
171 constexpr Size n = 1;
196 BOOST_TEST_MESSAGE(
"Testing Value comparisons...");
197 constexpr Size n = 1;
203 BOOST_CHECK(
equal(a, a).at(0));
205 BOOST_CHECK(
lt(a, a2).at(0));
206 BOOST_CHECK(
leq(a, a).at(0));
207 BOOST_CHECK(
gt(a2, a).at(0));
208 BOOST_CHECK(
geq(a, a).at(0));
210 BOOST_CHECK(
equal(c, c).at(0));
212 BOOST_CHECK(
lt(c, c2).at(0));
213 BOOST_CHECK(
leq(c, c).at(0));
214 BOOST_CHECK(
gt(c2, c).at(0));
215 BOOST_CHECK(
geq(c, c).at(0));
217 BOOST_CHECK(
equal(d, d).at(0));
219 BOOST_CHECK_THROW(
lt(d, d2), QuantLib::Error);
220 BOOST_CHECK_THROW(
leq(d, d2), QuantLib::Error);
221 BOOST_CHECK_THROW(
gt(d, d2), QuantLib::Error);
222 BOOST_CHECK_THROW(
geq(d, d2), QuantLib::Error);
224 BOOST_CHECK(
equal(e, e).at(0));
226 BOOST_CHECK_THROW(
lt(e, e2), QuantLib::Error);
227 BOOST_CHECK_THROW(
leq(e, e2), QuantLib::Error);
228 BOOST_CHECK_THROW(
gt(e, e2), QuantLib::Error);
229 BOOST_CHECK_THROW(
geq(e, e2), QuantLib::Error);
233 BOOST_TEST_MESSAGE(
"Testing Value illegal comparisons...");
234 constexpr Size n = 1;
239 BOOST_CHECK_THROW(
equal(a, c), QuantLib::Error);
240 BOOST_CHECK_THROW(
equal(a, d), QuantLib::Error);
241 BOOST_CHECK_THROW(
equal(a, e), QuantLib::Error);
242 BOOST_CHECK_THROW(
equal(c, d), QuantLib::Error);
243 BOOST_CHECK_THROW(
equal(c, e), QuantLib::Error);
244 BOOST_CHECK_THROW(
equal(d, e), QuantLib::Error);
245 BOOST_CHECK_THROW(
notequal(a, c), QuantLib::Error);
246 BOOST_CHECK_THROW(
notequal(a, d), QuantLib::Error);
247 BOOST_CHECK_THROW(
notequal(a, e), QuantLib::Error);
248 BOOST_CHECK_THROW(
notequal(c, d), QuantLib::Error);
249 BOOST_CHECK_THROW(
notequal(c, e), QuantLib::Error);
250 BOOST_CHECK_THROW(
notequal(d, e), QuantLib::Error);
251 BOOST_CHECK_THROW(
lt(a, c), QuantLib::Error);
252 BOOST_CHECK_THROW(
lt(a, d), QuantLib::Error);
253 BOOST_CHECK_THROW(
lt(a, e), QuantLib::Error);
254 BOOST_CHECK_THROW(
lt(c, d), QuantLib::Error);
255 BOOST_CHECK_THROW(
lt(c, e), QuantLib::Error);
256 BOOST_CHECK_THROW(
lt(d, e), QuantLib::Error);
257 BOOST_CHECK_THROW(
leq(a, c), QuantLib::Error);
258 BOOST_CHECK_THROW(
leq(a, d), QuantLib::Error);
259 BOOST_CHECK_THROW(
leq(a, e), QuantLib::Error);
260 BOOST_CHECK_THROW(
leq(c, d), QuantLib::Error);
261 BOOST_CHECK_THROW(
leq(c, e), QuantLib::Error);
262 BOOST_CHECK_THROW(
leq(d, e), QuantLib::Error);
263 BOOST_CHECK_THROW(
gt(a, c), QuantLib::Error);
264 BOOST_CHECK_THROW(
gt(a, d), QuantLib::Error);
265 BOOST_CHECK_THROW(
gt(a, e), QuantLib::Error);
266 BOOST_CHECK_THROW(
gt(c, d), QuantLib::Error);
267 BOOST_CHECK_THROW(
gt(c, e), QuantLib::Error);
268 BOOST_CHECK_THROW(
gt(d, e), QuantLib::Error);
269 BOOST_CHECK_THROW(
geq(a, c), QuantLib::Error);
270 BOOST_CHECK_THROW(
geq(a, d), QuantLib::Error);
271 BOOST_CHECK_THROW(
geq(a, e), QuantLib::Error);
272 BOOST_CHECK_THROW(
geq(c, d), QuantLib::Error);
273 BOOST_CHECK_THROW(
geq(c, e), QuantLib::Error);
274 BOOST_CHECK_THROW(
geq(d, e), QuantLib::Error);
277BOOST_AUTO_TEST_SUITE_END()
279BOOST_AUTO_TEST_SUITE_END()
RandomVariable max(RandomVariable x, const RandomVariable &y)
RandomVariable exp(RandomVariable x)
RandomVariable sqrt(RandomVariable x)
RandomVariable log(RandomVariable x)
RandomVariable pow(RandomVariable x, const RandomVariable &y)
RandomVariable normalCdf(RandomVariable x)
RandomVariable abs(RandomVariable x)
RandomVariable normalPdf(RandomVariable x)
Filter equal(Filter x, const Filter &y)
RandomVariable min(RandomVariable x, const RandomVariable &y)
Filter lt(const ValueType &x, const ValueType &y)
Filter notequal(const ValueType &x, const ValueType &y)
Filter gt(const ValueType &x, const ValueType &y)
ValueType typeSafeAssign(ValueType &x, const ValueType &y)
Filter leq(const ValueType &x, const ValueType &y)
Filter geq(const ValueType &x, const ValueType &y)
boost::variant< RandomVariable, EventVec, CurrencyVec, IndexVec, DaycounterVec, Filter > ValueType
BOOST_AUTO_TEST_CASE(testValueRandomVariableBinaryOps)
value type and operations