| 32 | | #define BOOST_UBLAS_TEST_END() if (test_fails_ > 0) { std::cerr << "Number of failed tests: " << test_fails_ << std::endl; return -1; \ |
| 33 | | } else { std::cerr << "No failed test" << std::endl; return 0; } |
| | 66 | /// Define the beginning of a test suite. |
| | 67 | #define BOOST_UBLAS_TEST_BEGIN() /* [BOOST_UBLAS_TEST_BEGIN] */ \ |
| | 68 | { \ |
| | 69 | /* Begin of Test Suite */ \ |
| | 70 | unsigned int test_fails__(0) \ |
| | 71 | /* [/BOOST_UBLAS_TEST_BEGIN] */ |
| | 72 | |
| | 73 | |
| | 74 | /// Define a test case \a x inside the current test suite. |
| | 75 | #define BOOST_UBLAS_TEST_DEF(x) void BOOST_UBLAS_TEST_EXPAND_(x)(unsigned int& test_fails__) |
| | 76 | |
| | 77 | |
| | 78 | /// Call the test case \a x. |
| | 79 | #define BOOST_UBLAS_TEST_DO(x) /* [BOOST_UBLAS_TEST_DO] */ \ |
| | 80 | try \ |
| | 81 | { \ |
| | 82 | BOOST_UBLAS_TEST_EXPAND_(x)(test_fails__); \ |
| | 83 | } \ |
| | 84 | catch (::std::exception& e) \ |
| | 85 | { \ |
| | 86 | ++test_fails__; \ |
| | 87 | BOOST_UBLAS_TEST_ERROR( e.what() ); \ |
| | 88 | } \ |
| | 89 | catch (...) \ |
| | 90 | { \ |
| | 91 | ++test_fails__; \ |
| | 92 | } \ |
| | 93 | /* [/BOOST_UBLAS_TEST_DO] */ |
| | 94 | |
| | 95 | |
| | 96 | /// Define the end of a test suite. |
| | 97 | #define BOOST_UBLAS_TEST_END() /* [BOOST_UBLAS_TEST_END] */ \ |
| | 98 | if (test_fails__ > 0) \ |
| | 99 | { \ |
| | 100 | ::std::cerr << "Number of failed tests: " << test_fails__ << ::std::endl; \ |
| | 101 | } \ |
| | 102 | else \ |
| | 103 | { \ |
| | 104 | ::std::cerr << "No failed test" << ::std::endl; \ |
| | 105 | } \ |
| | 106 | } /* End of test suite */ \ |
| | 107 | /* [/BOOST_UBLAS_TEST_END] */ |
| | 108 | |
| | 109 | |
| | 110 | /// Check the truth of assertion \a x. |
| | 111 | #define BOOST_UBLAS_TEST_CHECK(x) /* [BOOST_UBLAS_TEST_CHECK] */ \ |
| | 112 | if (!(x)) \ |
| | 113 | { \ |
| | 114 | BOOST_UBLAS_TEST_ERROR( "Failed assertion: " << BOOST_UBLAS_TEST_STRINGIFY_(x) ); \ |
| | 115 | ++test_fails__; \ |
| | 116 | } \ |
| | 117 | /* [/BOOST_UBLAS_TEST_CHECK] */ |
| | 118 | |
| | 119 | |
| | 120 | /// Check for the equality of \a x against \a y. |
| | 121 | #define BOOST_UBLA_TEST_CHECK_EQUAL(x,y) /* [BOOST_UBLA_TEST_CHECK_EQUAL] */ \ |
| | 122 | if (!(BOOST_UBLAS_TEST_PARAM_EXPAND_(x) == BOOST_UBLAS_TEST_PARAM_EXPAND_(y))) \ |
| | 123 | { \ |
| | 124 | BOOST_UBLAS_TEST_ERROR( "Failed assertion: (" << BOOST_UBLAS_TEST_STRINGIFY_(x) << " == " << BOOST_UBLAS_TEST_STRINGIFY_(y) << ")" ); \ |
| | 125 | ++test_fails__; \ |
| | 126 | } \ |
| | 127 | /* [/BOOST_UBLA_TEST_CHECK_EQUAL] */ |
| | 128 | |
| | 129 | |
| | 130 | /// Check that \a x and \a y are close with respect to a given precision. |
| | 131 | #define BOOST_UBLAS_TEST_CHECK_PRECISION(x,y,e) /* [BOOST_UBLAS_TEST_CHECK_PRECISION] */ \ |
| | 132 | if (!::boost::numeric::ublas::test::detail::close_to(BOOST_UBLAS_TEST_EXPAND_(x), BOOST_UBLAS_TEST_EXPAND_(y), BOOST_UBLAS_TEST_EXPAND_(e))) \ |
| | 133 | { \ |
| | 134 | BOOST_UBLAS_TEST_ERROR( "Failed assertion: abs(" << BOOST_UBLAS_TEST_STRINGIFY_(x) << "-" << BOOST_UBLAS_TEST_STRINGIFY_(y) << ") <= " << BOOST_UBLAS_TEST_STRINGIFY_(e) << " [with " << BOOST_UBLAS_TEST_STRINGIFY_(x) << " == " << BOOST_UBLAS_TEST_EXPAND_(x) << ", " << BOOST_UBLAS_TEST_STRINGIFY_(y) << " == " << BOOST_UBLAS_TEST_EXPAND_(y) << " and " << BOOST_UBLAS_TEST_STRINGIFY_(e) << " == " << BOOST_UBLAS_TEST_EXPAND_(e) << "]" ); \ |
| | 135 | ++test_fails__; \ |
| | 136 | } \ |
| | 137 | /* [/BOOST_UBLAS_TEST_CHECK_PRECISION] */ |
| | 138 | |
| | 139 | |
| | 140 | /// Check that \a x is close to \a y with respect to a given relative precision. |
| | 141 | #define BOOST_UBLAS_TEST_CHECK_REL_PRECISION(x,y,e) /* [BOOST_UBLAS_TEST_CHECK_REL_PRECISION] */ \ |
| | 142 | if (!::boost::numeric::ublas::test::detail::close_to(BOOST_UBLAS_TEST_EXPAND_(x)/BOOST_UBLAS_TEST_EXPAND_(y), 1.0, BOOST_UBLAS_TEST_EXPAND_(e))) \ |
| | 143 | { \ |
| | 144 | BOOST_UBLAS_TEST_ERROR( "Failed assertion: abs((" << BOOST_UBLAS_TEST_STRINGIFY_(x) << "-" << BOOST_UBLAS_TEST_STRINGIFY_(y) << ")/" << BOOST_UBLAS_TEST_STRINGIFY_(y) << ") <= " << BOOST_UBLAS_TEST_STRINGIFY_(e) << " [with " << BOOST_UBLAS_TEST_STRINGIFY_(x) << " == " << BOOST_UBLAS_TEST_EXPAND_(x) << ", " << BOOST_UBLAS_TEST_STRINGIFY_(y) << " == " << BOOST_UBLAS_TEST_EXPAND_(y) << " and " << BOOST_UBLAS_TEST_STRINGIFY_(e) << " == " << BOOST_UBLAS_TEST_EXPAND_(e) << "]" ); \ |
| | 145 | ++test_fails__; \ |
| | 146 | } \ |
| | 147 | /* [/BOOST_UBLAS_TEST_CHECK_REL_PRECISION] */ |
| | 148 | |
| | 149 | |
| | 150 | /// Check that elements of \a x and \a y are equal. |
| | 151 | #define BOOST_UBLAS_TEST_CHECK_VECTOR_EQ(x,y,n) /* [BOOST_UBLAS_TEST_CHECK_VECTOR_EQ] */ \ |
| | 152 | if (BOOST_UBLAS_TEST_EXPAND_(n) > 0) \ |
| | 153 | { \ |
| | 154 | unsigned long n__ = BOOST_UBLAS_TEST_EXPAND_(n); \ |
| | 155 | for (unsigned long i__ = n__; i__ > 0; --i__) \ |
| | 156 | { \ |
| | 157 | if (!(BOOST_UBLAS_TEST_EXPAND_(x)[n__-i__]==BOOST_UBLAS_TEST_EXPAND_(y)[n__-i__])) \ |
| | 158 | { \ |
| | 159 | BOOST_UBLAS_TEST_ERROR( "Failed assertion: (" << BOOST_UBLAS_TEST_STRINGIFY_(x[i__]) << "==" << BOOST_UBLAS_TEST_STRINGIFY_(y[i__]) << ")" << " [with " << BOOST_UBLAS_TEST_STRINGIFY_(x[i__]) << " == " << BOOST_UBLAS_TEST_EXPAND_(x)[n__-i__] << ", " << BOOST_UBLAS_TEST_STRINGIFY_(y[i__]) << " == " << BOOST_UBLAS_TEST_EXPAND_(y)[n__-i__] << ", " << BOOST_UBLAS_TEST_STRINGIFY_(i__) << " == " << i__ << " and " << BOOST_UBLAS_TEST_STRINGIFY_(n) << " == " << n__ << "]" ); \ |
| | 160 | ++test_fails__; \ |
| | 161 | } \ |
| | 162 | } \ |
| | 163 | } \ |
| | 164 | /* [/BOOST_UBLAS_TEST_CHECK_VECTOR_EQ] */ |
| | 165 | |
| | 166 | |
| | 167 | /// Check that elements of \a x and \a y are close with respect to a given precision. |
| | 168 | #define BOOST_UBLAS_TEST_CHECK_VECTOR_CLOSE(x,y,n,e) /* [BOOST_UBLAS_TEST_CHECK_VECTOR_CLOSE] */ \ |
| | 169 | if (BOOST_UBLAS_TEST_EXPAND_(n) > 0) \ |
| | 170 | { \ |
| | 171 | unsigned long n__ = BOOST_UBLAS_TEST_EXPAND_(n); \ |
| | 172 | for (unsigned long i__ = n__; i__ > 0; --i__) \ |
| | 173 | { \ |
| | 174 | BOOST_UBLAS_TEST_CHECK_PRECISION((BOOST_UBLAS_TEST_EXPAND_(x)[n__-i__], BOOST_UBLAS_TEST_EXPAND_(y)[n__-i__]), BOOST_UBLAS_TEST_EXPAND_(e)); \ |
| | 175 | } \ |
| | 176 | } \ |
| | 177 | /* [/BOOST_UBLAS_TEST_CHECK_VECTOR_CLOSE] */ |
| | 178 | |
| | 179 | |
| | 180 | ///< Check that elements of matrices \a x and \a y are equal. |
| | 181 | #define BOOST_UBLAS_TEST_CHECK_MATRIX_EQ(x,y,nr,nc) /* [BOOST_UBLAS_TEST_CHECK_MATRIX_EQ] */ \ |
| | 182 | for (unsigned long i__ = 0; i__ < BOOST_UBLAS_TEST_EXPAND_(nr); ++i__) \ |
| | 183 | { \ |
| | 184 | for (unsigned long j__ = 0; j__ < BOOST_UBLAS_TEST_EXPAND_(nc); ++j__) \ |
| | 185 | { \ |
| | 186 | BOOST_UBLAS_TEST_CHECK_EQUAL(BOOST_UBLAS_TEST_EXPAND_(x)(i__,j__), BOOST_UBLAS_TEST_EXPAND_(y)(i__,j__)); \ |
| | 187 | } \ |
| | 188 | } \ |
| | 189 | /* [/BOOST_UBLAS_TEST_CHECK_MATRIX_EQ] */ |
| | 190 | |
| | 191 | |
| | 192 | ///< Check that elements of matrices \a x and \a y are close with respect to a |
| | 193 | /// give precision. |
| | 194 | #define BOOST_UBLAS_TEST_CHECK_MATRIX_CLOSE(x,y,nr,nc,e) /* [BOOST_UBLAS_TEST_CHECK_MATRIX_CLOSE] */ \ |
| | 195 | for (unsigned long i__ = 0; i__ < BOOST_UBLAS_TEST_EXPAND_(nr); ++i__) \ |
| | 196 | { \ |
| | 197 | for (unsigned long j__ = 0; j__ < BOOST_UBLAS_TEST_EXPAND_(nc); ++j__) \ |
| | 198 | { \ |
| | 199 | BOOST_UBLAS_TEST_CHECK_PRECISION(BOOST_UBLAS_TEST_EXPAND_(x)(i__,j__), BOOST_UBLAS_TEST_EXPAND_(y)(i__,j__), BOOST_UBLAS_TEST_EXPAND_(e)); \ |
| | 200 | } \ |
| | 201 | } \ |
| | 202 | /* [/BOOST_UBLAS_TEST_CHECK_MATRIX_CLOSE] */ |