test_nc_chi_squared.cpp 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. // test_nc_chi_squared.cpp
  2. // Copyright John Maddock 2008.
  3. // Use, modification and distribution are subject to the
  4. // Boost Software License, Version 1.0.
  5. // (See accompanying file LICENSE_1_0.txt
  6. // or copy at http://www.boost.org/LICENSE_1_0.txt)
  7. #include <pch.hpp>
  8. #ifdef _MSC_VER
  9. #pragma warning (disable:4127 4512)
  10. #endif
  11. #if !defined(TEST_FLOAT) && !defined(TEST_DOUBLE) && !defined(TEST_LDOUBLE) && !defined(TEST_REAL_CONCEPT)
  12. # define TEST_FLOAT
  13. # define TEST_DOUBLE
  14. # define TEST_LDOUBLE
  15. # define TEST_REAL_CONCEPT
  16. #endif
  17. #include <boost/math/tools/test.hpp>
  18. #include <boost/math/concepts/real_concept.hpp> // for real_concept
  19. #include <boost/math/distributions/non_central_chi_squared.hpp> // for chi_squared_distribution
  20. #include <boost/math/special_functions/cbrt.hpp> // for chi_squared_distribution
  21. #define BOOST_TEST_MAIN
  22. #include <boost/test/unit_test.hpp> // for test_main
  23. #include <boost/test/results_collector.hpp>
  24. #include <boost/test/unit_test.hpp>
  25. #include <boost/test/tools/floating_point_comparison.hpp> // for BOOST_CHECK_CLOSE
  26. #include "test_out_of_range.hpp"
  27. #include "functor.hpp"
  28. #include "handle_test_result.hpp"
  29. #include "test_nccs_hooks.hpp"
  30. #include "table_type.hpp"
  31. #include "test_nc_chi_squared.hpp"
  32. #include <iostream>
  33. #include <iomanip>
  34. using std::cout;
  35. using std::endl;
  36. #include <limits>
  37. using std::numeric_limits;
  38. void expected_results()
  39. {
  40. //
  41. // Define the max and mean errors expected for
  42. // various compilers and platforms.
  43. //
  44. const char* largest_type;
  45. #ifndef BOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS
  46. if(boost::math::policies::digits<double, boost::math::policies::policy<> >() == boost::math::policies::digits<long double, boost::math::policies::policy<> >())
  47. {
  48. largest_type = "(long\\s+)?double|real_concept";
  49. }
  50. else
  51. {
  52. largest_type = "long double|real_concept";
  53. }
  54. #else
  55. largest_type = "(long\\s+)?double|real_concept";
  56. #endif
  57. add_expected_result(
  58. "[^|]*", // compiler
  59. "[^|]*", // stdlib
  60. "Mac OS", // platform
  61. largest_type, // test type(s)
  62. "[^|]*medium[^|]*", // test data group
  63. "[^|]*", 550, 100); // test function
  64. //
  65. // Catch all cases come last:
  66. //
  67. add_expected_result(
  68. "[^|]*", // compiler
  69. "[^|]*", // stdlib
  70. "[^|]*", // platform
  71. largest_type, // test type(s)
  72. "[^|]*medium[^|]*", // test data group
  73. "[^|]*", 350, 100); // test function
  74. add_expected_result(
  75. "[^|]*", // compiler
  76. "[^|]*", // stdlib
  77. "[^|]*", // platform
  78. largest_type, // test type(s)
  79. "[^|]*large[^|]*", // test data group
  80. "[^|]*", 17000, 3000); // test function
  81. //
  82. // Allow some long double error to creep into
  83. // the double results:
  84. //
  85. add_expected_result(
  86. "[^|]*", // compiler
  87. "[^|]*", // stdlib
  88. "[^|]*", // platform
  89. "double", // test type(s)
  90. "[^|]*", // test data group
  91. "[^|]*", 3, 2); // test function
  92. //
  93. // Finish off by printing out the compiler/stdlib/platform names,
  94. // we do this to make it easier to mark up expected error rates.
  95. //
  96. std::cout << "Tests run with " << BOOST_COMPILER << ", "
  97. << BOOST_STDLIB << ", " << BOOST_PLATFORM << std::endl;
  98. }
  99. BOOST_AUTO_TEST_CASE( test_main )
  100. {
  101. BOOST_MATH_CONTROL_FP;
  102. // Basic sanity-check spot values.
  103. expected_results();
  104. // (Parameter value, arbitrarily zero, only communicates the floating point type).
  105. #ifdef TEST_FLOAT
  106. test_spots(0.0F); // Test float.
  107. #endif
  108. #ifdef TEST_DOUBLE
  109. test_spots(0.0); // Test double.
  110. #endif
  111. #ifndef BOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS
  112. #ifdef TEST_LDOUBLE
  113. test_spots(0.0L); // Test long double.
  114. #endif
  115. #ifndef BOOST_MATH_NO_REAL_CONCEPT_TESTS
  116. #ifdef TEST_REAL_CONCEPT
  117. test_spots(boost::math::concepts::real_concept(0.)); // Test real concept.
  118. #endif
  119. #endif
  120. #endif
  121. #ifdef TEST_FLOAT
  122. test_accuracy(0.0F, "float"); // Test float.
  123. #endif
  124. #ifdef TEST_DOUBLE
  125. test_accuracy(0.0, "double"); // Test double.
  126. #endif
  127. #ifndef BOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS
  128. #ifdef TEST_LDOUBLE
  129. test_accuracy(0.0L, "long double"); // Test long double.
  130. #endif
  131. #ifndef BOOST_MATH_NO_REAL_CONCEPT_TESTS
  132. #ifdef TEST_REAL_CONCEPT
  133. test_accuracy(boost::math::concepts::real_concept(0.), "real_concept"); // Test real concept.
  134. #endif
  135. #endif
  136. #endif
  137. } // BOOST_AUTO_TEST_CASE( test_main )