test_spherical_harmonic.cpp 4.6 KB

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