test_sinc.hpp 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. // Copyright John Maddock 2018.
  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/sinc.hpp>
  10. #include <boost/array.hpp>
  11. #include "functor.hpp"
  12. #include "handle_test_result.hpp"
  13. #include "table_type.hpp"
  14. #ifndef SC_
  15. #define SC_(x) static_cast<typename table_type<T>::type>(BOOST_JOIN(x, L))
  16. #endif
  17. template <class Real, class T>
  18. void do_test_sinc(const T& data, const char* type_name, const char* test_name)
  19. {
  20. #if !(defined(ERROR_REPORTING_MODE) && !defined(DIGAMMA_FUNCTION_TO_TEST))
  21. typedef Real value_type;
  22. typedef value_type (*pg)(value_type);
  23. #if defined(BOOST_MATH_NO_DEDUCED_FUNCTION_POINTERS)
  24. pg funcp = boost::math::sinc_pi<value_type>;
  25. #else
  26. pg funcp = boost::math::sinc_pi;
  27. #endif
  28. boost::math::tools::test_result<value_type> result;
  29. std::cout << "Testing " << test_name << " with type " << type_name
  30. << "\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n";
  31. //
  32. // test sinc against data:
  33. //
  34. result = boost::math::tools::test_hetero<Real>(
  35. data,
  36. bind_func<Real>(funcp, 0),
  37. extract_result<Real>(1));
  38. handle_test_result(result, data[result.worst()], result.worst(), type_name, "sinc_pi", test_name);
  39. std::cout << std::endl;
  40. #endif
  41. }
  42. template <class T>
  43. void test_sinc(T, const char* name)
  44. {
  45. //
  46. // The actual test data is rather verbose, so it's in a separate file
  47. //
  48. // The contents are as follows, each row of data contains
  49. // three items, input value a, input value b and erf(a, b):
  50. //
  51. # include "sinc_data.ipp"
  52. do_test_sinc<T>(sinc_data, name, "Sinc Function");
  53. }