// Copyright John Maddock 2006.
// Copyright Paul A. Bristow 2007, 2009
//  Use, modification and distribution are subject to the
//  Boost Software License, Version 1.0. (See accompanying file
//  LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)

#define BOOST_MATH_OVERFLOW_ERROR_POLICY ignore_error

#include <boost/math/concepts/real_concept.hpp>
#include <boost/math/special_functions/math_fwd.hpp>
#define BOOST_TEST_MAIN
#include <boost/test/unit_test.hpp>
#include <boost/test/tools/floating_point_comparison.hpp>
#include <boost/math/tools/stats.hpp>
#include <boost/math/tools/test.hpp>
#include <boost/math/tools/big_constant.hpp>
#include <boost/math/constants/constants.hpp>
#include <boost/type_traits/is_floating_point.hpp>
#include <boost/array.hpp>
#include "functor.hpp"

#include "handle_test_result.hpp"
#include "table_type.hpp"

#include <boost/math/special_functions/hypergeometric_1F1.hpp>
#include <boost/math/quadrature/exp_sinh.hpp>

#ifdef _MSC_VER
#pragma warning(disable:4127)
#endif

template <class Real, class T>
void do_test_1F1(const T& data, const char* type_name, const char* test_name)
{
   typedef Real                   value_type;

   typedef value_type(*pg)(value_type, value_type, value_type);
#if defined(BOOST_MATH_NO_DEDUCED_FUNCTION_POINTERS)
   pg funcp = boost::math::hypergeometric_0F1_regularized<value_type, value_type>;
#else
   pg funcp = boost::math::hypergeometric_1F1_regularized;
#endif

   boost::math::tools::test_result<value_type> result;

   std::cout << "Testing " << test_name << " with type " << type_name
      << "\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n";

   //
   // test hypergeometric_2F0 against data:
   //
   result = boost::math::tools::test_hetero<Real>(
      data,
      bind_func<Real>(funcp, 0, 1, 2),
      extract_result<Real>(3));
   handle_test_result(result, data[result.worst()], result.worst(), type_name, "hypergeometric_1F1_regularized", test_name);
   std::cout << std::endl;
}

#ifndef SC_
#define SC_(x) BOOST_MATH_BIG_CONSTANT(T, 1000000, x)
#endif

template <class T>
void test_spots1(T, const char* type_name)
{
#ifdef TEST_MP
#include "hypergeometric_1f1_large_regularized_mp.ipp"
#else
#include "hypergeometric_1f1_large_regularized.ipp"
#endif

   do_test_1F1<T>(hypergeometric_1f1_large_regularized, type_name, "Large random values - regularized");
}

template <class T>
void test_spots(T z, const char* type_name)
{
   test_spots1(z, type_name);

   //
   // Special cases for coverage:
   //
   BOOST_IF_CONSTEXPR(std::numeric_limits<T>::has_infinity)
   {
      BOOST_CHECK_EQUAL(boost::math::hypergeometric_1F1_regularized(600.25, 102.75, 11512.0), std::numeric_limits<T>::infinity());
      BOOST_IF_CONSTEXPR(std::numeric_limits<long double>::max_exponent > 16000)
      {
         BOOST_CHECK_EQUAL(boost::math::hypergeometric_1F1_regularized(600.25, 102.75, 9985.0), std::numeric_limits<T>::infinity());
      }
      else BOOST_IF_CONSTEXPR(std::numeric_limits<T>::max_exponent <= std::numeric_limits<double>::max_exponent)
      {
         BOOST_CHECK_EQUAL(boost::math::hypergeometric_1F1_regularized(600.25, 102.75, 514.0), std::numeric_limits<T>::infinity());
      }
   }
}

