3 #ifndef INCLUDE_NN_NLIB_TESTING_PRED_H_ 4 #define INCLUDE_NN_NLIB_TESTING_PRED_H_ 11 template <
class Pred,
class T1>
12 AssertionResult EvalPred1(
const char* pred_text,
const char* e1, Pred pred,
const T1& v1) {
13 return pred(v1) ? AssertionResult(
true) : AssertionResult(false)
14 << pred_text <<
"(" << e1
15 <<
") evaluates to false, where" 16 <<
"\n" << e1 <<
" evaluates to " << v1;
19 template <
class Pred,
class T1,
class T2>
20 AssertionResult EvalPred2(
const char* pred_text,
const char* e1,
const char* e2, Pred pred,
21 const T1& v1,
const T2& v2) {
22 return pred(v1, v2) ? AssertionResult(
true) : AssertionResult(false)
23 << pred_text <<
"(" << e1 <<
", " << e2
24 <<
") evaluates to false, where" 25 <<
"\n" << e1 <<
" evaluates to " << v1
26 <<
"\n" << e2 <<
" evaluates to " << v2;
29 template <
class Pred,
class T1,
class T2,
class T3>
30 AssertionResult EvalPred3(
const char* pred_text,
const char* e1,
const char* e2,
const char* e3,
31 Pred pred,
const T1& v1,
const T2& v2,
const T3& v3) {
32 return pred(v1, v2, v3) ? AssertionResult(
true)
33 : AssertionResult(false) << pred_text <<
"(" << e1 <<
", " << e2 <<
", " 34 << e3 <<
") evaluates to false, where" 35 <<
"\n" << e1 <<
" evaluates to " << v1 <<
"\n" 36 << e2 <<
" evaluates to " << v2 <<
"\n" << e3
37 <<
" evaluates to " << v3;
40 template <
class Pred,
class T1,
class T2,
class T3,
class T4>
41 AssertionResult EvalPred4(
const char* pred_text,
const char* e1,
const char* e2,
const char* e3,
42 const char* e4, Pred pred,
const T1& v1,
const T2& v2,
const T3& v3,
44 return pred(v1, v2, v3, v4) ? AssertionResult(
true)
45 : AssertionResult(false)
46 << pred_text <<
"(" << e1 <<
", " << e2 <<
", " << e3 <<
", " 47 << e4 <<
") evaluates to false, where" 48 <<
"\n" << e1 <<
" evaluates to " << v1 <<
"\n" << e2
49 <<
" evaluates to " << v2 <<
"\n" << e3 <<
" evaluates to " 50 << v3 <<
"\n" << e4 <<
" evaluates to " << v4;
53 template <
class Pred,
class T1,
class T2,
class T3,
class T4,
class T5>
54 AssertionResult EvalPred5(
const char* pred_text,
const char* e1,
const char* e2,
const char* e3,
55 const char* e4,
const char* e5, Pred pred,
const T1& v1,
const T2& v2,
56 const T3& v3,
const T4& v4,
const T5& v5) {
57 return pred(v1, v2, v3, v4, v5)
58 ? AssertionResult(
true)
59 : AssertionResult(false) << pred_text <<
"(" << e1 <<
", " << e2 <<
", " << e3
60 <<
", " << e4 <<
", " << e5 <<
") 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 <<
"\n" << e5
64 <<
" evaluates to " << v5;
70 #define NLIB_TESTING_PRED1_(pred, v1, iffail) \ 74 if (::nlib_ns::testing::AssertionResult ar = \ 75 ::nlib_ns::testing::EvalPred1(#pred, #v1, pred, v1)) \ 80 #define NLIB_TESTING_PRED2_(pred, v1, v2, iffail) \ 84 if (::nlib_ns::testing::AssertionResult ar = \ 85 ::nlib_ns::testing::EvalPred2(#pred, #v1, #v2, pred, v1, v2)) \ 90 #define NLIB_TESTING_PRED3_(pred, v1, v2, v3, iffail) \ 94 if (::nlib_ns::testing::AssertionResult ar = \ 95 ::nlib_ns::testing::EvalPred3(#pred, #v1, #v2, #v3, pred, v1, v2, v3)) \ 100 #define NLIB_TESTING_PRED4_(pred, v1, v2, v3, v4, iffail) \ 104 if (::nlib_ns::testing::AssertionResult ar = \ 105 ::nlib_ns::testing::EvalPred4(#pred, #v1, #v2, #v3, #v4, pred, v1, v2, v3, v4)) \ 110 #define NLIB_TESTING_PRED5_(pred, v1, v2, v3, v4, v5, iffail) \ 114 if (::nlib_ns::testing::AssertionResult ar = ::nlib_ns::testing::EvalPred5( \ 115 #pred, #v1, #v2, #v3, #v4, #v5, pred, v1, v2, v3, v4, v5)) \ 120 #define NLIB_TESTING_PRED_FORMAT1_(pred_format, v1, iffail) \ 124 if (::nlib_ns::testing::AssertionResult ar = pred_format(#v1, v1)) \ 129 #define NLIB_TESTING_PRED_FORMAT2_(pred_format, v1, v2, iffail) \ 133 if (::nlib_ns::testing::AssertionResult ar = pred_format(#v1, #v2, v1, v2)) \ 138 #define NLIB_TESTING_PRED_FORMAT3_(pred_format, v1, v2, v3, iffail) \ 142 if (::nlib_ns::testing::AssertionResult ar = pred_format(#v1, #v2, #v3, v1, v2, v3)) \ 147 #define NLIB_TESTING_PRED_FORMAT4_(pred_format, v1, v2, v3, v4, iffail) \ 151 if (::nlib_ns::testing::AssertionResult ar = \ 152 pred_format(#v1, #v2, #v3, #v4, v1, v2, v3, v4)) \ 157 #define NLIB_TESTING_PRED_FORMAT5_(pred_format, v1, v2, v3, v4, v5, iffail) \ 161 if (::nlib_ns::testing::AssertionResult ar = \ 162 pred_format(#v1, #v2, #v3, #v4, #v5, v1, v2, v3, v4, v5)) \ 167 #define ASSERT_PRED1(pred, v1) NLIB_TESTING_PRED1_(pred, v1, NLIB_TESTING_FATAL_) 168 #define EXPECT_PRED1(pred, v1) NLIB_TESTING_PRED1_(pred, v1, NLIB_TESTING_NONFATAL_) 169 #define ASSERT_PRED_FORMAT1(pred_format, v1) \ 170 NLIB_TESTING_PRED_FORMAT1_(pred_format, v1, NLIB_TESTING_FATAL_) 171 #define EXPECT_PRED_FORMAT1(pred_format, v1) \ 172 NLIB_TESTING_PRED_FORMAT1_(pred_format, v1, NLIB_TESTING_NONFATAL_) 174 #define ASSERT_PRED2(pred, v1, v2) NLIB_TESTING_PRED2_(pred, v1, v2, NLIB_TESTING_FATAL_) 175 #define EXPECT_PRED2(pred, v1, v2) NLIB_TESTING_PRED2_(pred, v1, v2, NLIB_TESTING_NONFATAL_) 176 #define ASSERT_PRED_FORMAT2(pred_format, v1, v2) \ 177 NLIB_TESTING_PRED_FORMAT2_(pred_format, v1, v2, NLIB_TESTING_FATAL_) 178 #define EXPECT_PRED_FORMAT2(pred_format, v1, v2) \ 179 NLIB_TESTING_PRED_FORMAT2_(pred_format, v1, v2, NLIB_TESTING_NONFATAL_) 181 #define ASSERT_PRED3(pred, v1, v2, v3) NLIB_TESTING_PRED3_(pred, v1, v2, v3, NLIB_TESTING_FATAL_) 182 #define EXPECT_PRED3(pred, v1, v2, v3) NLIB_TESTING_PRED3_(pred, v1, v2, v3, NLIB_TESTING_NONFATAL_) 183 #define ASSERT_PRED_FORMAT3(pred_format, v1, v2, v3) \ 184 NLIB_TESTING_PRED_FORMAT3_(pred_format, v1, v2, v3, NLIB_TESTING_FATAL_) 185 #define EXPECT_PRED_FORMAT3(pred_format, v1, v2, v3) \ 186 NLIB_TESTING_PRED_FORMAT3_(pred_format, v1, v2, v3, NLIB_TESTING_NONFATAL_) 188 #define ASSERT_PRED4(pred, v1, v2, v3, v4) \ 189 NLIB_TESTING_PRED4_(pred, v1, v2, v3, v4, NLIB_TESTING_FATAL_) 190 #define EXPECT_PRED4(pred, v1, v2, v3, v4) \ 191 NLIB_TESTING_PRED4_(pred, v1, v2, v3, v4, NLIB_TESTING_NONFATAL_) 192 #define ASSERT_PRED_FORMAT4(pred_format, v1, v2, v3, v4) \ 193 NLIB_TESTING_PRED_FORMAT4_(pred_format, v1, v2, v3, v4, NLIB_TESTING_FATAL_) 194 #define EXPECT_PRED_FORMAT4(pred_format, v1, v2, v3, v4) \ 195 NLIB_TESTING_PRED_FORMAT4_(pred_format, v1, v2, v3, v4, NLIB_TESTING_NONFATAL_) 197 #define ASSERT_PRED5(pred, v1, v2, v3, v4, v5) \ 198 NLIB_TESTING_PRED5_(pred, v1, v2, v3, v4, v5, NLIB_TESTING_FATAL_) 199 #define EXPECT_PRED5(pred, v1, v2, v3, v4, v5) \ 200 NLIB_TESTING_PRED5_(pred, v1, v2, v3, v4, v5, NLIB_TESTING_NONFATAL_) 201 #define ASSERT_PRED_FORMAT5(pred_format, v1, v2, v3, v4, v5) \ 202 NLIB_TESTING_PRED_FORMAT5_(pred_format, v1, v2, v3, v4, v5, NLIB_TESTING_FATAL_) 203 #define EXPECT_PRED_FORMAT5(pred_format, v1, v2, v3, v4, v5) \ 204 NLIB_TESTING_PRED_FORMAT5_(pred_format, v1, v2, v3, v4, v5, NLIB_TESTING_NONFATAL_) 206 #endif // INCLUDE_NN_NLIB_TESTING_PRED_H_ Defines the macro for a basic, simple test.