📄 test_error_handling.cpp
字号:
TEST_EXCEPTION(boost::math::policies::raise_overflow_error<T>(func, msg2, throw_policy), std::overflow_error); TEST_EXCEPTION(boost::math::policies::raise_overflow_error<T>(func, 0, throw_policy), std::overflow_error); TEST_EXCEPTION(boost::math::policies::raise_underflow_error<T>(func, msg2, throw_policy), std::underflow_error); TEST_EXCEPTION(boost::math::policies::raise_underflow_error<T>(func, 0, throw_policy), std::underflow_error); TEST_EXCEPTION(boost::math::policies::raise_denorm_error<T>(func, msg2, T(0), throw_policy), std::underflow_error); TEST_EXCEPTION(boost::math::policies::raise_denorm_error<T>(func, 0, T(0), throw_policy), std::underflow_error); TEST_EXCEPTION(boost::math::policies::raise_evaluation_error(func, msg1, T(1.25), throw_policy), boost::math::evaluation_error); TEST_EXCEPTION(boost::math::policies::raise_evaluation_error(func, 0, T(1.25), throw_policy), boost::math::evaluation_error); TEST_EXCEPTION(boost::math::policies::raise_indeterminate_result_error(func, msg1, T(1.25), T(12.34), throw_policy), std::domain_error); TEST_EXCEPTION(boost::math::policies::raise_indeterminate_result_error(func, 0, T(1.25), T(12.34), throw_policy), std::domain_error); // // Now try user error handlers: these should all throw user_error(): // - because by design these are undefined and must be defined by the user ;-) BOOST_CHECK_THROW(boost::math::policies::raise_domain_error(func, msg1, T(0.0), user_policy), user_defined_error); BOOST_CHECK_THROW(boost::math::policies::raise_pole_error(func, msg1, T(0.0), user_policy), user_defined_error); BOOST_CHECK_THROW(boost::math::policies::raise_overflow_error<T>(func, msg2, user_policy), user_defined_error); BOOST_CHECK_THROW(boost::math::policies::raise_underflow_error<T>(func, msg2, user_policy), user_defined_error); BOOST_CHECK_THROW(boost::math::policies::raise_denorm_error<T>(func, msg2, T(0), user_policy), user_defined_error); BOOST_CHECK_THROW(boost::math::policies::raise_evaluation_error(func, msg1, T(0.0), user_policy), user_defined_error); BOOST_CHECK_THROW(boost::math::policies::raise_indeterminate_result_error(func, msg1, T(0.0), T(0.0), user_policy), user_defined_error); // Test with ignore_error 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); 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); 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>()); BOOST_CHECK_EQUAL(boost::math::policies::raise_underflow_error<T>(func, msg2, ignore_policy), T(0)); BOOST_CHECK_EQUAL(boost::math::policies::raise_denorm_error<T>(func, msg2, T(1.25), ignore_policy), T(1.25)); BOOST_CHECK_EQUAL(boost::math::policies::raise_evaluation_error(func, msg1, T(1.25), ignore_policy), T(1.25)); BOOST_CHECK_EQUAL(boost::math::policies::raise_indeterminate_result_error(func, 0, T(0.0), T(12.34), ignore_policy), T(12.34)); // Test with errno_on_error errno = 0; 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); BOOST_CHECK(errno == EDOM); errno = 0; 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); BOOST_CHECK(errno == EDOM); errno = 0; 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>()); BOOST_CHECK_EQUAL(errno, ERANGE); errno = 0; BOOST_CHECK_EQUAL(boost::math::policies::raise_underflow_error<T>(func, msg2, errno_policy), T(0)); BOOST_CHECK_EQUAL(errno, ERANGE); errno = 0; BOOST_CHECK_EQUAL(boost::math::policies::raise_denorm_error<T>(func, msg2, T(1.25), errno_policy), T(1.25)); BOOST_CHECK_EQUAL(errno, ERANGE); errno = 0; BOOST_CHECK_EQUAL(boost::math::policies::raise_evaluation_error(func, msg1, T(1.25), errno_policy), T(1.25)); BOOST_CHECK(errno == EDOM); errno = 0; BOOST_CHECK(boost::math::policies::raise_indeterminate_result_error(func, 0, T(0.0), T(12.34), errno_policy) == T(12.34)); BOOST_CHECK_EQUAL(errno, EDOM);}int test_main(int, char* []){ // Test error handling. // (Parameter value, arbitrarily zero, only communicates the floating point type FPT). test_error(0.0F); // Test float. test_error(0.0); // Test double. test_error(0.0L); // Test long double. test_error(boost::math::concepts::real_concept(0.0L)); // Test concepts. return 0;} // int test_main(int, char* [])/*Autorun "i:\boost-06-05-03-1300\libs\math\test\Math_test\debug\test_error_handling.exe"Running 1 test case...Error in function boost::math::test_function<float>(float, float, float): Error while handling value 0Error in function boost::math::test_function<float>(float, float, float): Domain Error evaluating function at 0Error in function boost::math::test_function<float>(float, float, float): Error while handling value 0Error in function boost::math::test_function<float>(float, float, float): Evaluation of function at pole 0Error in function boost::math::test_function<float>(float, float, float): Error message goes here...Error in function boost::math::test_function<float>(float, float, float): Overflow ErrorError in function boost::math::test_function<float>(float, float, float): Error message goes here...Error in function boost::math::test_function<float>(float, float, float): Underflow ErrorError in function boost::math::test_function<float>(float, float, float): Error message goes here...Error in function boost::math::test_function<float>(float, float, float): Denorm ErrorError in function boost::math::test_function<float>(float, float, float): Error while handling value 1.25Error in function boost::math::test_function<float>(float, float, float): Internal Evaluation Error, best value so far was 1.25Error in function boost::math::test_function<double>(double, double, double): Error while handling value 0Error in function boost::math::test_function<double>(double, double, double): Domain Error evaluating function at 0Error in function boost::math::test_function<double>(double, double, double): Error while handling value 0Error in function boost::math::test_function<double>(double, double, double): Evaluation of function at pole 0Error in function boost::math::test_function<double>(double, double, double): Error message goes here...Error in function boost::math::test_function<double>(double, double, double): Overflow ErrorError in function boost::math::test_function<double>(double, double, double): Error message goes here...Error in function boost::math::test_function<double>(double, double, double): Underflow ErrorError in function boost::math::test_function<double>(double, double, double): Error message goes here...Error in function boost::math::test_function<double>(double, double, double): Denorm ErrorError in function boost::math::test_function<double>(double, double, double): Error while handling value 1.25Error in function boost::math::test_function<double>(double, double, double): Internal Evaluation Error, best value so far was 1.25Error in function boost::math::test_function<long double>(long double, long double, long double): Error while handling value 0Error in function boost::math::test_function<long double>(long double, long double, long double): Domain Error evaluating function at 0Error in function boost::math::test_function<long double>(long double, long double, long double): Error while handling value 0Error in function boost::math::test_function<long double>(long double, long double, long double): Evaluation of function at pole 0Error in function boost::math::test_function<long double>(long double, long double, long double): Error message goes here...Error in function boost::math::test_function<long double>(long double, long double, long double): Overflow ErrorError in function boost::math::test_function<long double>(long double, long double, long double): Error message goes here...Error in function boost::math::test_function<long double>(long double, long double, long double): Underflow ErrorError in function boost::math::test_function<long double>(long double, long double, long double): Error message goes here...Error in function boost::math::test_function<long double>(long double, long double, long double): Denorm ErrorError in function boost::math::test_function<long double>(long double, long double, long double): Error while handling value 1.25Error in function boost::math::test_function<long double>(long double, long double, long double): Internal Evaluation Error, best value so far was 1.25Error 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 0Error 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 0Error 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 0Error 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 0Error 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...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 ErrorError 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...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 ErrorError 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...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 ErrorError 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.25Error 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*** No errors detected*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -