1 // Copyright Paul A. Bristow 2006-7.
2 // Copyright John Maddock 2006-7.
4 // Use, modification and distribution are subject to the
5 // Boost Software License, Version 1.0.
6 // (See accompanying file LICENSE_1_0.txt
7 // or copy at http://www.boost.org/LICENSE_1_0.txt)
9 // Test error handling mechanism produces the expected error messages.
10 // for example Error in function boost::math::test_function<float>(float, float, float): Domain Error evaluating function at 0
12 // Define some custom dummy error handlers that do nothing but throw,
13 // in order to check that they are otherwise undefined.
14 // The user MUST define them before they can be used.
16 struct user_defined_error
{};
18 namespace boost
{ namespace math
{ namespace policies
{
20 #ifndef BOOST_NO_EXCEPTIONS
23 T
user_domain_error(const char* , const char* , const T
& )
25 throw user_defined_error();
29 T
user_pole_error(const char* , const char* , const T
& )
31 throw user_defined_error();
35 T
user_overflow_error(const char* , const char* , const T
& )
37 throw user_defined_error();
41 T
user_underflow_error(const char* , const char* , const T
& )
43 throw user_defined_error();
47 T
user_denorm_error(const char* , const char* , const T
& )
49 throw user_defined_error();
53 T
user_evaluation_error(const char* , const char* , const T
& )
55 throw user_defined_error();
59 T
user_indeterminate_result_error(const char* , const char* , const T
& )
61 throw user_defined_error();
66 #include <boost/math/tools/test.hpp>
67 #include <boost/math/concepts/real_concept.hpp>
68 #include <boost/math/policies/policy.hpp>
69 #include <boost/math/policies/error_handling.hpp>
70 #include <boost/math/tools/polynomial.hpp>
71 #define BOOST_TEST_MAIN
72 #include <boost/test/unit_test.hpp> // for test_main
73 #include <cerrno> // for errno
77 // Define some policies:
79 using namespace boost::math::policies
;
81 domain_error
<throw_on_error
>,
82 pole_error
<throw_on_error
>,
83 overflow_error
<throw_on_error
>,
84 underflow_error
<throw_on_error
>,
85 denorm_error
<throw_on_error
>,
86 evaluation_error
<throw_on_error
>,
87 indeterminate_result_error
<throw_on_error
> > throw_policy
;
89 domain_error
<errno_on_error
>,
90 pole_error
<errno_on_error
>,
91 overflow_error
<errno_on_error
>,
92 underflow_error
<errno_on_error
>,
93 denorm_error
<errno_on_error
>,
94 evaluation_error
<errno_on_error
>,
95 indeterminate_result_error
<errno_on_error
> > errno_policy
;
97 domain_error
<ignore_error
>,
98 pole_error
<ignore_error
>,
99 overflow_error
<ignore_error
>,
100 underflow_error
<ignore_error
>,
101 denorm_error
<ignore_error
>,
102 evaluation_error
<ignore_error
>,
103 indeterminate_result_error
<ignore_error
> > ignore_policy
;
105 domain_error
<user_error
>,
106 pole_error
<user_error
>,
107 overflow_error
<user_error
>,
108 underflow_error
<user_error
>,
109 denorm_error
<user_error
>,
110 evaluation_error
<user_error
>,
111 indeterminate_result_error
<user_error
> > user_policy
;
112 policy
<> default_policy
;
114 #define TEST_EXCEPTION(expression, exception, msg)\
115 BOOST_MATH_CHECK_THROW(expression, exception);\
116 try{ expression; }catch(const exception& e){ std::cout << e.what() << std::endl; BOOST_CHECK_EQUAL(std::string(e.what()), std::string(msg)); }
119 std::string
format_message_string(const char* str
)
121 std::string type_name
= boost::math::policies::detail::name_of
<T
>();
122 std::string
result(str
);
123 if(type_name
!= "float")
125 std::string::size_type pos
= 0;
126 while((pos
= result
.find("float", pos
)) != std::string::npos
)
128 result
.replace(pos
, 5, type_name
);
129 pos
+= type_name
.size();
138 const char* func
= "boost::math::test_function<%1%>(%1%, %1%, %1%)";
139 const char* msg1
= "Error while handling value %1%";
140 const char* msg2
= "Error message goes here...";
142 // Check that exception is thrown, catch and show the message, for example:
143 // Error in function boost::math::test_function<float>(float, float, float): Error while handling value 0
144 #ifndef BOOST_NO_EXCEPTIONS
145 TEST_EXCEPTION(boost::math::policies::raise_domain_error(func
, msg1
, T(0.0), throw_policy
), std::domain_error
, format_message_string
<T
>("Error in function boost::math::test_function<float>(float, float, float): Error while handling value 0"));
146 TEST_EXCEPTION(boost::math::policies::raise_domain_error(func
, 0, T(0.0), throw_policy
), std::domain_error
, format_message_string
<T
>("Error in function boost::math::test_function<float>(float, float, float): Domain Error evaluating function at 0"));
147 TEST_EXCEPTION(boost::math::policies::raise_pole_error(func
, msg1
, T(0.0), throw_policy
), std::domain_error
, format_message_string
<T
>("Error in function boost::math::test_function<float>(float, float, float): Error while handling value 0"));
148 TEST_EXCEPTION(boost::math::policies::raise_pole_error(func
, 0, T(0.0), throw_policy
), std::domain_error
, format_message_string
<T
>("Error in function boost::math::test_function<float>(float, float, float): Evaluation of function at pole 0"));
149 TEST_EXCEPTION(boost::math::policies::raise_overflow_error
<T
>(func
, msg2
, throw_policy
), std::overflow_error
, format_message_string
<T
>("Error in function boost::math::test_function<float>(float, float, float): Error message goes here..."));
150 TEST_EXCEPTION(boost::math::policies::raise_overflow_error
<T
>(func
, 0, throw_policy
), std::overflow_error
, format_message_string
<T
>("Error in function boost::math::test_function<float>(float, float, float): Overflow Error"));
151 TEST_EXCEPTION(boost::math::policies::raise_underflow_error
<T
>(func
, msg2
, throw_policy
), std::underflow_error
, format_message_string
<T
>("Error in function boost::math::test_function<float>(float, float, float): Error message goes here..."));
152 TEST_EXCEPTION(boost::math::policies::raise_underflow_error
<T
>(func
, 0, throw_policy
), std::underflow_error
, format_message_string
<T
>("Error in function boost::math::test_function<float>(float, float, float): Underflow Error"));
153 TEST_EXCEPTION(boost::math::policies::raise_denorm_error
<T
>(func
, msg2
, T(0), throw_policy
), std::underflow_error
, format_message_string
<T
>("Error in function boost::math::test_function<float>(float, float, float): Error message goes here..."));
154 TEST_EXCEPTION(boost::math::policies::raise_denorm_error
<T
>(func
, 0, T(0), throw_policy
), std::underflow_error
, format_message_string
<T
>("Error in function boost::math::test_function<float>(float, float, float): Denorm Error"));
155 TEST_EXCEPTION(boost::math::policies::raise_evaluation_error(func
, msg1
, T(1.25), throw_policy
), boost::math::evaluation_error
, format_message_string
<T
>("Error in function boost::math::test_function<float>(float, float, float): Error while handling value 1.25"));
156 TEST_EXCEPTION(boost::math::policies::raise_evaluation_error(func
, 0, T(1.25), throw_policy
), boost::math::evaluation_error
, format_message_string
<T
>("Error in function boost::math::test_function<float>(float, float, float): Internal Evaluation Error, best value so far was 1.25"));
157 TEST_EXCEPTION(boost::math::policies::raise_indeterminate_result_error(func
, msg1
, T(1.25), T(12.34), throw_policy
), std::domain_error
, format_message_string
<T
>("Error in function boost::math::test_function<float>(float, float, float): Error while handling value 1.25"));
158 TEST_EXCEPTION(boost::math::policies::raise_indeterminate_result_error(func
, 0, T(1.25), T(12.34), throw_policy
), std::domain_error
, format_message_string
<T
>("Error in function boost::math::test_function<float>(float, float, float): Indeterminate result with value 1.25"));
160 // Now try user error handlers: these should all throw user_error():
161 // - because by design these are undefined and must be defined by the user ;-)
162 BOOST_MATH_CHECK_THROW(boost::math::policies::raise_domain_error(func
, msg1
, T(0.0), user_policy
), user_defined_error
);
163 BOOST_MATH_CHECK_THROW(boost::math::policies::raise_pole_error(func
, msg1
, T(0.0), user_policy
), user_defined_error
);
164 BOOST_MATH_CHECK_THROW(boost::math::policies::raise_overflow_error
<T
>(func
, msg2
, user_policy
), user_defined_error
);
165 BOOST_MATH_CHECK_THROW(boost::math::policies::raise_underflow_error
<T
>(func
, msg2
, user_policy
), user_defined_error
);
166 BOOST_MATH_CHECK_THROW(boost::math::policies::raise_denorm_error
<T
>(func
, msg2
, T(0), user_policy
), user_defined_error
);
167 BOOST_MATH_CHECK_THROW(boost::math::policies::raise_evaluation_error(func
, msg1
, T(0.0), user_policy
), user_defined_error
);
168 BOOST_MATH_CHECK_THROW(boost::math::policies::raise_indeterminate_result_error(func
, msg1
, T(0.0), T(0.0), user_policy
), user_defined_error
);
171 // Test with ignore_error
172 BOOST_CHECK((boost::math::isnan
)(boost::math::policies::raise_domain_error(func
, msg1
, T(0.0), ignore_policy
)) || !std::numeric_limits
<T
>::has_quiet_NaN
);
173 BOOST_CHECK((boost::math::isnan
)(boost::math::policies::raise_pole_error(func
, msg1
, T(0.0), ignore_policy
)) || !std::numeric_limits
<T
>::has_quiet_NaN
);
174 BOOST_CHECK_EQUAL(boost::math::policies::raise_overflow_error
<T
>(func
, msg2
, ignore_policy
), std::numeric_limits
<T
>::has_infinity
? std::numeric_limits
<T
>::infinity() : boost::math::tools::max_value
<T
>());
175 BOOST_CHECK_EQUAL(boost::math::policies::raise_underflow_error
<T
>(func
, msg2
, ignore_policy
), T(0));
176 BOOST_CHECK_EQUAL(boost::math::policies::raise_denorm_error
<T
>(func
, msg2
, T(1.25), ignore_policy
), T(1.25));
177 BOOST_CHECK_EQUAL(boost::math::policies::raise_evaluation_error(func
, msg1
, T(1.25), ignore_policy
), T(1.25));
178 BOOST_CHECK_EQUAL(boost::math::policies::raise_indeterminate_result_error(func
, 0, T(0.0), T(12.34), ignore_policy
), T(12.34));
180 // Test with errno_on_error
182 BOOST_CHECK((boost::math::isnan
)(boost::math::policies::raise_domain_error(func
, msg1
, T(0.0), errno_policy
)) || !std::numeric_limits
<T
>::has_quiet_NaN
);
183 BOOST_CHECK(errno
== EDOM
);
185 BOOST_CHECK((boost::math::isnan
)(boost::math::policies::raise_pole_error(func
, msg1
, T(0.0), errno_policy
)) || !std::numeric_limits
<T
>::has_quiet_NaN
);
186 BOOST_CHECK(errno
== EDOM
);
188 BOOST_CHECK_EQUAL(boost::math::policies::raise_overflow_error
<T
>(func
, msg2
, errno_policy
), std::numeric_limits
<T
>::has_infinity
? std::numeric_limits
<T
>::infinity() : boost::math::tools::max_value
<T
>());
189 BOOST_CHECK_EQUAL(errno
, ERANGE
);
191 BOOST_CHECK_EQUAL(boost::math::policies::raise_underflow_error
<T
>(func
, msg2
, errno_policy
), T(0));
192 BOOST_CHECK_EQUAL(errno
, ERANGE
);
194 BOOST_CHECK_EQUAL(boost::math::policies::raise_denorm_error
<T
>(func
, msg2
, T(1.25), errno_policy
), T(1.25));
195 BOOST_CHECK_EQUAL(errno
, ERANGE
);
197 BOOST_CHECK_EQUAL(boost::math::policies::raise_evaluation_error(func
, msg1
, T(1.25), errno_policy
), T(1.25));
198 BOOST_CHECK(errno
== EDOM
);
200 BOOST_CHECK(boost::math::policies::raise_indeterminate_result_error(func
, 0, T(0.0), T(12.34), errno_policy
) == T(12.34));
201 BOOST_CHECK_EQUAL(errno
, EDOM
);
205 void test_complex_error(T
)
208 // Error handling that can be applied to non-scalar types such as std::complex
210 const char* func
= "boost::math::test_function<%1%>(%1%, %1%, %1%)";
211 const char* msg1
= "Error while handling value %1%";
212 const char* msg2
= "Error message goes here...";
214 // Check that exception is thrown, catch and show the message, for example:
215 // Error in function boost::math::test_function<float>(float, float, float): Error while handling value 0
216 #ifndef BOOST_NO_EXCEPTIONS
217 TEST_EXCEPTION(boost::math::policies::raise_domain_error(func
, msg1
, T(0.0), throw_policy
), std::domain_error
, format_message_string
<T
>("Error in function boost::math::test_function<float>(float, float, float): Error while handling value (0,0)"));
218 TEST_EXCEPTION(boost::math::policies::raise_domain_error(func
, 0, T(0.0), throw_policy
), std::domain_error
, format_message_string
<T
>("Error in function boost::math::test_function<float>(float, float, float): Domain Error evaluating function at (0,0)"));
219 TEST_EXCEPTION(boost::math::policies::raise_pole_error(func
, msg1
, T(0.0), throw_policy
), std::domain_error
, format_message_string
<T
>("Error in function boost::math::test_function<float>(float, float, float): Error while handling value (0,0)"));
220 TEST_EXCEPTION(boost::math::policies::raise_pole_error(func
, 0, T(0.0), throw_policy
), std::domain_error
, format_message_string
<T
>("Error in function boost::math::test_function<float>(float, float, float): Evaluation of function at pole (0,0)"));
221 //TEST_EXCEPTION(boost::math::policies::raise_overflow_error<T>(func, msg2, throw_policy), std::overflow_error, format_message_string<T>("Error in function boost::math::test_function<float>(float, float, float): Error message goes here..."));
222 //TEST_EXCEPTION(boost::math::policies::raise_overflow_error<T>(func, 0, throw_policy), std::overflow_error, format_message_string<T>("Error in function boost::math::test_function<float>(float, float, float): Overflow Error"));
223 TEST_EXCEPTION(boost::math::policies::raise_underflow_error
<T
>(func
, msg2
, throw_policy
), std::underflow_error
, format_message_string
<T
>("Error in function boost::math::test_function<float>(float, float, float): Error message goes here..."));
224 TEST_EXCEPTION(boost::math::policies::raise_underflow_error
<T
>(func
, 0, throw_policy
), std::underflow_error
, format_message_string
<T
>("Error in function boost::math::test_function<float>(float, float, float): Underflow Error"));
225 TEST_EXCEPTION(boost::math::policies::raise_denorm_error
<T
>(func
, msg2
, T(0), throw_policy
), std::underflow_error
, format_message_string
<T
>("Error in function boost::math::test_function<float>(float, float, float): Error message goes here..."));
226 TEST_EXCEPTION(boost::math::policies::raise_denorm_error
<T
>(func
, 0, T(0), throw_policy
), std::underflow_error
, format_message_string
<T
>("Error in function boost::math::test_function<float>(float, float, float): Denorm Error"));
227 TEST_EXCEPTION(boost::math::policies::raise_evaluation_error(func
, msg1
, T(1.25), throw_policy
), boost::math::evaluation_error
, format_message_string
<T
>("Error in function boost::math::test_function<float>(float, float, float): Error while handling value (1.25,0)"));
228 TEST_EXCEPTION(boost::math::policies::raise_evaluation_error(func
, 0, T(1.25), throw_policy
), boost::math::evaluation_error
, format_message_string
<T
>("Error in function boost::math::test_function<float>(float, float, float): Internal Evaluation Error, best value so far was (1.25,0)"));
229 TEST_EXCEPTION(boost::math::policies::raise_indeterminate_result_error(func
, msg1
, T(1.25), T(12.34), throw_policy
), std::domain_error
, format_message_string
<T
>("Error in function boost::math::test_function<float>(float, float, float): Error while handling value (1.25,0)"));
230 TEST_EXCEPTION(boost::math::policies::raise_indeterminate_result_error(func
, 0, T(1.25), T(12.34), throw_policy
), std::domain_error
, format_message_string
<T
>("Error in function boost::math::test_function<float>(float, float, float): Indeterminate result with value (1.25,0)"));
232 // Now try user error handlers: these should all throw user_error():
233 // - because by design these are undefined and must be defined by the user ;-)
234 BOOST_MATH_CHECK_THROW(boost::math::policies::raise_domain_error(func
, msg1
, T(0.0), user_policy
), user_defined_error
);
235 BOOST_MATH_CHECK_THROW(boost::math::policies::raise_pole_error(func
, msg1
, T(0.0), user_policy
), user_defined_error
);
236 //BOOST_MATH_CHECK_THROW(boost::math::policies::raise_overflow_error<T>(func, msg2, user_policy), user_defined_error);
237 BOOST_MATH_CHECK_THROW(boost::math::policies::raise_underflow_error
<T
>(func
, msg2
, user_policy
), user_defined_error
);
238 BOOST_MATH_CHECK_THROW(boost::math::policies::raise_denorm_error
<T
>(func
, msg2
, T(0), user_policy
), user_defined_error
);
239 BOOST_MATH_CHECK_THROW(boost::math::policies::raise_evaluation_error(func
, msg1
, T(0.0), user_policy
), user_defined_error
);
240 BOOST_MATH_CHECK_THROW(boost::math::policies::raise_indeterminate_result_error(func
, msg1
, T(0.0), T(0.0), user_policy
), user_defined_error
);
243 // Test with ignore_error
244 BOOST_CHECK((boost::math::isnan
)(boost::math::policies::raise_domain_error(func
, msg1
, T(0.0), ignore_policy
)) || !std::numeric_limits
<T
>::has_quiet_NaN
);
245 BOOST_CHECK((boost::math::isnan
)(boost::math::policies::raise_pole_error(func
, msg1
, T(0.0), ignore_policy
)) || !std::numeric_limits
<T
>::has_quiet_NaN
);
246 //BOOST_CHECK_EQUAL(boost::math::policies::raise_overflow_error<T>(func, msg2, ignore_policy), std::numeric_limits<T>::has_infinity ? std::numeric_limits<T>::infinity() : boost::math::tools::max_value<T>());
247 BOOST_CHECK_EQUAL(boost::math::policies::raise_underflow_error
<T
>(func
, msg2
, ignore_policy
), T(0));
248 BOOST_CHECK_EQUAL(boost::math::policies::raise_denorm_error
<T
>(func
, msg2
, T(1.25), ignore_policy
), T(1.25));
249 BOOST_CHECK_EQUAL(boost::math::policies::raise_evaluation_error(func
, msg1
, T(1.25), ignore_policy
), T(1.25));
250 BOOST_CHECK_EQUAL(boost::math::policies::raise_indeterminate_result_error(func
, 0, T(0.0), T(12.34), ignore_policy
), T(12.34));
252 // Test with errno_on_error
254 BOOST_CHECK((boost::math::isnan
)(boost::math::policies::raise_domain_error(func
, msg1
, T(0.0), errno_policy
)) || !std::numeric_limits
<T
>::has_quiet_NaN
);
255 BOOST_CHECK(errno
== EDOM
);
257 BOOST_CHECK((boost::math::isnan
)(boost::math::policies::raise_pole_error(func
, msg1
, T(0.0), errno_policy
)) || !std::numeric_limits
<T
>::has_quiet_NaN
);
258 BOOST_CHECK(errno
== EDOM
);
260 //BOOST_CHECK_EQUAL(boost::math::policies::raise_overflow_error<T>(func, msg2, errno_policy), std::numeric_limits<T>::has_infinity ? std::numeric_limits<T>::infinity() : boost::math::tools::max_value<T>());
261 //BOOST_CHECK_EQUAL(errno, ERANGE);
263 BOOST_CHECK_EQUAL(boost::math::policies::raise_underflow_error
<T
>(func
, msg2
, errno_policy
), T(0));
264 BOOST_CHECK_EQUAL(errno
, ERANGE
);
266 BOOST_CHECK_EQUAL(boost::math::policies::raise_denorm_error
<T
>(func
, msg2
, T(1.25), errno_policy
), T(1.25));
267 BOOST_CHECK_EQUAL(errno
, ERANGE
);
269 BOOST_CHECK_EQUAL(boost::math::policies::raise_evaluation_error(func
, msg1
, T(1.25), errno_policy
), T(1.25));
270 BOOST_CHECK(errno
== EDOM
);
272 BOOST_CHECK(boost::math::policies::raise_indeterminate_result_error(func
, 0, T(0.0), T(12.34), errno_policy
) == T(12.34));
273 BOOST_CHECK_EQUAL(errno
, EDOM
);
277 void test_polynomial_error(T
)
280 // Error handling that can be applied to non-scalar types such as std::complex
282 const char* func
= "boost::math::test_function<%1%>(%1%, %1%, %1%)";
283 const char* msg1
= "Error while handling value %1%";
284 const char* msg2
= "Error message goes here...";
286 static const typename
T::value_type data
[] = { 1, 2, 3 };
287 static const T
val(data
, 2);
289 // Check that exception is thrown, catch and show the message, for example:
290 // Error in function boost::math::test_function<float>(float, float, float): Error while handling value 0
291 #ifndef BOOST_NO_EXCEPTIONS
292 TEST_EXCEPTION(boost::math::policies::raise_domain_error(func
, msg1
, val
, throw_policy
), std::domain_error
, format_message_string
<T
>("Error in function boost::math::test_function<float>(float, float, float): Error while handling value { 1, 2, 3 }"));
293 TEST_EXCEPTION(boost::math::policies::raise_domain_error(func
, 0, val
, throw_policy
), std::domain_error
, format_message_string
<T
>("Error in function boost::math::test_function<float>(float, float, float): Domain Error evaluating function at { 1, 2, 3 }"));
294 TEST_EXCEPTION(boost::math::policies::raise_pole_error(func
, msg1
, val
, throw_policy
), std::domain_error
, format_message_string
<T
>("Error in function boost::math::test_function<float>(float, float, float): Error while handling value { 1, 2, 3 }"));
295 TEST_EXCEPTION(boost::math::policies::raise_pole_error(func
, 0, val
, throw_policy
), std::domain_error
, format_message_string
<T
>("Error in function boost::math::test_function<float>(float, float, float): Evaluation of function at pole { 1, 2, 3 }"));
296 //TEST_EXCEPTION(boost::math::policies::raise_overflow_error<T>(func, msg2, throw_policy), std::overflow_error, format_message_string<T>("Error in function boost::math::test_function<float>(float, float, float): Error message goes here..."));
297 //TEST_EXCEPTION(boost::math::policies::raise_overflow_error<T>(func, 0, throw_policy), std::overflow_error, format_message_string<T>("Error in function boost::math::test_function<float>(float, float, float): Overflow Error"));
298 //TEST_EXCEPTION(boost::math::policies::raise_underflow_error<T>(func, msg2, throw_policy), std::underflow_error, format_message_string<T>("Error in function boost::math::test_function<float>(float, float, float): Error message goes here..."));
299 //TEST_EXCEPTION(boost::math::policies::raise_underflow_error<T>(func, 0, throw_policy), std::underflow_error, format_message_string<T>("Error in function boost::math::test_function<float>(float, float, float): Underflow Error"));
300 //TEST_EXCEPTION(boost::math::policies::raise_denorm_error<T>(func, msg2, T(0), throw_policy), std::underflow_error, format_message_string<T>("Error in function boost::math::test_function<float>(float, float, float): Error message goes here..."));
301 //TEST_EXCEPTION(boost::math::policies::raise_denorm_error<T>(func, 0, T(0), throw_policy), std::underflow_error, format_message_string<T>("Error in function boost::math::test_function<float>(float, float, float): Denorm Error"));
302 TEST_EXCEPTION(boost::math::policies::raise_evaluation_error(func
, msg1
, val
, throw_policy
), boost::math::evaluation_error
, format_message_string
<T
>("Error in function boost::math::test_function<float>(float, float, float): Error while handling value { 1, 2, 3 }"));
303 TEST_EXCEPTION(boost::math::policies::raise_evaluation_error(func
, 0, val
, throw_policy
), boost::math::evaluation_error
, format_message_string
<T
>("Error in function boost::math::test_function<float>(float, float, float): Internal Evaluation Error, best value so far was { 1, 2, 3 }"));
304 TEST_EXCEPTION(boost::math::policies::raise_indeterminate_result_error(func
, msg1
, val
, T(12.34), throw_policy
), std::domain_error
, format_message_string
<T
>("Error in function boost::math::test_function<float>(float, float, float): Error while handling value { 1, 2, 3 }"));
305 TEST_EXCEPTION(boost::math::policies::raise_indeterminate_result_error(func
, 0, val
, T(12.34), throw_policy
), std::domain_error
, format_message_string
<T
>("Error in function boost::math::test_function<float>(float, float, float): Indeterminate result with value { 1, 2, 3 }"));
307 // Now try user error handlers: these should all throw user_error():
308 // - because by design these are undefined and must be defined by the user ;-)
309 BOOST_MATH_CHECK_THROW(boost::math::policies::raise_domain_error(func
, msg1
, T(0.0), user_policy
), user_defined_error
);
310 BOOST_MATH_CHECK_THROW(boost::math::policies::raise_pole_error(func
, msg1
, T(0.0), user_policy
), user_defined_error
);
311 //BOOST_MATH_CHECK_THROW(boost::math::policies::raise_overflow_error<T>(func, msg2, user_policy), user_defined_error);
312 //BOOST_MATH_CHECK_THROW(boost::math::policies::raise_underflow_error<T>(func, msg2, user_policy), user_defined_error);
313 //BOOST_MATH_CHECK_THROW(boost::math::policies::raise_denorm_error<T>(func, msg2, T(0), user_policy), user_defined_error);
314 BOOST_MATH_CHECK_THROW(boost::math::policies::raise_evaluation_error(func
, msg1
, T(0.0), user_policy
), user_defined_error
);
315 BOOST_MATH_CHECK_THROW(boost::math::policies::raise_indeterminate_result_error(func
, msg1
, T(0.0), T(0.0), user_policy
), user_defined_error
);
318 // Test with ignore_error
319 BOOST_CHECK((boost::math::isnan
)(boost::math::policies::raise_domain_error(func
, msg1
, T(0.0), ignore_policy
)) || !std::numeric_limits
<T
>::has_quiet_NaN
);
320 BOOST_CHECK((boost::math::isnan
)(boost::math::policies::raise_pole_error(func
, msg1
, T(0.0), ignore_policy
)) || !std::numeric_limits
<T
>::has_quiet_NaN
);
321 //BOOST_CHECK_EQUAL(boost::math::policies::raise_overflow_error<T>(func, msg2, ignore_policy), std::numeric_limits<T>::has_infinity ? std::numeric_limits<T>::infinity() : boost::math::tools::max_value<T>());
322 //BOOST_CHECK_EQUAL(boost::math::policies::raise_underflow_error<T>(func, msg2, ignore_policy), T(0));
323 //BOOST_CHECK_EQUAL(boost::math::policies::raise_denorm_error<T>(func, msg2, T(1.25), ignore_policy), T(1.25));
324 BOOST_CHECK_EQUAL(boost::math::policies::raise_evaluation_error(func
, msg1
, T(1.25), ignore_policy
), T(1.25));
325 BOOST_CHECK_EQUAL(boost::math::policies::raise_indeterminate_result_error(func
, 0, T(0.0), T(12.34), ignore_policy
), T(12.34));
327 // Test with errno_on_error
329 BOOST_CHECK((boost::math::isnan
)(boost::math::policies::raise_domain_error(func
, msg1
, T(0.0), errno_policy
)) || !std::numeric_limits
<T
>::has_quiet_NaN
);
330 BOOST_CHECK(errno
== EDOM
);
332 BOOST_CHECK((boost::math::isnan
)(boost::math::policies::raise_pole_error(func
, msg1
, T(0.0), errno_policy
)) || !std::numeric_limits
<T
>::has_quiet_NaN
);
333 BOOST_CHECK(errno
== EDOM
);
335 //BOOST_CHECK_EQUAL(boost::math::policies::raise_overflow_error<T>(func, msg2, errno_policy), std::numeric_limits<T>::has_infinity ? std::numeric_limits<T>::infinity() : boost::math::tools::max_value<T>());
336 //BOOST_CHECK_EQUAL(errno, ERANGE);
338 //BOOST_CHECK_EQUAL(boost::math::policies::raise_underflow_error<T>(func, msg2, errno_policy), T(0));
339 //BOOST_CHECK_EQUAL(errno, ERANGE);
341 //BOOST_CHECK_EQUAL(boost::math::policies::raise_denorm_error<T>(func, msg2, T(1.25), errno_policy), T(1.25));
342 //BOOST_CHECK_EQUAL(errno, ERANGE);
344 BOOST_CHECK_EQUAL(boost::math::policies::raise_evaluation_error(func
, msg1
, T(1.25), errno_policy
), T(1.25));
345 BOOST_CHECK(errno
== EDOM
);
347 BOOST_CHECK(boost::math::policies::raise_indeterminate_result_error(func
, 0, T(0.0), T(12.34), errno_policy
) == T(12.34));
348 BOOST_CHECK_EQUAL(errno
, EDOM
);
351 BOOST_AUTO_TEST_CASE( test_main
)
353 // Test error handling.
354 // (Parameter value, arbitrarily zero, only communicates the floating point type FPT).
355 test_error(0.0F
); // Test float.
356 test_error(0.0); // Test double.
357 test_error(0.0L); // Test long double.
358 test_error(boost::math::concepts::real_concept(0.0L)); // Test concepts.
360 // try complex numbers too:
361 test_complex_error(std::complex<float>(0));
362 test_complex_error(std::complex<double>(0));
363 test_complex_error(std::complex<long double>(0));
365 test_polynomial_error(boost::math::tools::polynomial
<float>());
367 } // BOOST_AUTO_TEST_CASE( test_main )
371 Autorun "i:\boost-06-05-03-1300\libs\math\test\Math_test\debug\test_error_handling.exe"
372 Running 1 test case...
373 Error in function boost::math::test_function<float>(float, float, float): Error while handling value 0
374 Error in function boost::math::test_function<float>(float, float, float): Domain Error evaluating function at 0
375 Error in function boost::math::test_function<float>(float, float, float): Error while handling value 0
376 Error in function boost::math::test_function<float>(float, float, float): Evaluation of function at pole 0
377 Error in function boost::math::test_function<float>(float, float, float): Error message goes here...
378 Error in function boost::math::test_function<float>(float, float, float): Overflow Error
379 Error in function boost::math::test_function<float>(float, float, float): Error message goes here...
380 Error in function boost::math::test_function<float>(float, float, float): Underflow Error
381 Error in function boost::math::test_function<float>(float, float, float): Error message goes here...
382 Error in function boost::math::test_function<float>(float, float, float): Denorm Error
383 Error in function boost::math::test_function<float>(float, float, float): Error while handling value 1.25
384 Error in function boost::math::test_function<float>(float, float, float): Internal Evaluation Error, best value so far was 1.25
385 Error in function boost::math::test_function<double>(double, double, double): Error while handling value 0
386 Error in function boost::math::test_function<double>(double, double, double): Domain Error evaluating function at 0
387 Error in function boost::math::test_function<double>(double, double, double): Error while handling value 0
388 Error in function boost::math::test_function<double>(double, double, double): Evaluation of function at pole 0
389 Error in function boost::math::test_function<double>(double, double, double): Error message goes here...
390 Error in function boost::math::test_function<double>(double, double, double): Overflow Error
391 Error in function boost::math::test_function<double>(double, double, double): Error message goes here...
392 Error in function boost::math::test_function<double>(double, double, double): Underflow Error
393 Error in function boost::math::test_function<double>(double, double, double): Error message goes here...
394 Error in function boost::math::test_function<double>(double, double, double): Denorm Error
395 Error in function boost::math::test_function<double>(double, double, double): Error while handling value 1.25
396 Error in function boost::math::test_function<double>(double, double, double): Internal Evaluation Error, best value so far was 1.25
397 Error in function boost::math::test_function<long double>(long double, long double, long double): Error while handling value 0
398 Error in function boost::math::test_function<long double>(long double, long double, long double): Domain Error evaluating function at 0
399 Error in function boost::math::test_function<long double>(long double, long double, long double): Error while handling value 0
400 Error in function boost::math::test_function<long double>(long double, long double, long double): Evaluation of function at pole 0
401 Error in function boost::math::test_function<long double>(long double, long double, long double): Error message goes here...
402 Error in function boost::math::test_function<long double>(long double, long double, long double): Overflow Error
403 Error in function boost::math::test_function<long double>(long double, long double, long double): Error message goes here...
404 Error in function boost::math::test_function<long double>(long double, long double, long double): Underflow Error
405 Error in function boost::math::test_function<long double>(long double, long double, long double): Error message goes here...
406 Error in function boost::math::test_function<long double>(long double, long double, long double): Denorm Error
407 Error in function boost::math::test_function<long double>(long double, long double, long double): Error while handling value 1.25
408 Error in function boost::math::test_function<long double>(long double, long double, long double): Internal Evaluation Error, best value so far was 1.25
409 Error in function boost::math::test_function<class boost::math::concepts::real_concept>(class boost::math::concepts::real_concept, class boost::math::concepts::real_concept, class boost::math::concepts::real_concept): Error while handling value 0
410 Error in function boost::math::test_function<class boost::math::concepts::real_concept>(class boost::math::concepts::real_concept, class boost::math::concepts::real_concept, class boost::math::concepts::real_concept): Domain Error evaluating function at 0
411 Error in function boost::math::test_function<class boost::math::concepts::real_concept>(class boost::math::concepts::real_concept, class boost::math::concepts::real_concept, class boost::math::concepts::real_concept): Error while handling value 0
412 Error in function boost::math::test_function<class boost::math::concepts::real_concept>(class boost::math::concepts::real_concept, class boost::math::concepts::real_concept, class boost::math::concepts::real_concept): Evaluation of function at pole 0
413 Error in function boost::math::test_function<class boost::math::concepts::real_concept>(class boost::math::concepts::real_concept, class boost::math::concepts::real_concept, class boost::math::concepts::real_concept): Error message goes here...
414 Error in function boost::math::test_function<class boost::math::concepts::real_concept>(class boost::math::concepts::real_concept, class boost::math::concepts::real_concept, class boost::math::concepts::real_concept): Overflow Error
415 Error in function boost::math::test_function<class boost::math::concepts::real_concept>(class boost::math::concepts::real_concept, class boost::math::concepts::real_concept, class boost::math::concepts::real_concept): Error message goes here...
416 Error in function boost::math::test_function<class boost::math::concepts::real_concept>(class boost::math::concepts::real_concept, class boost::math::concepts::real_concept, class boost::math::concepts::real_concept): Underflow Error
417 Error in function boost::math::test_function<class boost::math::concepts::real_concept>(class boost::math::concepts::real_concept, class boost::math::concepts::real_concept, class boost::math::concepts::real_concept): Error message goes here...
418 Error in function boost::math::test_function<class boost::math::concepts::real_concept>(class boost::math::concepts::real_concept, class boost::math::concepts::real_concept, class boost::math::concepts::real_concept): Denorm Error
419 Error in function boost::math::test_function<class boost::math::concepts::real_concept>(class boost::math::concepts::real_concept, class boost::math::concepts::real_concept, class boost::math::concepts::real_concept): Error while handling value 1.25
420 Error in function boost::math::test_function<class boost::math::concepts::real_concept>(class boost::math::concepts::real_concept, class boost::math::concepts::real_concept, class boost::math::concepts::real_concept): Internal Evaluation Error, best value so far was 1.25
421 *** No errors detected
424 ------ Rebuild All started: Project: test_error_handling, Configuration: Release Win32 ------
425 test_error_handling.cpp
427 Finished generating code
428 test_error_handling.vcxproj -> J:\Cpp\MathToolkit\test\Math_test\Release\test_error_handling.exe
429 Running 1 test case...
430 Error in function boost::math::test_function<float>(float, float, float): Error while handling value 0
431 Error in function boost::math::test_function<float>(float, float, float): Domain Error evaluating function at 0
432 Error in function boost::math::test_function<float>(float, float, float): Error while handling value 0
433 Error in function boost::math::test_function<float>(float, float, float): Evaluation of function at pole 0
434 Error in function boost::math::test_function<float>(float, float, float): Error message goes here...
435 Error in function boost::math::test_function<float>(float, float, float): Overflow Error
436 Error in function boost::math::test_function<float>(float, float, float): Error message goes here...
437 Error in function boost::math::test_function<float>(float, float, float): Underflow Error
438 Error in function boost::math::test_function<float>(float, float, float): Error message goes here...
439 Error in function boost::math::test_function<float>(float, float, float): Denorm Error
440 Error in function boost::math::test_function<float>(float, float, float): Error while handling value 1.25
441 Error in function boost::math::test_function<float>(float, float, float): Internal Evaluation Error, best value so far was 1.25
442 Error in function boost::math::test_function<float>(float, float, float): Error while handling value 1.25
443 Error in function boost::math::test_function<float>(float, float, float): Indeterminate result with value 1.25
444 Error in function boost::math::test_function<double>(double, double, double): Error while handling value 0
445 Error in function boost::math::test_function<double>(double, double, double): Domain Error evaluating function at 0
446 Error in function boost::math::test_function<double>(double, double, double): Error while handling value 0
447 Error in function boost::math::test_function<double>(double, double, double): Evaluation of function at pole 0
448 Error in function boost::math::test_function<double>(double, double, double): Error message goes here...
449 Error in function boost::math::test_function<double>(double, double, double): Overflow Error
450 Error in function boost::math::test_function<double>(double, double, double): Error message goes here...
451 Error in function boost::math::test_function<double>(double, double, double): Underflow Error
452 Error in function boost::math::test_function<double>(double, double, double): Error message goes here...
453 Error in function boost::math::test_function<double>(double, double, double): Denorm Error
454 Error in function boost::math::test_function<double>(double, double, double): Error while handling value 1.25
455 Error in function boost::math::test_function<double>(double, double, double): Internal Evaluation Error, best value so far was 1.25
456 Error in function boost::math::test_function<double>(double, double, double): Error while handling value 1.25
457 Error in function boost::math::test_function<double>(double, double, double): Indeterminate result with value 1.25
458 Error in function boost::math::test_function<long double>(long double, long double, long double): Error while handling value 0
459 Error in function boost::math::test_function<long double>(long double, long double, long double): Domain Error evaluating function at 0
460 Error in function boost::math::test_function<long double>(long double, long double, long double): Error while handling value 0
461 Error in function boost::math::test_function<long double>(long double, long double, long double): Evaluation of function at pole 0
462 Error in function boost::math::test_function<long double>(long double, long double, long double): Error message goes here...
463 Error in function boost::math::test_function<long double>(long double, long double, long double): Overflow Error
464 Error in function boost::math::test_function<long double>(long double, long double, long double): Error message goes here...
465 Error in function boost::math::test_function<long double>(long double, long double, long double): Underflow Error
466 Error in function boost::math::test_function<long double>(long double, long double, long double): Error message goes here...
467 Error in function boost::math::test_function<long double>(long double, long double, long double): Denorm Error
468 Error in function boost::math::test_function<long double>(long double, long double, long double): Error while handling value 1.25
469 Error in function boost::math::test_function<long double>(long double, long double, long double): Internal Evaluation Error, best value so far was 1.25
470 Error in function boost::math::test_function<long double>(long double, long double, long double): Error while handling value 1.25
471 Error in function boost::math::test_function<long double>(long double, long double, long double): Indeterminate result with value 1.25
472 Error in function boost::math::test_function<class boost::math::concepts::real_concept>(class boost::math::concepts::real_concept, class boost::math::concepts::real_concept, class boost::math::concepts::real_concept): Error while handling value 0
473 Error in function boost::math::test_function<class boost::math::concepts::real_concept>(class boost::math::concepts::real_concept, class boost::math::concepts::real_concept, class boost::math::concepts::real_concept): Domain Error evaluating function at 0
474 Error in function boost::math::test_function<class boost::math::concepts::real_concept>(class boost::math::concepts::real_concept, class boost::math::concepts::real_concept, class boost::math::concepts::real_concept): Error while handling value 0
475 Error in function boost::math::test_function<class boost::math::concepts::real_concept>(class boost::math::concepts::real_concept, class boost::math::concepts::real_concept, class boost::math::concepts::real_concept): Evaluation of function at pole 0
476 Error in function boost::math::test_function<class boost::math::concepts::real_concept>(class boost::math::concepts::real_concept, class boost::math::concepts::real_concept, class boost::math::concepts::real_concept): Error message goes here...
477 Error in function boost::math::test_function<class boost::math::concepts::real_concept>(class boost::math::concepts::real_concept, class boost::math::concepts::real_concept, class boost::math::concepts::real_concept): Overflow Error
478 Error in function boost::math::test_function<class boost::math::concepts::real_concept>(class boost::math::concepts::real_concept, class boost::math::concepts::real_concept, class boost::math::concepts::real_concept): Error message goes here...
479 Error in function boost::math::test_function<class boost::math::concepts::real_concept>(class boost::math::concepts::real_concept, class boost::math::concepts::real_concept, class boost::math::concepts::real_concept): Underflow Error
480 Error in function boost::math::test_function<class boost::math::concepts::real_concept>(class boost::math::concepts::real_concept, class boost::math::concepts::real_concept, class boost::math::concepts::real_concept): Error message goes here...
481 Error in function boost::math::test_function<class boost::math::concepts::real_concept>(class boost::math::concepts::real_concept, class boost::math::concepts::real_concept, class boost::math::concepts::real_concept): Denorm Error
482 Error in function boost::math::test_function<class boost::math::concepts::real_concept>(class boost::math::concepts::real_concept, class boost::math::concepts::real_concept, class boost::math::concepts::real_concept): Error while handling value 1.25
483 Error in function boost::math::test_function<class boost::math::concepts::real_concept>(class boost::math::concepts::real_concept, class boost::math::concepts::real_concept, class boost::math::concepts::real_concept): Internal Evaluation Error, best value so far was 1.25
484 Error in function boost::math::test_function<class boost::math::concepts::real_concept>(class boost::math::concepts::real_concept, class boost::math::concepts::real_concept, class boost::math::concepts::real_concept): Error while handling value 1.25
486 *** No errors detected
487 Error in function boost::math::test_function<class boost::math::concepts::real_concept>(class boost::math::concepts::real_concept, class boost::math::concepts::real_concept, class boost::math::concepts::real_concept): Indeterminate result with value 1.25
488 ========== Rebuild All: 1 succeeded, 0 failed, 0 skipped ==========