1+ // (C) Copyright Kilian Kilger 2025.
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+
6+ #define BOOST_TEST_MAIN
7+
8+ #include < boost/test/unit_test.hpp>
9+ #include < boost/test/tools/floating_point_comparison.hpp>
10+ #include < boost/test/unit_test.hpp>
11+ #include < boost/test/results_collector.hpp>
12+ #include < boost/math/special_functions/gamma.hpp>
13+
14+ using namespace std ;
15+ using namespace boost ::math;
16+ using namespace boost ::math::policies;
17+
18+ typedef policy<
19+ policies::domain_error<errno_on_error>,
20+ policies::pole_error<errno_on_error>,
21+ policies::overflow_error<errno_on_error>,
22+ policies::evaluation_error<errno_on_error>
23+ > c_policy;
24+
25+ template <typename T>
26+ struct test_lower
27+ {
28+ T operator ()(T a, T x) const
29+ {
30+ return tgamma_lower (a, x, c_policy ());
31+ }
32+
33+ T expected (T a) const
34+ {
35+ return T (0.0 );
36+ }
37+ };
38+
39+ template <typename T>
40+ struct test_upper
41+ {
42+ T operator ()(T a, T x) const
43+ {
44+ return tgamma (a, x, c_policy ());
45+ }
46+ T expected (T a) const
47+ {
48+ return tgamma (a, c_policy ());
49+ }
50+ };
51+
52+ template <typename T>
53+ struct test_gamma_p
54+ {
55+ T operator ()(T a, T x) const
56+ {
57+ return gamma_p (a, x, c_policy ());
58+ }
59+ T expected (T) const
60+ {
61+ return T (0.0 );
62+ }
63+ };
64+
65+ template <typename T>
66+ struct test_gamma_q
67+ {
68+ T operator ()(T a, T x) const
69+ {
70+ return gamma_q (a, x, c_policy ());
71+ }
72+ T expected (T) const
73+ {
74+ return T (1.0 );
75+ }
76+ };
77+
78+ template <typename T, template <typename > class Fun >
79+ void test_impl (T a)
80+ {
81+ Fun<T> fn;
82+ errno = 0 ;
83+ T x = T (0.0 );
84+ T result = fn (a, x);
85+ int saveErrno = errno;
86+
87+ errno = 0 ;
88+
89+ T expected = fn.expected (a);
90+
91+ BOOST_CHECK (errno == saveErrno);
92+ BOOST_CHECK_EQUAL (result, expected);
93+ }
94+
95+ template <template <typename > class Fun >
96+ void test_type_dispatch (float a)
97+ {
98+ test_impl<float , Fun>(a);
99+ test_impl<double , Fun>(double (a));
100+ test_impl<long double , Fun>(static_cast <long double >(a));
101+ }
102+
103+ template <template <typename > class Fun >
104+ void test_impl ()
105+ {
106+ test_type_dispatch<Fun>(1.0 );
107+ test_type_dispatch<Fun>(0.1 );
108+ test_type_dispatch<Fun>(0.5 );
109+ test_type_dispatch<Fun>(0.6 );
110+ test_type_dispatch<Fun>(1.3 );
111+ test_type_dispatch<Fun>(1.5 );
112+ test_type_dispatch<Fun>(2 );
113+ test_type_dispatch<Fun>(100 );
114+ test_type_dispatch<Fun>(std::numeric_limits<float >::max ());
115+ }
116+
117+ void test_derivative ()
118+ {
119+ double derivative = 0 ;
120+ double result = boost::math::detail::gamma_incomplete_imp (1.0 , 0.0 ,
121+ true , false , c_policy (), &derivative);
122+ BOOST_CHECK (errno == 0 );
123+ BOOST_CHECK_EQUAL (derivative, 0 );
124+ BOOST_CHECK_EQUAL (result, 0 );
125+ }
126+
127+ BOOST_AUTO_TEST_CASE ( test_main )
128+ {
129+ test_impl<test_lower>();
130+ test_impl<test_upper>();
131+ test_impl<test_gamma_p>();
132+ test_impl<test_gamma_q>();
133+ test_derivative ();
134+ }
0 commit comments