1 // (C) Copyright John Maddock 2006-7.
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)
6 #ifndef BOOST_MATH_HANDLE_TEST_RESULT
7 #define BOOST_MATH_HANDLE_TEST_RESULT
9 #include <boost/math/tools/stats.hpp>
10 #include <boost/math/tools/test.hpp>
11 #include <boost/math/tools/precision.hpp>
12 #include <boost/regex.hpp>
13 #include <boost/test/test_tools.hpp>
17 #if defined(BOOST_INTEL)
18 # pragma warning(disable:239)
19 # pragma warning(disable:264)
23 // Every client of this header has to define this function,
24 // and initialise the table of expected results:
26 void expected_results();
28 typedef std::pair<boost::regex, std::pair<boost::uintmax_t, boost::uintmax_t> > expected_data_type;
29 typedef std::list<expected_data_type> list_type;
34 static list_type data;
38 inline void add_expected_result(
42 const char* type_name,
43 const char* test_name,
44 const char* group_name,
45 boost::uintmax_t max_peek_error,
46 boost::uintmax_t max_mean_error)
48 std::string re("(?:");
71 get_expected_data().push_back(
72 std::make_pair(boost::regex(re, boost::regex::perl | boost::regex::icase),
73 std::make_pair(max_peek_error, max_mean_error)));
76 inline std::string build_test_name(const char* type_name, const char* test_name, const char* group_name)
78 std::string result(BOOST_COMPILER);
80 result += BOOST_STDLIB;
82 result += BOOST_PLATFORM;
92 inline const std::pair<boost::uintmax_t, boost::uintmax_t>&
93 get_max_errors(const char* type_name, const char* test_name, const char* group_name)
95 static const std::pair<boost::uintmax_t, boost::uintmax_t> defaults(1, 1);
96 std::string name = build_test_name(type_name, test_name, group_name);
97 list_type& l = get_expected_data();
98 list_type::const_iterator a(l.begin()), b(l.end());
101 if(regex_match(name, a->first))
104 std::cout << name << std::endl;
105 std::cout << a->first.str() << std::endl;
114 template <class T, class Seq>
115 void handle_test_result(const boost::math::tools::test_result<T>& result,
116 const Seq& worst, int row,
117 const char* type_name,
118 const char* test_name,
119 const char* group_name)
122 #pragma warning(push)
123 #pragma warning(disable:4127)
125 using namespace std; // To aid selection of the right pow.
126 T eps = boost::math::tools::epsilon<T>();
127 std::cout << std::setprecision(4);
129 T max_error_found = (result.max)()/eps;
130 T mean_error_found = result.rms()/eps;
132 // Begin by printing the main tag line with the results:
134 std::cout << test_name << "<" << type_name << "> Max = " << max_error_found
135 << " RMS Mean=" << mean_error_found;
137 // If the max error is non-zero, give the row of the table that
138 // produced the worst error:
140 if((result.max)() != 0)
142 std::cout << "\n worst case at row: "
144 if(std::numeric_limits<T>::digits10)
146 std::cout << std::setprecision(std::numeric_limits<T>::digits10 + 2);
150 std::cout << std::setprecision(std::numeric_limits<long double>::digits10 + 2);
152 for(unsigned i = 0; i < worst.size(); ++i)
156 #if defined(__SGI_STL_PORT)
157 std::cout << boost::math::tools::real_cast<double>(worst[i]);
159 std::cout << worst[i];
164 std::cout << std::endl;
166 // Now verify that the results are within our expected bounds:
168 std::pair<boost::uintmax_t, boost::uintmax_t> const& bounds = get_max_errors(type_name, test_name, group_name);
169 if(bounds.first < max_error_found)
171 std::cerr << "Peak error greater than expected value of " << bounds.first << std::endl;
172 BOOST_CHECK(bounds.first >= max_error_found);
174 if(bounds.second < mean_error_found)
176 std::cerr << "Mean error greater than expected value of " << bounds.second << std::endl;
177 BOOST_CHECK(bounds.second >= mean_error_found);
179 std::cout << std::endl;
185 template <class T, class Seq>
186 void print_test_result(const boost::math::tools::test_result<T>& result,
187 const Seq& worst, int row, const char* name, const char* test)
189 using namespace std; // To aid selection of the right pow.
190 T eps = boost::math::tools::epsilon<T>();
191 std::cout << std::setprecision(4);
193 T max_error_found = (result.max)()/eps;
194 T mean_error_found = result.rms()/eps;
196 // Begin by printing the main tag line with the results:
198 std::cout << test << "(" << name << ") Max = " << max_error_found
199 << " RMS Mean=" << mean_error_found;
201 // If the max error is non-zero, give the row of the table that
202 // produced the worst error:
204 if((result.max)() != 0)
206 std::cout << "\n worst case at row: "
208 for(unsigned i = 0; i < worst.size(); ++i)
212 std::cout << worst[i];
216 std::cout << std::endl;
219 #endif // BOOST_MATH_HANDLE_TEST_RESULT