@@ -77,19 +77,9 @@ static vector<_test *> _tests;
77
77
this ->em.clear(), this ->am.clear(); \
78
78
this ->im.clear(), this ->om.clear()
79
79
80
- #define _GET_FAIL_MSG (e, a ) \
81
- cerr << " expected: " ; \
82
- if (this ->em.empty()) \
83
- cerr << (e); \
84
- else \
85
- cerr << this ->em; \
86
- cerr << " " ; \
87
- cerr << " actual: " ; \
88
- if (this ->am.empty()) \
89
- cerr << (a); \
90
- else \
91
- cerr << this ->am; \
92
- cerr << " ." << endl
80
+ #define _GET_FAIL_MSG () \
81
+ cerr << format(" expected: {} actual: {}." , this ->em, this ->am) \
82
+ << endl
93
83
94
84
#define _GET_SUCCESS_MSG (i, o ) \
95
85
cout << " input: " ; \
@@ -105,14 +95,21 @@ static vector<_test *> _tests;
105
95
cout << this ->om; \
106
96
cout << " .\n "
107
97
98
+ #define SUCCESS () this ->incTc ()
99
+
100
+ #define FAIL () \
101
+ cerr << " test-" << (this ->getTc () + 1) << " failed! "; \
102
+ for (io_t _e : this ->getIo ()) cerr << _e; \
103
+ _GET_FAIL_MSG (); \
104
+ exit (1 );
105
+
108
106
#define _CHECK (op, e, a ) \
109
107
if (e op a) { \
110
- this -> incTc (); \
108
+ SUCCESS (); \
111
109
} else { \
112
- cerr << " test-" << (this ->getTc () + 1 ) << " failed! " ; \
113
- for (io_t _e : this ->getIo ()) cerr << _e; \
114
- _GET_FAIL_MSG (e, a); \
115
- exit (1 ); \
110
+ string em = to_string (e), am = to_string (a); \
111
+ SET_CUSTOM_FAIL_MSG (em, am); \
112
+ FAIL (); \
116
113
}
117
114
118
115
#define CHECK_EQ (e, a ) _CHECK(==, (e), (a))
@@ -155,6 +152,13 @@ static vector<_test *> _tests;
155
152
#define vi_v (v, n, i ) vi_t v ((n), (i))
156
153
#define vi2_v (v, n, i ) vi2_t v ((n), vi_t((n), (i)))
157
154
155
+ template <class T>
156
+ ostream &operator<<(ostream &out, const pair<T, T> &p)
157
+ {
158
+ out << " {" << format (" {}, {}" , p.first , p.second ) << " }" ;
159
+ return out;
160
+ }
161
+
158
162
template <class T >
159
163
ostream &operator <<(ostream &out, const vector<T> &c)
160
164
{
@@ -180,3 +184,9 @@ string to_string(const vector<T> &c)
180
184
oss << c;
181
185
return oss.str ();
182
186
}
187
+
188
+ string to_string (const string &s)
189
+ {
190
+ string q (" \" " );
191
+ return q + s + q;
192
+ }
0 commit comments