Imported Upstream version 1.57.0
[platform/upstream/boost.git] / libs / math / test / sinc_test.hpp
1 // unit test file sinc.hpp for the special functions test suite
2
3 //  (C) Copyright Hubert Holin 2003.
4 //  Distributed under the Boost Software License, Version 1.0. (See
5 //  accompanying file LICENSE_1_0.txt or copy at
6 //  http://www.boost.org/LICENSE_1_0.txt)
7
8
9 #include <functional>
10 #include <iomanip>
11 #include <iostream>
12 #include <complex>
13
14
15 #include <boost/math/special_functions/sinc.hpp>
16
17 #define BOOST_TEST_MAIN
18 #include <boost/test/unit_test.hpp>
19
20
21 BOOST_TEST_CASE_TEMPLATE_FUNCTION(sinc_pi_test, T)
22 {
23     using    ::std::abs;
24         
25     using    ::std::numeric_limits;
26     
27     using    ::boost::math::sinc_pi;
28     
29     
30     BOOST_TEST_MESSAGE("Testing sinc_pi in the real domain for "
31         << string_type_name<T>::_() << ".");
32     
33     BOOST_CHECK_PREDICATE(::std::less_equal<T>(),
34         (abs(sinc_pi<T>(static_cast<T>(0))-static_cast<T>(1)))
35         (numeric_limits<T>::epsilon()));
36 }
37
38
39 BOOST_TEST_CASE_TEMPLATE_FUNCTION(sinc_pi_complex_test, T)
40 {
41     using    ::std::abs;
42     using    ::std::sinh;
43         
44     using    ::std::numeric_limits;
45     
46     using    ::boost::math::sinc_pi;
47     
48     
49     BOOST_TEST_MESSAGE("Testing sinc_pi in the complex domain for "
50         << string_type_name<T>::_() << ".");
51     
52     BOOST_CHECK_PREDICATE(::std::less_equal<T>(),
53         (abs(sinc_pi<T>(::std::complex<T>(0, 1))-
54              ::std::complex<T>(sinh(static_cast<T>(1)))))
55         (numeric_limits<T>::epsilon()));
56 }
57
58
59 void    sinc_pi_manual_check()
60 {
61     using    ::boost::math::sinc_pi;
62     
63     
64     BOOST_TEST_MESSAGE(" ");
65     BOOST_TEST_MESSAGE("sinc_pi");
66     
67     for    (int i = 0; i <= 100; i++)
68     {
69 #ifndef BOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS
70         BOOST_TEST_MESSAGE( ::std::setw(15)
71                     << sinc_pi<float>(static_cast<float>(i-50)/
72                                                 static_cast<float>(50))
73                     << ::std::setw(15)
74                     << sinc_pi<double>(static_cast<double>(i-50)/
75                                                 static_cast<double>(50))
76                     << ::std::setw(15)
77                     << sinc_pi<long double>(static_cast<long double>(i-50)/
78                                                 static_cast<long double>(50)));
79 #else
80         BOOST_TEST_MESSAGE( ::std::setw(15)
81                     << sinc_pi<float>(static_cast<float>(i-50)/
82                                                 static_cast<float>(50))
83                     << ::std::setw(15)
84                     << sinc_pi<double>(static_cast<double>(i-50)/
85                                                 static_cast<double>(50)));
86 #endif
87     }
88     
89     BOOST_TEST_MESSAGE(" ");
90 }
91
92