3 #include <boost/test/unit_test.hpp> 15 using test_type = int;
19 test_type c = a + 2 * tol;
22 "a=" << a <<
", and b=" << b <<
" are not within tolerance=" << tol);
25 "a=" << a <<
", and c=" << c <<
" are within tolerance=" << tol);
33 using test_type = float;
36 test_type b = a + std::numeric_limits<test_type>::epsilon();
37 test_type c = a + 10 * tol * std::numeric_limits<test_type>::epsilon();
40 "a=" << a <<
", and b=" << b <<
" are not within tolerance=" << tol);
43 "a=" << a <<
", and c=" << c <<
" are within tolerance=" << tol);
51 using test_type = double;
54 test_type b = a + std::numeric_limits<test_type>::epsilon();
55 test_type c = a + 10 * tol * std::numeric_limits<test_type>::epsilon();
58 "a=" << a <<
", and b=" << b <<
" are not within tolerance=" << tol);
61 "a=" << a <<
", and c=" << c <<
" are within tolerance=" << tol);
69 using value_type = int;
70 using test_type = std::complex<value_type>;
72 test_type a = {10, 5};
73 test_type com_eps = {tol, tol};
74 test_type b = a + com_eps;
75 test_type c = 2 * com_eps + a;
78 "a=" << a <<
", and b=" << b <<
" are not within tolerance=" << tol);
81 "a=" << a <<
", and c=" << c <<
" are within tolerance=" << tol);
89 using value_type = float;
90 using test_type = std::vector<value_type>;
93 value_type num_a = 10.00;
94 test_type a(nsamples, num_a);
95 value_type num_b = num_a + std::numeric_limits<value_type>::epsilon();
96 test_type b(nsamples, num_b);
99 "a and b are not within tolerance=" << tol);
107 #if BOOST_VERSION <= 105800 114 check_close_enough_float_vector_failure,
116 #endif // BOOST_VERSION <= 105800 119 using value_type = float;
120 using test_type = std::vector<value_type>;
123 value_type num_a = 10.00;
124 test_type a(nsamples, num_a);
127 (value_type)(10 * tol) * std::numeric_limits<value_type>::epsilon();
128 test_type b(nsamples, num_b);
131 "a and c are within tolerance=" << tol);
140 #if BOOST_VERSION <= 105800 142 check_close_enough_complex_double_multi_array,
148 check_close_enough_complex_double_multi_array,
150 #endif // BOOST_VERSION <= 105800 153 using value_type = double;
154 using complex_type = std::complex<value_type>;
155 using test_type = boost::multi_array<complex_type, 3>;
160 complex_type num_a = {10.00, 5.00};
161 complex_type com_eps = {std::numeric_limits<value_type>::epsilon(),
162 std::numeric_limits<value_type>::epsilon()};
163 complex_type num_b = num_a + com_eps;
164 complex_type num_c = num_a + 10.0 * tol * com_eps;
166 test_type a(boost::extents[S][V][nsamples]);
167 test_type b(boost::extents[S][V][nsamples]);
168 test_type c(boost::extents[S][V][nsamples]);
170 for (
int i = 0; i != S; ++i) {
171 for (
int j = 0; j != V; ++j) {
172 for (
int k = 0; k !=
nsamples; ++k) {
182 "a and b are not within tolerance=" << tol);
185 "a and c are within tolerance=" << tol);
bool check_collection_close_enough(collection_t const &a, collection_t const &b, int tol=1, int max_differences_printed=JB_TESTING_MAX_DIFFERENCES_PRINTED)
Given two collections of numbers of the same value type, find the differences that are out of a given...
BOOST_AUTO_TEST_CASE(check_close_enough_integer)
std::size_t nsamples(container_type const &a)
Count the elements in the last dimension of a vector-like container.
Helper functions and classes to simplify unit tests.
#define JB_TESTING_MAX_DIFFERENCES_PRINTED
BOOST_AUTO_TEST_CASE_EXPECTED_FAILURES(check_close_enough_float_vector_failure, JB_TESTING_MAX_DIFFERENCES_PRINTED)
bool check_close_enough(value_t num_a, value_t num_b, int tol)
Given two numbers of the same integer type check if the difference is within a given tolerance...