1 #ifndef UNIT_TEST_SUPPORT_H 2 #define UNIT_TEST_SUPPORT_H 5 #include <boost/test/unit_test.hpp> 6 #include <boost/test/floating_point_comparison.hpp> 7 #include <blitz/array.h> 21 #define BOOST_CHECK_MATRIX_CLOSE_TOL( A, B, tol ) BOOST_CHECK_LT(max(abs(A - (B))), tol) 22 #define BOOST_CHECK_MATRIX_CLOSE( A, B ) BOOST_CHECK_MATRIX_CLOSE_TOL(A, B, 1e-8) 28 #define BOOST_CHECK_ARRAYAD_CLOSE_TOL( A, B, tol ) BOOST_CHECK_MATRIX_CLOSE_TOL(A.value(), B.value(), tol); BOOST_CHECK_MATRIX_CLOSE_TOL(A.jacobian(), B.jacobian(), tol) 29 #define BOOST_CHECK_ARRAYAD_CLOSE( A, B ) BOOST_CHECK_MATRIX_CLOSE(A.value(), B.value()); BOOST_CHECK_MATRIX_CLOSE(A.jacobian(), B.jacobian()) 35 #define CHECK_THROW_EXCEPTION( S , V ) \ 38 BOOST_ERROR("Exception was not thrown"); \ 39 } catch(const FullPhysics::Exception& E) { \ 40 BOOST_CHECK_EQUAL(std::string(E.what()), std::string(V)) ; \ 43 template<
class T,
int N>
44 inline void compare_shapes(
const blitz::Array<T, N>&
A,
const blitz::Array<T, N>& B) {
45 if( product(A.shape()) != product(B.shape()) ) {
46 std::cerr <<
"Shapes of arrays do not match: " << A.shape() <<
" vs. " << B.shape() << std::endl;
55 inline void compare_item_by_item(
const blitz::Array<T, 1>&
A,
const blitz::Array<T, 1>& B,
double tol,
bool show_all=
false) {
58 for(
int i = 0; i < A.extent(blitz::firstDim); i++) {
59 double diff = fabs(
A(i) - B(i));
60 if (diff > max) { max = diff; }
61 if( diff >= tol or show_all ) {
62 std::cerr <<
"@[" << i <<
"] " <<
A(i) <<
" != " << B(i) <<
" -- " << diff << std::endl;
65 std::cerr <<
"Maximum difference = " << max << std::endl;
73 inline void compare_item_by_item(
const blitz::Array<T, 2>&
A,
const blitz::Array<T, 2>& B,
double tol,
bool show_all=
false) {
76 for(
int i = 0; i < A.extent(blitz::firstDim); i++) {
77 for(
int j = 0; j < A.extent(blitz::secondDim); j++) {
78 double diff = fabs(
A(i,j) - B(i,j));
79 if (diff > max) { max = diff; }
80 if( diff >= tol or show_all ) {
81 std::cerr <<
"@[" << i <<
", " << j <<
"] " <<
A(i,j) <<
" != " << B(i,j) <<
" -- " << diff << std::endl;
85 std::cerr <<
"Maximum difference = " << max << std::endl;
93 inline void compare_item_by_item(
const blitz::Array<T, 3>&
A,
const blitz::Array<T, 3>& B,
double tol,
bool show_all=
false) {
96 for(
int i = 0; i < A.extent(blitz::firstDim); i++) {
97 for(
int j = 0; j < A.extent(blitz::secondDim); j++) {
98 for(
int k = 0; k < A.extent(blitz::thirdDim); k++) {
99 double diff = fabs(
A(i,j,k) - B(i,j,k));
100 if (diff > max) { max = diff; }
101 if( diff >= tol or show_all ) {
102 std::cerr <<
"@[" << i <<
", " << j <<
", " << k <<
"] " <<
A(i,j,k) <<
" != " << B(i,j,k) <<
" -- " << diff << std::endl;
107 std::cerr <<
"Maximum difference = " << max << std::endl;
115 inline void compare_item_by_item(
const blitz::Array<T, 4>&
A,
const blitz::Array<T, 4>& B,
double tol,
bool show_all=
false) {
118 for(
int i = 0; i < A.extent(blitz::firstDim); i++) {
119 for(
int j = 0; j < A.extent(blitz::secondDim); j++) {
120 for(
int k = 0; k < A.extent(blitz::thirdDim); k++) {
121 for(
int m = 0;
m < A.extent(blitz::fourthDim);
m++) {
122 double diff = fabs(
A(i,j,k,
m) - B(i,j,k,
m));
123 if (diff > max) { max = diff; }
124 if( diff >= tol or show_all ) {
125 std::cerr <<
"@[" << i <<
", " << j <<
", " << k <<
", " <<
m <<
"] " <<
A(i,j,k,
m) <<
" != " << B(i,j,k,
m) <<
" -- " << diff << std::endl;
131 std::cerr <<
"Maximum difference = " << max << std::endl;
142 #define is_long_test() \ 143 if(!getenv("L2_FP_LONG_CHECK") && !getenv("L2_FP_REALLY_LONG_CHECK")) { \ 144 BOOST_WARN_MESSAGE(false, "Skipping long test. To run, make long_check"); \ 148 #define is_really_long_test() \ 149 if(!getenv("L2_FP_REALLY_LONG_CHECK")) { \ 150 BOOST_WARN_MESSAGE(false, "Skipping really long test. To run, make really_long_check"); \ 162 #define is_timing_test() \ 163 if(!getenv("L2_FP_TIMING_CHECK")) { \ 164 BOOST_WARN_MESSAGE(false, "Skipping timing test. To run, make timing_check"); \ void compare_item_by_item(const blitz::Array< T, 1 > &A, const blitz::Array< T, 1 > &B, double tol, bool show_all=false)
Go through two 1D arrays and compare items item by item.
const Unit A("A", 1.0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0)
const Unit m("m", 1.0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0)
void compare_shapes(const blitz::Array< T, N > &A, const blitz::Array< T, N > &B)