test_gamma.hpp 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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. #define BOOST_MATH_OVERFLOW_ERROR_POLICY ignore_error
  7. #include <boost/math/special_functions/gamma.hpp>
  8. #define BOOST_TEST_MAIN
  9. #include <boost/test/unit_test.hpp>
  10. #include <boost/test/floating_point_comparison.hpp>
  11. #include <boost/math/tools/stats.hpp>
  12. #include <boost/math/tools/test.hpp>
  13. #include <boost/math/constants/constants.hpp>
  14. #include <boost/type_traits/is_floating_point.hpp>
  15. #include <boost/array.hpp>
  16. #include "libs/math/test/functor.hpp"
  17. #include "libs/math/test/handle_test_result.hpp"
  18. #include "../table_type.hpp"
  19. #ifndef SC_
  20. #define SC_(x) static_cast<typename table_type<T>::type>(BOOST_JOIN(x, L))
  21. #endif
  22. template <class Real, class T>
  23. void do_test_gamma(const T& data, const char* type_name, const char* test_name)
  24. {
  25. typedef typename T::value_type row_type;
  26. typedef Real value_type;
  27. typedef value_type (*pg)(value_type);
  28. #if defined(BOOST_MATH_NO_DEDUCED_FUNCTION_POINTERS)
  29. pg funcp = boost::math::tgamma<value_type>;
  30. #else
  31. pg funcp = boost::math::tgamma;
  32. #endif
  33. boost::math::tools::test_result<value_type> result;
  34. std::cout << "Testing " << test_name << " with type " << type_name
  35. << "\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n";
  36. //
  37. // test tgamma against data:
  38. //
  39. result = boost::math::tools::test_hetero<Real>(
  40. data,
  41. bind_func<Real>(funcp, 0),
  42. extract_result<Real>(1));
  43. handle_test_result(result, data[result.worst()], result.worst(), type_name, "boost::math::tgamma", test_name);
  44. //
  45. // test lgamma against data:
  46. //
  47. #if defined(BOOST_MATH_NO_DEDUCED_FUNCTION_POINTERS)
  48. funcp = boost::math::lgamma<value_type>;
  49. #else
  50. funcp = boost::math::lgamma;
  51. #endif
  52. result = boost::math::tools::test_hetero<Real>(
  53. data,
  54. bind_func<Real>(funcp, 0),
  55. extract_result<Real>(2));
  56. handle_test_result(result, data[result.worst()], result.worst(), type_name, "boost::math::lgamma", test_name);
  57. std::cout << std::endl;
  58. }
  59. template <class T>
  60. void test_gamma(T, const char* name)
  61. {
  62. #include "gamma.ipp"
  63. do_test_gamma<T>(gamma, name, "random values");
  64. #include "gamma_1_2.ipp"
  65. do_test_gamma<T>(gamma_1_2, name, "Values near 1 and 2");
  66. #include "gamma_0.ipp"
  67. do_test_gamma<T>(gamma_0, name, "Values near 0");
  68. #include "gamma_neg.ipp"
  69. do_test_gamma<T>(gamma_neg, name, "Negative arguments");
  70. }