test_cbrt.hpp 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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. #include <boost/math/concepts/real_concept.hpp>
  7. #define BOOST_TEST_MAIN
  8. #include <boost/test/unit_test.hpp>
  9. #include <boost/test/tools/floating_point_comparison.hpp>
  10. #include <boost/math/tools/stats.hpp>
  11. #include <boost/math/tools/test.hpp>
  12. #include <boost/type_traits/is_floating_point.hpp>
  13. #include <boost/array.hpp>
  14. #include <boost/math/special_functions/math_fwd.hpp>
  15. #include "functor.hpp"
  16. #include "handle_test_result.hpp"
  17. #include "table_type.hpp"
  18. #ifndef SC_
  19. #define SC_(x) static_cast<typename table_type<T>::type>(BOOST_JOIN(x, L))
  20. #endif
  21. template <class Real>
  22. struct negative_cbrt
  23. {
  24. negative_cbrt(){}
  25. template <class S>
  26. Real operator()(const S& row)
  27. {
  28. return boost::math::cbrt(Real(-Real(row[1])));
  29. }
  30. };
  31. template <class Real, class T>
  32. void do_test_cbrt(const T& data, const char* type_name, const char* test_name)
  33. {
  34. #if !(defined(ERROR_REPORTING_MODE) && !defined(CBRT_FUNCTION_TO_TEST))
  35. typedef Real value_type;
  36. typedef value_type (*pg)(value_type);
  37. #ifdef CBRT_FUNCTION_TO_TEST
  38. pg funcp = boost::math::cbrt<value_type>;
  39. #elif defined(BOOST_MATH_NO_DEDUCED_FUNCTION_POINTERS)
  40. pg funcp = boost::math::cbrt<value_type>;
  41. #else
  42. pg funcp = boost::math::cbrt;
  43. #endif
  44. boost::math::tools::test_result<value_type> result;
  45. std::cout << "Testing " << test_name << " with type " << type_name
  46. << "\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n";
  47. //
  48. // test cbrt against data:
  49. //
  50. result = boost::math::tools::test_hetero<Real>(
  51. data,
  52. bind_func<Real>(funcp, 1),
  53. extract_result<Real>(0));
  54. result += boost::math::tools::test_hetero<Real>(
  55. data,
  56. negative_cbrt<Real>(),
  57. negate<Real>(extract_result<Real>(0)));
  58. handle_test_result(result, data[result.worst()], result.worst(), type_name, "cbrt", test_name);
  59. std::cout << std::endl;
  60. #endif
  61. }
  62. template <class T>
  63. void test_cbrt(T, const char* name)
  64. {
  65. //
  66. // The actual test data is rather verbose, so it's in a separate file.
  67. //
  68. // The contents are as follows, each row of data contains
  69. // three items, input value a, input value b and erf(a, b):
  70. //
  71. # include "cbrt_data.ipp"
  72. do_test_cbrt<T>(cbrt_data, name, "cbrt Function");
  73. }