16 #ifndef INCLUDE_NN_NLIB_TESTING_PRED_H_ 17 #define INCLUDE_NN_NLIB_TESTING_PRED_H_ 24 template<
class Pred,
class T1>
25 AssertionResult EvalPred1(
const char* pred_text,
const char* e1, Pred pred,
const T1& v1) {
26 return pred(v1) ? AssertionResult(
true)
27 : AssertionResult(false)
28 << pred_text <<
"(" << e1 <<
") evaluates to false, where" 30 << e1 <<
" evaluates to " << v1;
33 template<
class Pred,
class T1,
class T2>
34 AssertionResult EvalPred2(
const char* pred_text,
const char* e1,
const char* e2, Pred pred,
35 const T1& v1,
const T2& v2) {
36 return pred(v1, v2) ? AssertionResult(
true)
37 : AssertionResult(false) << pred_text <<
"(" << e1 <<
", " << e2
38 <<
") evaluates to false, where" 40 << e1 <<
" evaluates to " << v1 <<
"\n" 41 << e2 <<
" evaluates to " << v2;
44 template<
class Pred,
class T1,
class T2,
class T3>
45 AssertionResult EvalPred3(
const char* pred_text,
const char* e1,
const char* e2,
const char* e3,
46 Pred pred,
const T1& v1,
const T2& v2,
const T3& v3) {
47 return pred(v1, v2, v3) ? AssertionResult(
true)
48 : AssertionResult(false) << pred_text <<
"(" << e1 <<
", " << e2 <<
", " 49 << e3 <<
") evaluates to false, where" 51 << e1 <<
" evaluates to " << v1 <<
"\n" 52 << e2 <<
" evaluates to " << v2 <<
"\n" 53 << e3 <<
" evaluates to " << v3;
56 template<
class Pred,
class T1,
class T2,
class T3,
class T4>
58 EvalPred4(
const char* pred_text,
const char* e1,
const char* e2,
const char* e3,
const char* e4,
59 Pred pred,
const T1& v1,
const T2& v2,
const T3& v3,
const T4& v4) {
60 return pred(v1, v2, v3, v4) ? AssertionResult(
true)
61 : AssertionResult(false)
62 << pred_text <<
"(" << e1 <<
", " << e2 <<
", " << e3 <<
", " 63 << e4 <<
") evaluates to false, where" 65 << e1 <<
" evaluates to " << v1 <<
"\n" 66 << e2 <<
" evaluates to " << v2 <<
"\n" 67 << e3 <<
" evaluates to " << v3 <<
"\n" 68 << e4 <<
" evaluates to " << v4;
71 template<
class Pred,
class T1,
class T2,
class T3,
class T4,
class T5>
72 AssertionResult EvalPred5(
const char* pred_text,
const char* e1,
const char* e2,
const char* e3,
73 const char* e4,
const char* e5, Pred pred,
const T1& v1,
const T2& v2,
74 const T3& v3,
const T4& v4,
const T5& v5) {
75 return pred(v1, v2, v3, v4, v5) ? AssertionResult(
true)
76 : AssertionResult(false) << pred_text <<
"(" << e1 <<
", " << e2
77 <<
", " << e3 <<
", " << e4 <<
", " 78 << e5 <<
") evaluates to false, where" 80 << e1 <<
" evaluates to " << v1 <<
"\n" 81 << e2 <<
" evaluates to " << v2 <<
"\n" 82 << e3 <<
" evaluates to " << v3 <<
"\n" 83 << e4 <<
" evaluates to " << v4 <<
"\n" 84 << e5 <<
" evaluates to " << v5;
90 #define NLIB_TESTING_PRED1_(pred, v1, iffail) \ 94 if (::nlib_ns::testing::AssertionResult ar = \ 95 ::nlib_ns::testing::EvalPred1(#pred, #v1, pred, v1)) \ 100 #define NLIB_TESTING_PRED2_(pred, v1, v2, iffail) \ 104 if (::nlib_ns::testing::AssertionResult ar = \ 105 ::nlib_ns::testing::EvalPred2(#pred, #v1, #v2, pred, v1, v2)) \ 110 #define NLIB_TESTING_PRED3_(pred, v1, v2, v3, iffail) \ 114 if (::nlib_ns::testing::AssertionResult ar = \ 115 ::nlib_ns::testing::EvalPred3(#pred, #v1, #v2, #v3, pred, v1, v2, v3)) \ 120 #define NLIB_TESTING_PRED4_(pred, v1, v2, v3, v4, iffail) \ 124 if (::nlib_ns::testing::AssertionResult ar = \ 125 ::nlib_ns::testing::EvalPred4(#pred, #v1, #v2, #v3, #v4, pred, v1, v2, v3, v4)) \ 130 #define NLIB_TESTING_PRED5_(pred, v1, v2, v3, v4, v5, iffail) \ 134 if (::nlib_ns::testing::AssertionResult ar = ::nlib_ns::testing::EvalPred5( \ 135 #pred, #v1, #v2, #v3, #v4, #v5, pred, v1, v2, v3, v4, v5)) \ 140 #define NLIB_TESTING_PRED_FORMAT1_(pred_format, v1, iffail) \ 144 if (::nlib_ns::testing::AssertionResult ar = pred_format(#v1, v1)) \ 149 #define NLIB_TESTING_PRED_FORMAT2_(pred_format, v1, v2, iffail) \ 153 if (::nlib_ns::testing::AssertionResult ar = pred_format(#v1, #v2, v1, v2)) \ 158 #define NLIB_TESTING_PRED_FORMAT3_(pred_format, v1, v2, v3, iffail) \ 162 if (::nlib_ns::testing::AssertionResult ar = pred_format(#v1, #v2, #v3, v1, v2, v3)) \ 167 #define NLIB_TESTING_PRED_FORMAT4_(pred_format, v1, v2, v3, v4, iffail) \ 171 if (::nlib_ns::testing::AssertionResult ar = \ 172 pred_format(#v1, #v2, #v3, #v4, v1, v2, v3, v4)) \ 177 #define NLIB_TESTING_PRED_FORMAT5_(pred_format, v1, v2, v3, v4, v5, iffail) \ 181 if (::nlib_ns::testing::AssertionResult ar = \ 182 pred_format(#v1, #v2, #v3, #v4, #v5, v1, v2, v3, v4, v5)) \ 187 #define ASSERT_PRED1(pred, v1) NLIB_TESTING_PRED1_(pred, v1, NLIB_TESTING_FATAL_) 188 #define EXPECT_PRED1(pred, v1) NLIB_TESTING_PRED1_(pred, v1, NLIB_TESTING_NONFATAL_) 189 #define ASSERT_PRED_FORMAT1(pred_format, v1) \ 190 NLIB_TESTING_PRED_FORMAT1_(pred_format, v1, NLIB_TESTING_FATAL_) 191 #define EXPECT_PRED_FORMAT1(pred_format, v1) \ 192 NLIB_TESTING_PRED_FORMAT1_(pred_format, v1, NLIB_TESTING_NONFATAL_) 194 #define ASSERT_PRED2(pred, v1, v2) NLIB_TESTING_PRED2_(pred, v1, v2, NLIB_TESTING_FATAL_) 195 #define EXPECT_PRED2(pred, v1, v2) NLIB_TESTING_PRED2_(pred, v1, v2, NLIB_TESTING_NONFATAL_) 196 #define ASSERT_PRED_FORMAT2(pred_format, v1, v2) \ 197 NLIB_TESTING_PRED_FORMAT2_(pred_format, v1, v2, NLIB_TESTING_FATAL_) 198 #define EXPECT_PRED_FORMAT2(pred_format, v1, v2) \ 199 NLIB_TESTING_PRED_FORMAT2_(pred_format, v1, v2, NLIB_TESTING_NONFATAL_) 201 #define ASSERT_PRED3(pred, v1, v2, v3) NLIB_TESTING_PRED3_(pred, v1, v2, v3, NLIB_TESTING_FATAL_) 202 #define EXPECT_PRED3(pred, v1, v2, v3) NLIB_TESTING_PRED3_(pred, v1, v2, v3, NLIB_TESTING_NONFATAL_) 203 #define ASSERT_PRED_FORMAT3(pred_format, v1, v2, v3) \ 204 NLIB_TESTING_PRED_FORMAT3_(pred_format, v1, v2, v3, NLIB_TESTING_FATAL_) 205 #define EXPECT_PRED_FORMAT3(pred_format, v1, v2, v3) \ 206 NLIB_TESTING_PRED_FORMAT3_(pred_format, v1, v2, v3, NLIB_TESTING_NONFATAL_) 208 #define ASSERT_PRED4(pred, v1, v2, v3, v4) \ 209 NLIB_TESTING_PRED4_(pred, v1, v2, v3, v4, NLIB_TESTING_FATAL_) 210 #define EXPECT_PRED4(pred, v1, v2, v3, v4) \ 211 NLIB_TESTING_PRED4_(pred, v1, v2, v3, v4, NLIB_TESTING_NONFATAL_) 212 #define ASSERT_PRED_FORMAT4(pred_format, v1, v2, v3, v4) \ 213 NLIB_TESTING_PRED_FORMAT4_(pred_format, v1, v2, v3, v4, NLIB_TESTING_FATAL_) 214 #define EXPECT_PRED_FORMAT4(pred_format, v1, v2, v3, v4) \ 215 NLIB_TESTING_PRED_FORMAT4_(pred_format, v1, v2, v3, v4, NLIB_TESTING_NONFATAL_) 217 #define ASSERT_PRED5(pred, v1, v2, v3, v4, v5) \ 218 NLIB_TESTING_PRED5_(pred, v1, v2, v3, v4, v5, NLIB_TESTING_FATAL_) 219 #define EXPECT_PRED5(pred, v1, v2, v3, v4, v5) \ 220 NLIB_TESTING_PRED5_(pred, v1, v2, v3, v4, v5, NLIB_TESTING_NONFATAL_) 221 #define ASSERT_PRED_FORMAT5(pred_format, v1, v2, v3, v4, v5) \ 222 NLIB_TESTING_PRED_FORMAT5_(pred_format, v1, v2, v3, v4, v5, NLIB_TESTING_FATAL_) 223 #define EXPECT_PRED_FORMAT5(pred_format, v1, v2, v3, v4, v5) \ 224 NLIB_TESTING_PRED_FORMAT5_(pred_format, v1, v2, v3, v4, v5, NLIB_TESTING_NONFATAL_) 226 #endif // INCLUDE_NN_NLIB_TESTING_PRED_H_