23 #include <boost/optional.hpp> 35 if(expected != actual) {
36 std::cout <<
"Not equal:\nexpected: " << expected <<
"\nactual: " << actual << std::endl;
51 const boost::optional<V>& actual,
double tol = 1
e-9) {
52 if (!expected && actual) {
53 std::cout <<
"expected is boost::none, while actual is not" << std::endl;
56 if (expected && !actual) {
57 std::cout <<
"actual is boost::none, while expected is not" << std::endl;
60 if (!expected && !actual)
68 std::cout <<
"actual is boost::none" << std::endl;
77 std::cout <<
"actual is boost::none" << std::endl;
90 if (expected.size() != actual.size())
94 for(
const V&
a: expected) {
102 std::cout <<
"expected: " << std::endl;
103 for(
const V&
a: expected) { std::cout <<
a <<
" "; }
104 std::cout <<
"\nactual: " << std::endl;
105 for(
const V&
a: actual) { std::cout <<
a <<
" "; }
106 std::cout << std::endl;
116 template<
class V1,
class V2>
118 typedef typename std::map<V1,V2> Map;
120 if (expected.size() != actual.size())
122 typename Map::const_iterator
123 itExp = expected.begin(),
124 itAct = actual.begin();
126 for (; itExp!=expected.end() && itAct!=actual.end(); ++itExp, ++itAct) {
135 std::cout <<
"expected: " << std::endl;
136 for(
const typename Map::value_type&
a: expected) {
137 a.first.print(
"key");
138 a.second.print(
" value");
140 std::cout <<
"\nactual: " << std::endl;
141 for(
const typename Map::value_type&
a: actual) {
142 a.first.print(
"key");
143 a.second.print(
" value");
145 std::cout << std::endl;
156 typedef typename std::map<size_t,V2> Map;
158 if (expected.size() != actual.size())
160 typename Map::const_iterator
161 itExp = expected.begin(),
162 itAct = actual.begin();
164 for (; itExp!=expected.end() && itAct!=actual.end(); ++itExp, ++itAct) {
165 if (itExp->first != itAct->first ||
173 std::cout <<
"expected: " << std::endl;
174 for(
const typename Map::value_type&
a: expected) {
175 std::cout <<
"Key: " <<
a.first << std::endl;
176 a.second.print(
" value");
178 std::cout <<
"\nactual: " << std::endl;
179 for(
const typename Map::value_type&
a: actual) {
180 std::cout <<
"Key: " <<
a.first << std::endl;
181 a.second.print(
" value");
183 std::cout << std::endl;
192 template<
class V1,
class V2>
194 const std::vector<std::pair<V1,V2> >& actual,
double tol = 1
e-9) {
195 typedef typename std::vector<std::pair<V1,V2> > VectorPair;
197 if (
expected.size() != actual.size())
199 typename VectorPair::const_iterator
201 itAct = actual.begin();
203 for (; itExp!=
expected.end() && itAct!=actual.end(); ++itExp, ++itAct) {
212 std::cout <<
"expected: " << std::endl;
213 for(
const typename VectorPair::value_type&
a:
expected) {
214 a.first.print(
" first ");
215 a.second.print(
" second");
217 std::cout <<
"\nactual: " << std::endl;
218 for(
const typename VectorPair::value_type&
a: actual) {
219 a.first.print(
" first ");
220 a.second.print(
" second");
222 std::cout << std::endl;
235 typename V::const_iterator
236 itExp = expected.begin(),
237 itAct = actual.begin();
239 for (; itExp!=expected.end() && itAct!=actual.end(); ++itExp, ++itAct) {
245 if(itExp != expected.end() || itAct != actual.end())
249 std::cout <<
"expected: " << std::endl;
250 for(
const typename V::value_type&
a: expected) {
a.print(
" "); }
251 std::cout <<
"\nactual: " << std::endl;
252 for(
const typename V::value_type&
a: actual) {
a.print(
" "); }
253 std::cout << std::endl;
265 typedef typename std::map<size_t,V2> Map;
267 if (expected.size() != actual.size())
269 typename Map::const_iterator
270 itExp = expected.begin(),
271 itAct = actual.begin();
273 for (; itExp!=expected.end() && itAct!=actual.end(); ++itExp, ++itAct) {
274 if (itExp->first != itAct->first || itExp->second != itAct->second) {
281 std::cout <<
"expected: " << std::endl;
282 for(
const typename Map::value_type&
a: expected) {
283 std::cout <<
"Key: " <<
a.first << std::endl;
284 std::cout <<
"Value: " <<
a.second << std::endl;
286 std::cout <<
"\nactual: " << std::endl;
287 for(
const typename Map::value_type&
a: actual) {
288 std::cout <<
"Key: " <<
a.first << std::endl;
289 std::cout <<
"Value: " <<
a.second << std::endl;
291 std::cout << std::endl;
304 if (expected.size() != actual.size())
306 typename V::const_iterator
307 itExp = expected.begin(),
308 itAct = actual.begin();
310 for (; itExp!=expected.end() && itAct!=actual.end(); ++itExp, ++itAct) {
311 if (*itExp != *itAct) {
318 std::cout <<
"expected: " << std::endl;
319 for(
const typename V::value_type&
a: expected) { std::cout <<
a <<
" "; }
320 std::cout <<
"\nactual: " << std::endl;
321 for(
const typename V::value_type&
a: actual) { std::cout <<
a <<
" "; }
322 std::cout << std::endl;
332 if (expected == actual)
334 printf(
"Not equal:\n");
335 std::cout <<
"expected: [" << expected <<
"]\n";
336 std::cout <<
"actual: [" << actual <<
"]" << std::endl;
345 if (!actual.equals(expected,
tol))
347 printf(
"Erroneously equal:\n");
348 expected.print(
"expected");
349 actual.print(
"actual");
361 std::streambuf* old = std::cout.rdbuf(buffer.rdbuf());
367 std::string actual_ = buffer.str();
368 std::cout.rdbuf(old);
380 const std::string&
s =
"") {
384 std::streambuf* old = std::cout.rdbuf(buffer.rdbuf());
390 std::string actual_ = buffer.str();
391 std::cout.rdbuf(old);
bool assert_stdout_equal(const std::string &expected, const V &actual)
Concept check for values that can be used in unit tests.
bool assert_print_equal(const std::string &expected, const V &actual, const std::string &s="")
bool assert_container_equality(const std::map< size_t, V2 > &expected, const std::map< size_t, V2 > &actual)
Included from all GTSAM files.
Array< double, 1, 3 > e(1./3., 0.5, 2.)
bool assert_container_equal(const std::map< V1, V2 > &expected, const std::map< V1, V2 > &actual, double tol=1e-9)
bool assert_equal(const Matrix &expected, const Matrix &actual, double tol)
bool assert_inequal(const Matrix &A, const Matrix &B, double tol)
std::uint64_t Key
Integer nonlinear key type.