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 = 1e-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)
66bool assert_equal(
const V& expected,
const boost::optional<V>& actual,
double tol = 1e-9) {
68 std::cout <<
"actual is boost::none" << std::endl;
75bool assert_equal(
const V& expected,
const boost::optional<const V&>& actual,
double tol = 1e-9) {
77 std::cout <<
"actual is boost::none" << std::endl;
88bool GTSAM_DEPRECATED
assert_equal(
const std::vector<V>& expected,
const std::vector<V>& actual,
double tol = 1e-9) {
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;
116template<
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;
192template<
class V1,
class V2>
194 const std::vector<std::pair<V1,V2> >& actual,
double tol = 1e-9) {
195 typedef typename std::vector<std::pair<V1,V2> > VectorPair;
197 if (expected.size() != actual.size())
199 typename VectorPair::const_iterator
200 itExp = expected.begin(),
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;
331inline bool assert_equal(
const std::string& expected,
const std::string& actual) {
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");
359 std::stringstream buffer;
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 =
"") {
382 std::stringstream buffer;
384 std::streambuf* old = std::cout.rdbuf(buffer.rdbuf());
390 std::string actual_ = buffer.str();
391 std::cout.rdbuf(old);
Concept check for values that can be used in unit tests.
Included from all GTSAM files.
Global functions in a separate testing namespace.
Definition: chartTesting.h:28
bool assert_stdout_equal(const std::string &expected, const V &actual)
Capture std out via cout stream and compare against string.
Definition: TestableAssertions.h:357
bool assert_container_equal(const std::map< V1, V2 > &expected, const std::map< V1, V2 > &actual, double tol=1e-9)
Function for comparing maps of testable->testable TODO: replace with more generalized version.
Definition: TestableAssertions.h:117
bool assert_equal(const Matrix &expected, const Matrix &actual, double tol)
equals with an tolerance, prints out message if unequal
Definition: Matrix.cpp:42
bool assert_container_equality(const std::map< size_t, V2 > &expected, const std::map< size_t, V2 > &actual)
Function for comparing maps of size_t->testable Types are assumed to have operator ==.
Definition: TestableAssertions.h:264
bool assert_inequal(const Matrix &A, const Matrix &B, double tol)
inequals with an tolerance, prints out message if within tolerance
Definition: Matrix.cpp:62
bool assert_print_equal(const std::string &expected, const V &actual, const std::string &s="")
Capture print function output and compare against string.
Definition: TestableAssertions.h:379
std::uint64_t Key
Integer nonlinear key type.
Definition: types.h:69