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) : AssertionResult(false)
27 << pred_text <<
"(" << e1
28 <<
") evaluates to false, where" 29 <<
"\n" << e1 <<
" evaluates to " << v1;
32 template <
class Pred,
class T1,
class T2>
33 AssertionResult EvalPred2(
const char* pred_text,
const char* e1,
const char* e2, Pred pred,
34 const T1& v1,
const T2& v2) {
35 return pred(v1, v2) ? AssertionResult(
true) : AssertionResult(false)
36 << pred_text <<
"(" << e1 <<
", " << e2
37 <<
") evaluates to false, where" 38 <<
"\n" << e1 <<
" evaluates to " << v1
39 <<
"\n" << e2 <<
" evaluates to " << v2;
42 template <
class Pred,
class T1,
class T2,
class T3>
43 AssertionResult EvalPred3(
const char* pred_text,
const char* e1,
const char* e2,
const char* e3,
44 Pred pred,
const T1& v1,
const T2& v2,
const T3& v3) {
45 return pred(v1, v2, v3) ? AssertionResult(
true)
46 : AssertionResult(false) << pred_text <<
"(" << e1 <<
", " << e2 <<
", " 47 << e3 <<
") evaluates to false, where" 48 <<
"\n" << e1 <<
" evaluates to " << v1 <<
"\n" 49 << e2 <<
" evaluates to " << v2 <<
"\n" << e3
50 <<
" evaluates to " << v3;
53 template <
class Pred,
class T1,
class T2,
class T3,
class T4>
54 AssertionResult EvalPred4(
const char* pred_text,
const char* e1,
const char* e2,
const char* e3,
55 const char* e4, Pred pred,
const T1& v1,
const T2& v2,
const T3& v3,
57 return pred(v1, v2, v3, v4) ? AssertionResult(
true)
58 : AssertionResult(false)
59 << pred_text <<
"(" << e1 <<
", " << e2 <<
", " << e3 <<
", " 60 << e4 <<
") evaluates to false, where" 61 <<
"\n" << e1 <<
" evaluates to " << v1 <<
"\n" << e2
62 <<
" evaluates to " << v2 <<
"\n" << e3 <<
" evaluates to " 63 << v3 <<
"\n" << e4 <<
" evaluates to " << v4;
66 template <
class Pred,
class T1,
class T2,
class T3,
class T4,
class T5>
67 AssertionResult EvalPred5(
const char* pred_text,
const char* e1,
const char* e2,
const char* e3,
68 const char* e4,
const char* e5, Pred pred,
const T1& v1,
const T2& v2,
69 const T3& v3,
const T4& v4,
const T5& v5) {
70 return pred(v1, v2, v3, v4, v5)
71 ? AssertionResult(
true)
72 : AssertionResult(false) << pred_text <<
"(" << e1 <<
", " << e2 <<
", " << e3
73 <<
", " << e4 <<
", " << e5 <<
") evaluates to false, where" 74 <<
"\n" << e1 <<
" evaluates to " << v1 <<
"\n" << e2
75 <<
" evaluates to " << v2 <<
"\n" << e3 <<
" evaluates to " 76 << v3 <<
"\n" << e4 <<
" evaluates to " << v4 <<
"\n" << e5
77 <<
" evaluates to " << v5;
83 #define NLIB_TESTING_PRED1_(pred, v1, iffail) \ 87 if (::nlib_ns::testing::AssertionResult ar = \ 88 ::nlib_ns::testing::EvalPred1(#pred, #v1, pred, v1)) \ 93 #define NLIB_TESTING_PRED2_(pred, v1, v2, iffail) \ 97 if (::nlib_ns::testing::AssertionResult ar = \ 98 ::nlib_ns::testing::EvalPred2(#pred, #v1, #v2, pred, v1, v2)) \ 103 #define NLIB_TESTING_PRED3_(pred, v1, v2, v3, iffail) \ 107 if (::nlib_ns::testing::AssertionResult ar = \ 108 ::nlib_ns::testing::EvalPred3(#pred, #v1, #v2, #v3, pred, v1, v2, v3)) \ 113 #define NLIB_TESTING_PRED4_(pred, v1, v2, v3, v4, iffail) \ 117 if (::nlib_ns::testing::AssertionResult ar = \ 118 ::nlib_ns::testing::EvalPred4(#pred, #v1, #v2, #v3, #v4, pred, v1, v2, v3, v4)) \ 123 #define NLIB_TESTING_PRED5_(pred, v1, v2, v3, v4, v5, iffail) \ 127 if (::nlib_ns::testing::AssertionResult ar = ::nlib_ns::testing::EvalPred5( \ 128 #pred, #v1, #v2, #v3, #v4, #v5, pred, v1, v2, v3, v4, v5)) \ 133 #define NLIB_TESTING_PRED_FORMAT1_(pred_format, v1, iffail) \ 137 if (::nlib_ns::testing::AssertionResult ar = pred_format(#v1, v1)) \ 142 #define NLIB_TESTING_PRED_FORMAT2_(pred_format, v1, v2, iffail) \ 146 if (::nlib_ns::testing::AssertionResult ar = pred_format(#v1, #v2, v1, v2)) \ 151 #define NLIB_TESTING_PRED_FORMAT3_(pred_format, v1, v2, v3, iffail) \ 155 if (::nlib_ns::testing::AssertionResult ar = pred_format(#v1, #v2, #v3, v1, v2, v3)) \ 160 #define NLIB_TESTING_PRED_FORMAT4_(pred_format, v1, v2, v3, v4, iffail) \ 164 if (::nlib_ns::testing::AssertionResult ar = \ 165 pred_format(#v1, #v2, #v3, #v4, v1, v2, v3, v4)) \ 170 #define NLIB_TESTING_PRED_FORMAT5_(pred_format, v1, v2, v3, v4, v5, iffail) \ 174 if (::nlib_ns::testing::AssertionResult ar = \ 175 pred_format(#v1, #v2, #v3, #v4, #v5, v1, v2, v3, v4, v5)) \ 180 #define ASSERT_PRED1(pred, v1) NLIB_TESTING_PRED1_(pred, v1, NLIB_TESTING_FATAL_) 181 #define EXPECT_PRED1(pred, v1) NLIB_TESTING_PRED1_(pred, v1, NLIB_TESTING_NONFATAL_) 182 #define ASSERT_PRED_FORMAT1(pred_format, v1) \ 183 NLIB_TESTING_PRED_FORMAT1_(pred_format, v1, NLIB_TESTING_FATAL_) 184 #define EXPECT_PRED_FORMAT1(pred_format, v1) \ 185 NLIB_TESTING_PRED_FORMAT1_(pred_format, v1, NLIB_TESTING_NONFATAL_) 187 #define ASSERT_PRED2(pred, v1, v2) NLIB_TESTING_PRED2_(pred, v1, v2, NLIB_TESTING_FATAL_) 188 #define EXPECT_PRED2(pred, v1, v2) NLIB_TESTING_PRED2_(pred, v1, v2, NLIB_TESTING_NONFATAL_) 189 #define ASSERT_PRED_FORMAT2(pred_format, v1, v2) \ 190 NLIB_TESTING_PRED_FORMAT2_(pred_format, v1, v2, NLIB_TESTING_FATAL_) 191 #define EXPECT_PRED_FORMAT2(pred_format, v1, v2) \ 192 NLIB_TESTING_PRED_FORMAT2_(pred_format, v1, v2, NLIB_TESTING_NONFATAL_) 194 #define ASSERT_PRED3(pred, v1, v2, v3) NLIB_TESTING_PRED3_(pred, v1, v2, v3, NLIB_TESTING_FATAL_) 195 #define EXPECT_PRED3(pred, v1, v2, v3) NLIB_TESTING_PRED3_(pred, v1, v2, v3, NLIB_TESTING_NONFATAL_) 196 #define ASSERT_PRED_FORMAT3(pred_format, v1, v2, v3) \ 197 NLIB_TESTING_PRED_FORMAT3_(pred_format, v1, v2, v3, NLIB_TESTING_FATAL_) 198 #define EXPECT_PRED_FORMAT3(pred_format, v1, v2, v3) \ 199 NLIB_TESTING_PRED_FORMAT3_(pred_format, v1, v2, v3, NLIB_TESTING_NONFATAL_) 201 #define ASSERT_PRED4(pred, v1, v2, v3, v4) \ 202 NLIB_TESTING_PRED4_(pred, v1, v2, v3, v4, NLIB_TESTING_FATAL_) 203 #define EXPECT_PRED4(pred, v1, v2, v3, v4) \ 204 NLIB_TESTING_PRED4_(pred, v1, v2, v3, v4, NLIB_TESTING_NONFATAL_) 205 #define ASSERT_PRED_FORMAT4(pred_format, v1, v2, v3, v4) \ 206 NLIB_TESTING_PRED_FORMAT4_(pred_format, v1, v2, v3, v4, NLIB_TESTING_FATAL_) 207 #define EXPECT_PRED_FORMAT4(pred_format, v1, v2, v3, v4) \ 208 NLIB_TESTING_PRED_FORMAT4_(pred_format, v1, v2, v3, v4, NLIB_TESTING_NONFATAL_) 210 #define ASSERT_PRED5(pred, v1, v2, v3, v4, v5) \ 211 NLIB_TESTING_PRED5_(pred, v1, v2, v3, v4, v5, NLIB_TESTING_FATAL_) 212 #define EXPECT_PRED5(pred, v1, v2, v3, v4, v5) \ 213 NLIB_TESTING_PRED5_(pred, v1, v2, v3, v4, v5, NLIB_TESTING_NONFATAL_) 214 #define ASSERT_PRED_FORMAT5(pred_format, v1, v2, v3, v4, v5) \ 215 NLIB_TESTING_PRED_FORMAT5_(pred_format, v1, v2, v3, v4, v5, NLIB_TESTING_FATAL_) 216 #define EXPECT_PRED_FORMAT5(pred_format, v1, v2, v3, v4, v5) \ 217 NLIB_TESTING_PRED_FORMAT5_(pred_format, v1, v2, v3, v4, v5, NLIB_TESTING_NONFATAL_) 219 #endif // INCLUDE_NN_NLIB_TESTING_PRED_H_