From 6a3a89bfd11cd52a4582553abd9e259eea9f2ec3 Mon Sep 17 00:00:00 2001 From: Matt Borland Date: Thu, 11 May 2023 14:36:24 +0200 Subject: [PATCH] Add testing to quadrature --- test/exp_sinh_quadrature_test.cpp | 22 ++++ test/gauss_kronrod_quadrature_test.cpp | 27 +++++ test/gauss_quadrature_test.cpp | 23 ++++ test/naive_monte_carlo_test.cpp | 160 +++++++++++++++++++++++++ test/test_trapezoidal.cpp | 41 +++++++ 5 files changed, 273 insertions(+) diff --git a/test/exp_sinh_quadrature_test.cpp b/test/exp_sinh_quadrature_test.cpp index da0c3a548..d39ec4c5d 100644 --- a/test/exp_sinh_quadrature_test.cpp +++ b/test/exp_sinh_quadrature_test.cpp @@ -29,6 +29,10 @@ #include #endif +#if __has_include() +# include +#endif + using std::exp; using std::cos; using std::tan; @@ -586,17 +590,35 @@ BOOST_AUTO_TEST_CASE(exp_sinh_quadrature_test) */ #ifdef TEST1 + +#ifdef __STDCPP_FLOAT32_T__ + test_left_limit_infinite(); + test_right_limit_infinite(); + test_nr_examples(); + test_crc(); +#else test_left_limit_infinite(); test_right_limit_infinite(); test_nr_examples(); test_crc(); #endif + +#endif #ifdef TEST2 + +#ifdef __STDCPP_FLOAT64_T__ + test_left_limit_infinite(); + test_right_limit_infinite(); + test_nr_examples(); + test_crc(); +#else test_left_limit_infinite(); test_right_limit_infinite(); test_nr_examples(); test_crc(); #endif + +#endif #ifndef BOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS #ifdef TEST3 #ifndef BOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS diff --git a/test/gauss_kronrod_quadrature_test.cpp b/test/gauss_kronrod_quadrature_test.cpp index 3ee9c8574..5877146d7 100644 --- a/test/gauss_kronrod_quadrature_test.cpp +++ b/test/gauss_kronrod_quadrature_test.cpp @@ -38,6 +38,10 @@ #pragma warning(disable:4127) // Conditional expression is constant #endif +#if __has_include() +# include +#endif + using std::expm1; using std::atan; using std::tan; @@ -456,6 +460,16 @@ BOOST_AUTO_TEST_CASE(gauss_quadrature_test) { #ifdef TEST1 std::cout << "Testing 15 point approximation:\n"; + +#ifdef __STDCPP_FLOAT64_T__ + test_linear(); + test_quadratic(); + test_ca(); + test_three_quadrature_schemes_examples(); + test_integration_over_real_line(); + test_right_limit_infinite(); + test_left_limit_infinite(); +#else test_linear(); test_quadratic(); test_ca(); @@ -463,9 +477,20 @@ BOOST_AUTO_TEST_CASE(gauss_quadrature_test) test_integration_over_real_line(); test_right_limit_infinite(); test_left_limit_infinite(); +#endif // test one case where we do not have pre-computed constants: std::cout << "Testing 17 point approximation:\n"; + +#ifdef __STDCPP_FLOAT64_T__ + test_linear(); + test_quadratic(); + test_ca(); + test_three_quadrature_schemes_examples(); + test_integration_over_real_line(); + test_right_limit_infinite(); + test_left_limit_infinite(); +#else test_linear(); test_quadratic(); test_ca(); @@ -473,6 +498,8 @@ BOOST_AUTO_TEST_CASE(gauss_quadrature_test) test_integration_over_real_line(); test_right_limit_infinite(); test_left_limit_infinite(); +#endif + test_complex_lambert_w>(); test_complex_lambert_w>(); #endif diff --git a/test/gauss_quadrature_test.cpp b/test/gauss_quadrature_test.cpp index e1d61243e..91eca9ec2 100644 --- a/test/gauss_quadrature_test.cpp +++ b/test/gauss_quadrature_test.cpp @@ -31,6 +31,10 @@ #pragma warning(disable:4127) // Conditional expression is constant #endif +#if __has_include() +# include +#endif + #if !defined(TEST1) && !defined(TEST2) && !defined(TEST3) # define TEST1 # define TEST2 @@ -445,6 +449,24 @@ BOOST_AUTO_TEST_CASE(gauss_quadrature_test) { #ifdef TEST1 + +#ifdef __STDCPP_FLOAT64_T__ + test_linear(); + test_quadratic(); + test_ca(); + test_three_quadrature_schemes_examples(); + test_integration_over_real_line(); + test_right_limit_infinite(); + test_left_limit_infinite(); + + test_linear(); + test_quadratic(); + test_ca(); + test_three_quadrature_schemes_examples(); + test_integration_over_real_line(); + test_right_limit_infinite(); + test_left_limit_infinite(); +#else test_linear(); test_quadratic(); test_ca(); @@ -460,6 +482,7 @@ BOOST_AUTO_TEST_CASE(gauss_quadrature_test) test_integration_over_real_line(); test_right_limit_infinite(); test_left_limit_infinite(); +#endif #if LDBL_MANT_DIG < 100 && defined(BOOST_MATH_RUN_MP_TESTS) test_linear(); diff --git a/test/naive_monte_carlo_test.cpp b/test/naive_monte_carlo_test.cpp index 358ebdd0a..47e8f54ba 100644 --- a/test/naive_monte_carlo_test.cpp +++ b/test/naive_monte_carlo_test.cpp @@ -16,6 +16,10 @@ #include #include +#if __has_include() +# include +#endif + using std::abs; using std::vector; using std::pair; @@ -452,93 +456,249 @@ BOOST_AUTO_TEST_CASE(naive_monte_carlo_test) { std::cout << "Default hardware concurrency = " << std::thread::hardware_concurrency() << std::endl; #if !defined(TEST) || TEST == 1 + +#if defined(__STDCPP_FLOAT32_T__) && defined(__STDCPP_FLOAT64_T__) + test_finite_singular_boundary(); + test_finite_singular_boundary(); +#else test_finite_singular_boundary(); test_finite_singular_boundary(); #endif + +#endif #if !defined(TEST) || TEST == 2 + +#if defined(__STDCPP_FLOAT32_T__) && defined(__STDCPP_FLOAT64_T__) + test_pi(); + test_pi(); +#else test_pi(); test_pi(); #endif + +#endif #if !defined(TEST) || TEST == 3 + +#ifdef __STDCPP_FLOAT32_T__ + test_pi_multithreaded(); + test_constant(); +#else test_pi_multithreaded(); test_constant(); +#endif + #endif //test_pi(); #if !defined(TEST) || TEST == 4 + +#if defined(__STDCPP_FLOAT32_T__) && defined(__STDCPP_FLOAT64_T__) + test_constant(); + test_cancel_and_restart(); +#else test_constant(); //test_constant(); test_cancel_and_restart(); #endif + +#endif #if !defined(TEST) || TEST == 5 + +#ifdef __STDCPP_FLOAT32_T__ + test_exception_from_integrand(); + test_variance(); +#else test_exception_from_integrand(); test_variance(); #endif + +#endif #if !defined(TEST) || TEST == 6 + +#ifdef __STDCPP_FLOAT64_T__ + test_variance(); + test_multithreaded_variance(); +#else test_variance(); test_multithreaded_variance(); #endif + +#endif #if !defined(TEST) || TEST == 7 + +#ifdef __STDCPP_FLOAT32_T__ + test_product(); + test_product(); +#else test_product(); test_product(); #endif + +#endif #if !defined(TEST) || TEST == 8 + +#ifdef __STDCPP_FLOAT32_T__ + test_product(); + test_product(); + test_product(); +#else test_product(); test_product(); test_product(); #endif + +#endif #if !defined(TEST) || TEST == 9 + +#if defined(__STDCPP_FLOAT32_T__) && defined(__STDCPP_FLOAT64_T__) + test_product(); + test_product(); +#else test_product(); test_product(); #endif + +#endif #if !defined(TEST) || TEST == 10 + +#ifdef __STDCPP_FLOAT64_T__ + test_product(); +#else test_product(); #endif + +#endif #if !defined(TEST) || TEST == 11 + +#ifdef __STDCPP_FLOAT64_T__ + test_product(); + test_product(); +#else test_product(); test_product(); #endif + +#endif #if !defined(TEST) || TEST == 12 + +#if defined(__STDCPP_FLOAT32_T__) && defined(__STDCPP_FLOAT64_T__) + test_upper_bound_infinite(); + test_upper_bound_infinite(); +#else test_upper_bound_infinite(); test_upper_bound_infinite(); #endif + +#endif #if !defined(TEST) || TEST == 13 + +#if defined(__STDCPP_FLOAT32_T__) && defined(__STDCPP_FLOAT64_T__) + test_lower_bound_infinite(); + test_lower_bound_infinite(); +#else test_lower_bound_infinite(); test_lower_bound_infinite(); #endif + +#endif #if !defined(TEST) || TEST == 14 + +#ifdef __STDCPP_FLOAT32_T__ + test_lower_bound_infinite2(); +#else test_lower_bound_infinite2(); #endif + +#endif #if !defined(TEST) || TEST == 15 + +#if defined(__STDCPP_FLOAT32_T__) && defined(__STDCPP_FLOAT64_T__) + test_double_infinite(); + test_double_infinite(); +#else test_double_infinite(); test_double_infinite(); #endif + +#endif #if !defined(TEST) || TEST == 16 + +#ifdef __STDCPP_FLOAT32_T__ + test_radovic(); + test_radovic(); +#else test_radovic(); test_radovic(); #endif + +#endif #if !defined(TEST) || TEST == 17 + +#if defined(__STDCPP_FLOAT32_T__) && defined(__STDCPP_FLOAT64_T__) + test_radovic(); + test_radovic(); +#else test_radovic(); test_radovic(); #endif + +#endif #if !defined(TEST) || TEST == 18 + +#ifdef __STDCPP_FLOAT64_T__ + test_radovic(); + test_radovic(); +#else test_radovic(); test_radovic(); #endif + +#endif #if !defined(TEST) || TEST == 19 + +#ifdef __STDCPP_FLOAT64_T__ + test_radovic(); + test_radovic(); +#else test_radovic(); test_radovic(); #endif + +#endif #if !defined(TEST) || TEST == 20 + +#ifdef __STDCPP_FLOAT32_T__ + test_alternative_rng_1(); +#else test_alternative_rng_1(); #endif + +#endif #if !defined(TEST) || TEST == 21 + +#ifdef __STDCPP_FLOAT64_T__ + test_alternative_rng_1(); +#else test_alternative_rng_1(); #endif + +#endif #if !defined(TEST) || TEST == 22 + +#ifdef __STDCPP_FLOAT32_T__ + test_alternative_rng_2(); +#else test_alternative_rng_2(); #endif + +#endif #if !defined(TEST) || TEST == 23 + +#ifdef __STDCPP_FLOAT64_T__ + test_alternative_rng_2(); +#else test_alternative_rng_2(); #endif +#endif + } diff --git a/test/test_trapezoidal.cpp b/test/test_trapezoidal.cpp index dc5eb88ac..ed8eeb3de 100644 --- a/test/test_trapezoidal.cpp +++ b/test/test_trapezoidal.cpp @@ -21,6 +21,11 @@ #ifdef BOOST_HAS_FLOAT128 #include #endif + +#if __has_include() +# include +#endif + using boost::multiprecision::cpp_bin_float_50; using boost::multiprecision::cpp_bin_float_100; using boost::math::quadrature::trapezoidal; @@ -230,8 +235,14 @@ void test_rational_sin() BOOST_AUTO_TEST_CASE(trapezoidal_quadrature) { + +#if defined(__STDCPP_FLOAT32_T__) && defined(__STDCPP_FLOAT64_T__) + test_constant(); + test_constant(); +#else test_constant(); test_constant(); +#endif #ifndef BOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS test_constant(); #endif @@ -241,8 +252,13 @@ BOOST_AUTO_TEST_CASE(trapezoidal_quadrature) test_constant(); test_constant(); +#if defined(__STDCPP_FLOAT32_T__) && defined(__STDCPP_FLOAT64_T__) + test_rational_periodic(); + test_rational_periodic(); +#else test_rational_periodic(); test_rational_periodic(); +#endif #ifndef BOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS test_rational_periodic(); #endif @@ -255,8 +271,13 @@ BOOST_AUTO_TEST_CASE(trapezoidal_quadrature) test_rational_periodic(); #endif +#if defined(__STDCPP_FLOAT32_T__) && defined(__STDCPP_FLOAT64_T__) + test_bump_function(); + test_bump_function(); +#else test_bump_function(); test_bump_function(); +#endif #ifndef BOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS test_bump_function(); #endif @@ -268,8 +289,13 @@ BOOST_AUTO_TEST_CASE(trapezoidal_quadrature) test_rational_periodic(); #endif +#if defined(__STDCPP_FLOAT32_T__) && defined(__STDCPP_FLOAT64_T__) + test_zero_function(); + test_zero_function(); +#else test_zero_function(); test_zero_function(); +#endif #ifndef BOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS test_zero_function(); #endif @@ -282,8 +308,13 @@ BOOST_AUTO_TEST_CASE(trapezoidal_quadrature) test_zero_function(); #endif +#if defined(__STDCPP_FLOAT32_T__) && defined(__STDCPP_FLOAT64_T__) + test_sinsq(); + test_sinsq(); +#else test_sinsq(); test_sinsq(); +#endif #ifndef BOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS test_sinsq(); #endif @@ -296,8 +327,13 @@ BOOST_AUTO_TEST_CASE(trapezoidal_quadrature) test_sinsq(); #endif +#if defined(__STDCPP_FLOAT32_T__) && defined(__STDCPP_FLOAT64_T__) + test_slowly_converging(); + test_slowly_converging(); +#else test_slowly_converging(); test_slowly_converging(); +#endif #ifndef BOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS test_slowly_converging(); #endif @@ -305,8 +341,13 @@ BOOST_AUTO_TEST_CASE(trapezoidal_quadrature) test_slowly_converging(); #endif +#if defined(__STDCPP_FLOAT32_T__) && defined(__STDCPP_FLOAT64_T__) + test_rational_sin(); + test_rational_sin(); +#else test_rational_sin(); test_rational_sin(); +#endif #ifndef BOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS test_rational_sin(); #endif