test_trig.hpp 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. // Copyright John Maddock 2014.
  2. // Use, modification and distribution are subject to the
  3. // Boost Software License, Version 1.0. (See accompanying file
  4. // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  5. #include <boost/math/concepts/real_concept.hpp>
  6. #define BOOST_TEST_MAIN
  7. #include <boost/test/unit_test.hpp>
  8. #include <boost/test/tools/floating_point_comparison.hpp>
  9. #include <boost/math/special_functions/math_fwd.hpp>
  10. #include <boost/math/constants/constants.hpp>
  11. #include <boost/type_traits/is_floating_point.hpp>
  12. #include <boost/array.hpp>
  13. #include "functor.hpp"
  14. #include "handle_test_result.hpp"
  15. #include "table_type.hpp"
  16. #ifndef SC_
  17. #define SC_(x) static_cast<typename table_type<T>::type>(BOOST_JOIN(x, L))
  18. #endif
  19. template <class Real, class T>
  20. void do_test_trig(const T& data, const char* type_name, const char* test_name)
  21. {
  22. #if !(defined(ERROR_REPORTING_MODE) && !defined(SIN_PI_RATIO_FUNCTION_TO_TEST))
  23. typedef Real value_type;
  24. typedef value_type (*pg)(value_type);
  25. #ifdef SIN_PI_RATIO_FUNCTION_TO_TEST
  26. pg funcp = SIN_PI_RATIO_FUNCTION_TO_TEST;
  27. #elif defined(BOOST_MATH_NO_DEDUCED_FUNCTION_POINTERS)
  28. pg funcp = boost::math::sin_pi<value_type>;
  29. #else
  30. pg funcp = boost::math::sin_pi;
  31. #endif
  32. boost::math::tools::test_result<value_type> result;
  33. std::cout << "Testing " << test_name << " with type " << type_name
  34. << "\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n";
  35. //
  36. // test sin_pi against data:
  37. //
  38. result = boost::math::tools::test_hetero<Real>(
  39. data,
  40. bind_func<Real>(funcp, 0),
  41. extract_result<Real>(1));
  42. handle_test_result(result, data[result.worst()], result.worst(), type_name, "sin_pi", test_name);
  43. //
  44. // test cos_pi against data:
  45. //
  46. #ifdef COS_PI_RATIO_FUNCTION_TO_TEST
  47. funcp = COS_PI_RATIO_FUNCTION_TO_TEST;
  48. #elif defined(BOOST_MATH_NO_DEDUCED_FUNCTION_POINTERS)
  49. funcp = boost::math::cos_pi<value_type>;
  50. #else
  51. funcp = boost::math::cos_pi;
  52. #endif
  53. result = boost::math::tools::test_hetero<Real>(
  54. data,
  55. bind_func<Real>(funcp, 0),
  56. extract_result<Real>(2));
  57. handle_test_result(result, data[result.worst()], result.worst(), type_name, "cos_pi", test_name);
  58. std::cout << std::endl;
  59. #endif
  60. }
  61. template <class T>
  62. void test_trig(T, const char* name)
  63. {
  64. //
  65. // The actual test data is rather verbose, so it's in a separate file
  66. //
  67. // The contents are as follows, each row of data contains
  68. // three items, input value a, input value b and erf(a, b):
  69. //
  70. # include "trig_data.ipp"
  71. do_test_trig<T>(trig_data, name, "sin_pi and cos_pi");
  72. # include "trig_data2.ipp"
  73. do_test_trig<T>(trig_data2, name, "sin_pi and cos_pi near integers and half integers");
  74. }