test_hermite.hpp 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. // Copyright John Maddock 2006.
  2. // Copyright Paul A. Bristow 2007, 2009
  3. // Use, modification and distribution are subject to the
  4. // Boost Software License, Version 1.0. (See accompanying file
  5. // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  6. #ifdef _MSC_VER
  7. # pragma warning(disable : 4127) // conditional expression is constant
  8. # pragma warning(disable : 4512) // assignment operator could not be generated
  9. # pragma warning(disable : 4756) // overflow in constant arithmetic
  10. // Constants are too big for float case, but this doesn't matter for test.
  11. #endif
  12. #include <boost/math/concepts/real_concept.hpp>
  13. #define BOOST_TEST_MAIN
  14. #include <boost/test/unit_test.hpp>
  15. #include <boost/test/tools/floating_point_comparison.hpp>
  16. #include <boost/math/special_functions/math_fwd.hpp>
  17. #include <boost/math/constants/constants.hpp>
  18. #include <boost/array.hpp>
  19. #include "functor.hpp"
  20. #include "handle_test_result.hpp"
  21. #include "table_type.hpp"
  22. #ifndef SC_
  23. #define SC_(x) static_cast<typename table_type<T>::type>(BOOST_JOIN(x, L))
  24. #endif
  25. template <class Real, class T>
  26. void do_test_hermite(const T& data, const char* type_name, const char* test_name)
  27. {
  28. #if !(defined(ERROR_REPORTING_MODE) && !defined(HERMITE_FUNCTION_TO_TEST))
  29. typedef Real value_type;
  30. typedef value_type (*pg)(unsigned, value_type);
  31. #ifdef HERMITE_FUNCTION_TO_TEST
  32. pg funcp = HERMITE_FUNCTION_TO_TEST;
  33. #elif defined(BOOST_MATH_NO_DEDUCED_FUNCTION_POINTERS)
  34. pg funcp = boost::math::hermite<value_type>;
  35. #else
  36. pg funcp = boost::math::hermite;
  37. #endif
  38. boost::math::tools::test_result<value_type> result;
  39. std::cout << "Testing " << test_name << " with type " << type_name
  40. << "\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n";
  41. //
  42. // test hermite against data:
  43. //
  44. result = boost::math::tools::test_hetero<Real>(
  45. data,
  46. bind_func_int1<Real>(funcp, 0, 1),
  47. extract_result<Real>(2));
  48. handle_test_result(result, data[result.worst()], result.worst(), type_name, "hermite", test_name);
  49. std::cout << std::endl;
  50. #endif
  51. }
  52. template <class T>
  53. void test_hermite(T, const char* name)
  54. {
  55. //
  56. // The actual test data is rather verbose, so it's in a separate file
  57. //
  58. // The contents are as follows, each row of data contains
  59. // three items, input value a, input value b and erf(a, b):
  60. //
  61. # include "hermite.ipp"
  62. do_test_hermite<T>(hermite, name, "Hermite Polynomials");
  63. }
  64. template <class T>
  65. void test_spots(T, const char* t)
  66. {
  67. std::cout << "Testing basic sanity checks for type " << t << std::endl;
  68. //
  69. // basic sanity checks, tolerance is 100 epsilon:
  70. // These spots were generated by MathCAD, precision is
  71. // 14-16 digits.
  72. //
  73. T tolerance = (std::max)(boost::math::tools::epsilon<T>() * 100, static_cast<T>(1e-14));
  74. BOOST_CHECK_CLOSE_FRACTION(::boost::math::hermite(0, static_cast<T>(1)), static_cast<T>(1.L), tolerance);
  75. BOOST_CHECK_CLOSE_FRACTION(::boost::math::hermite(1, static_cast<T>(1)), static_cast<T>(2.L), tolerance);
  76. BOOST_CHECK_CLOSE_FRACTION(::boost::math::hermite(1, static_cast<T>(2)), static_cast<T>(4.L), tolerance);
  77. BOOST_CHECK_CLOSE_FRACTION(::boost::math::hermite(1, static_cast<T>(10)), static_cast<T>(20), tolerance);
  78. BOOST_CHECK_CLOSE_FRACTION(::boost::math::hermite(1, static_cast<T>(100)), static_cast<T>(200), tolerance);
  79. BOOST_CHECK_CLOSE_FRACTION(::boost::math::hermite(1, static_cast<T>(1e6)), static_cast<T>(2e6), tolerance);
  80. if(std::numeric_limits<T>::max_exponent >= std::numeric_limits<double>::max_exponent)
  81. {
  82. BOOST_CHECK_CLOSE_FRACTION(::boost::math::hermite(1, static_cast<T>(1e307)), static_cast<T>(2e307), tolerance);
  83. BOOST_CHECK_CLOSE_FRACTION(::boost::math::hermite(99, static_cast<T>(100)), static_cast<T>(4.967223743011310E+227L), tolerance);
  84. }
  85. BOOST_CHECK_CLOSE_FRACTION(::boost::math::hermite(10, static_cast<T>(30)), static_cast<T>(5.896624628001300E+17L), tolerance);
  86. BOOST_CHECK_CLOSE_FRACTION(::boost::math::hermite(10, static_cast<T>(1000)), static_cast<T>(1.023976960161280E+33L), tolerance);
  87. BOOST_CHECK_CLOSE_FRACTION(::boost::math::hermite(10, static_cast<T>(10)), static_cast<T>(8.093278209760000E+12L), tolerance);
  88. BOOST_CHECK_CLOSE_FRACTION(::boost::math::hermite(10, static_cast<T>(-10)), static_cast<T>(8.093278209760000E+12L), tolerance);
  89. BOOST_CHECK_CLOSE_FRACTION(::boost::math::hermite(3, static_cast<T>(-10)), static_cast<T>(-7.880000000000000E+3L), tolerance);
  90. BOOST_CHECK_CLOSE_FRACTION(::boost::math::hermite(3, static_cast<T>(-1000)), static_cast<T>(-7.999988000000000E+9L), tolerance);
  91. BOOST_CHECK_CLOSE_FRACTION(::boost::math::hermite(3, static_cast<T>(-1000000)), static_cast<T>(-7.999999999988000E+18L), tolerance);
  92. }