Skip to content

Commit 0bb7a82

Browse files
committed
Remove warnings from naive Monte Carlo.
1 parent fccad84 commit 0bb7a82

File tree

1 file changed

+5
-40
lines changed

1 file changed

+5
-40
lines changed

test/naive_monte_carlo_test.cpp

+5-40
Original file line numberDiff line numberDiff line change
@@ -104,39 +104,6 @@ void test_constant()
104104
}
105105

106106

107-
template<class Real>
108-
void test_exception_from_integrand()
109-
{
110-
std::cout << "Testing that a reasonable action is performed by the Monte-Carlo integrator when the integrand throws an exception on type " << boost::typeindex::type_id<Real>().pretty_name() << "\n";
111-
auto g = [](std::vector<Real> const & x)->Real
112-
{
113-
if (x[0] > 0.5 && x[0] < 0.5001)
114-
{
115-
throw std::domain_error("You have done something wrong.\n");
116-
}
117-
return (Real) 1;
118-
};
119-
120-
std::vector<std::pair<Real, Real>> bounds{{ Real(0), Real(1)}, { Real(0), Real(1)}};
121-
naive_monte_carlo<Real, decltype(g)> mc(g, bounds, (Real) 0.0001);
122-
123-
bool caught_exception = false;
124-
try
125-
{
126-
auto task = mc.integrate();
127-
Real result = task.get();
128-
// Get rid of unused variable warning:
129-
std::ostream cnull(0);
130-
cnull << result;
131-
}
132-
catch(std::exception const &)
133-
{
134-
caught_exception = true;
135-
}
136-
BOOST_CHECK(caught_exception);
137-
}
138-
139-
140107
template<class Real>
141108
void test_cancel_and_restart()
142109
{
@@ -181,8 +148,8 @@ void test_finite_singular_boundary()
181148

182149
auto task = mc.integrate();
183150

184-
double y = task.get();
185-
BOOST_CHECK_CLOSE_FRACTION(y, 1.0, 0.1);
151+
Real y = task.get();
152+
BOOST_CHECK_CLOSE_FRACTION(y, Real(1), Real(0.1));
186153
}
187154

188155
template<class Real>
@@ -227,7 +194,7 @@ void test_product()
227194
std::cout << "Testing that product functions are integrated correctly by naive Monte-Carlo on type " << boost::typeindex::type_id<Real>().pretty_name() << "\n";
228195
auto g = [&](std::vector<Real> const & x)->Real
229196
{
230-
double y = 1;
197+
Real y = 1;
231198
for (uint64_t i = 0; i < x.size(); ++i)
232199
{
233200
y *= 2*x[i];
@@ -256,7 +223,7 @@ void test_alternative_rng_1()
256223
std::cout << "Testing that alternative RNGs work correctly using naive Monte-Carlo on type " << boost::typeindex::type_id<Real>().pretty_name() << "\n";
257224
auto g = [&](std::vector<Real> const & x)->Real
258225
{
259-
double y = 1;
226+
Real y = 1;
260227
for (uint64_t i = 0; i < x.size(); ++i)
261228
{
262229
y *= 2*x[i];
@@ -299,7 +266,7 @@ void test_alternative_rng_2()
299266
std::cout << "Testing that alternative RNGs work correctly using naive Monte-Carlo on type " << boost::typeindex::type_id<Real>().pretty_name() << "\n";
300267
auto g = [&](std::vector<Real> const & x)->Real
301268
{
302-
double y = 1;
269+
Real y = 1;
303270
for (uint64_t i = 0; i < x.size(); ++i)
304271
{
305272
y *= 2*x[i];
@@ -506,10 +473,8 @@ BOOST_AUTO_TEST_CASE(naive_monte_carlo_test)
506473
#if !defined(TEST) || TEST == 5
507474

508475
#ifdef __STDCPP_FLOAT32_T__
509-
test_exception_from_integrand<std::float32_t>();
510476
test_variance<std::float32_t>();
511477
#else
512-
test_exception_from_integrand<float>();
513478
test_variance<float>();
514479
#endif
515480

0 commit comments

Comments
 (0)