8 #include "gtest/gtest.h" 11 #include <type_traits> 13 namespace alps {
namespace testing {
21 template <>
struct is_scalar<float> :
public std::true_type { };
22 template <>
struct is_scalar<double> :
public std::true_type { };
23 template <>
struct is_scalar<long double> :
public std::true_type { };
27 typename std::enable_if<is_scalar<T>::value,
int>::type = 0>
30 const char* abs_error_expr,
35 const double diff =
std::abs(val1 - val2);
36 if (diff <= abs_error)
37 return ::testing::AssertionSuccess();
39 return ::testing::AssertionFailure()
40 <<
"The difference between " << expr1 <<
" and " << expr2
41 <<
" is " << diff <<
", which exceeds " << abs_error_expr <<
", where\n" 42 << expr1 <<
" evaluates to " << val1 <<
",\n" 43 << expr2 <<
" evaluates to " << val2 <<
".";
47 template <
typename Derived1,
typename Derived2>
50 const char* abs_error_expr,
51 const Eigen::MatrixBase<Derived1> &val1,
52 const Eigen::MatrixBase<Derived2> &val2,
55 if (val1.isApprox(val2, abs_error))
56 return ::testing::AssertionSuccess();
58 return ::testing::AssertionFailure()
59 <<
"The difference between " << expr1 <<
" and " << expr2
60 <<
" exceeds " << abs_error_expr <<
", where\n" 61 << expr1 <<
" evaluates to\n" << val1 <<
",\n" 62 << expr2 <<
" evaluates to\n" << val2 <<
"\n.";
70 #define ALPS_EXPECT_NEAR(val1, val2, abs_error) \ 71 EXPECT_PRED_FORMAT3(::alps::testing::NearPredFormat, val1, val2, abs_error) boost::array< T, N > abs(boost::array< T, N > arg)
::testing::AssertionResult NearPredFormat(const char *expr1, const char *expr2, const char *abs_error_expr, const T &val1, const T &val2, double abs_error)