Imported Upstream version 1.72.0
[platform/upstream/boost.git] / libs / math / test / test_spherical_harmonic.cpp
1 //  (C) Copyright John Maddock 2006.
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 #include <pch_light.hpp>
7
8 #include <boost/math/concepts/real_concept.hpp>
9 #define BOOST_TEST_MAIN
10 #include <boost/test/unit_test.hpp>
11 #include <boost/test/tools/floating_point_comparison.hpp>
12 #include <boost/math/special_functions/math_fwd.hpp>
13 #include <boost/math/constants/constants.hpp>
14 #include <boost/array.hpp>
15 #include "functor.hpp"
16
17 #include "handle_test_result.hpp"
18 #include "table_type.hpp"
19 #include "test_spherical_harmonic.hpp"
20
21 //
22 // DESCRIPTION:
23 // ~~~~~~~~~~~~
24 //
25 // This file tests the Spherical Harmonic Functions.
26 // There are two sets of tests, spot
27 // tests which compare our results with selected values computed
28 // using the online special function calculator at
29 // functions.wolfram.com, while the bulk of the accuracy tests
30 // use values generated with NTL::RR at 1000-bit precision
31 // and our generic versions of these functions.
32 //
33 // Note that when this file is first run on a new platform many of
34 // these tests will fail: the default accuracy is 1 epsilon which
35 // is too tight for most platforms.  In this situation you will
36 // need to cast a human eye over the error rates reported and make
37 // a judgement as to whether they are acceptable.  Either way please
38 // report the results to the Boost mailing list.  Acceptable rates of
39 // error are marked up below as a series of regular expressions that
40 // identify the compiler/stdlib/platform/data-type/test-data/test-function
41 // along with the maximum expected peek and RMS mean errors for that
42 // test.
43 //
44
45 void expected_results()
46 {
47    //
48    // Define the max and mean errors expected for
49    // various compilers and platforms.
50    //
51    const char* largest_type;
52 #ifndef BOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS
53    if(boost::math::policies::digits<double, boost::math::policies::policy<> >() == boost::math::policies::digits<long double, boost::math::policies::policy<> >())
54    {
55       largest_type = "(long\\s+)?double";
56    }
57    else
58    {
59       largest_type = "long double";
60    }
61 #else
62    largest_type = "(long\\s+)?double";
63 #endif
64 #ifndef BOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS
65    if((std::numeric_limits<long double>::digits <= 64) &&
66       (std::numeric_limits<long double>::digits != std::numeric_limits<double>::digits))
67    {
68       add_expected_result(
69          ".*",                          // compiler
70          ".*",                          // stdlib
71          ".*",                          // platform
72          "double",                      // test type(s)
73          ".*",                          // test data group
74          ".*", 15, 5);                  // test function
75    }
76 #endif
77    //
78    // Catch all cases come last:
79    //
80    add_expected_result(
81       ".*",                          // compiler
82       ".*",                          // stdlib
83       ".*",                          // platform
84       largest_type,                  // test type(s)
85       ".*",      // test data group
86       ".*", 30000, 1000);  // test function
87    add_expected_result(
88       ".*",                          // compiler
89       ".*",                          // stdlib
90       ".*",                          // platform
91       "real_concept",                  // test type(s)
92       ".*",      // test data group
93       ".*", 30000, 1000);  // test function
94    //
95    // Finish off by printing out the compiler/stdlib/platform names,
96    // we do this to make it easier to mark up expected error rates.
97    //
98    std::cout << "Tests run with " << BOOST_COMPILER << ", "
99       << BOOST_STDLIB << ", " << BOOST_PLATFORM << std::endl;
100 }
101
102 BOOST_AUTO_TEST_CASE( test_main )
103 {
104    BOOST_MATH_CONTROL_FP;
105    test_spots(0.0F, "float");
106    test_spots(0.0, "double");
107 #ifndef BOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS
108    test_spots(0.0L, "long double");
109    test_spots(boost::math::concepts::real_concept(0.1), "real_concept");
110 #endif
111
112    expected_results();
113
114    test_spherical_harmonic(0.1F, "float");
115    test_spherical_harmonic(0.1, "double");
116 #ifndef BOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS
117    test_spherical_harmonic(0.1L, "long double");
118 #ifndef BOOST_MATH_NO_REAL_CONCEPT_TESTS
119    test_spherical_harmonic(boost::math::concepts::real_concept(0.1), "real_concept");
120 #endif
121 #else
122    std::cout << "<note>The long double tests have been disabled on this platform "
123       "either because the long double overloads of the usual math functions are "
124       "not available at all, or because they are too inaccurate for these tests "
125       "to pass.</note>" << std::endl;
126 #endif
127    
128 }
129
130
131