37 if(expected != actual) {
38 std::cout <<
"Not equal:\nexpected: " << expected <<
"\nactual: " << actual << std::endl;
53 const std::optional<V>& actual,
double tol = 1e-9) {
54 if (!expected && actual) {
55 std::cout <<
"expected is {}, while actual is not" << std::endl;
58 if (expected && !actual) {
59 std::cout <<
"actual is {}, while expected is not" << std::endl;
62 if (!expected && !actual)
68bool assert_equal(
const V& expected,
const std::optional<V>& actual,
double tol = 1e-9) {
70 std::cout <<
"actual is {}" << std::endl;
78 const std::optional<std::reference_wrapper<const V>>& actual,
double tol = 1e-9) {
80 std::cout <<
"actual is std::nullopt" << std::endl;
90template<
class V1,
class V2>
92 typedef typename std::map<V1,V2> Map;
94 if (expected.size() != actual.size())
96 typename Map::const_iterator
97 itExp = expected.begin(),
98 itAct = actual.begin();
100 for (; itExp!=expected.end() && itAct!=actual.end(); ++itExp, ++itAct) {
109 std::cout <<
"expected: " << std::endl;
110 for(
const typename Map::value_type& a: expected) {
111 a.first.print(
"key");
112 a.second.print(
" value");
114 std::cout <<
"\nactual: " << std::endl;
115 for(
const typename Map::value_type& a: actual) {
116 a.first.print(
"key");
117 a.second.print(
" value");
119 std::cout << std::endl;
130 typedef typename std::map<size_t,V2> Map;
132 if (expected.size() != actual.size())
134 typename Map::const_iterator
135 itExp = expected.begin(),
136 itAct = actual.begin();
138 for (; itExp!=expected.end() && itAct!=actual.end(); ++itExp, ++itAct) {
139 if (itExp->first != itAct->first ||
147 std::cout <<
"expected: " << std::endl;
148 for(
const typename Map::value_type& a: expected) {
149 std::cout <<
"Key: " << a.first << std::endl;
150 a.second.print(
" value");
152 std::cout <<
"\nactual: " << std::endl;
153 for(
const typename Map::value_type& a: actual) {
154 std::cout <<
"Key: " << a.first << std::endl;
155 a.second.print(
" value");
157 std::cout << std::endl;
166template<
class V1,
class V2>
168 const std::vector<std::pair<V1,V2> >& actual,
double tol = 1e-9) {
169 typedef typename std::vector<std::pair<V1,V2> > VectorPair;
171 if (expected.size() != actual.size())
173 typename VectorPair::const_iterator
174 itExp = expected.begin(),
175 itAct = actual.begin();
177 for (; itExp!=expected.end() && itAct!=actual.end(); ++itExp, ++itAct) {
186 std::cout <<
"expected: " << std::endl;
187 for(
const typename VectorPair::value_type& a: expected) {
188 a.first.print(
" first ");
189 a.second.print(
" second");
191 std::cout <<
"\nactual: " << std::endl;
192 for(
const typename VectorPair::value_type& a: actual) {
193 a.first.print(
" first ");
194 a.second.print(
" second");
196 std::cout << std::endl;
209 typename V::const_iterator
210 itExp = expected.begin(),
211 itAct = actual.begin();
213 for (; itExp!=expected.end() && itAct!=actual.end(); ++itExp, ++itAct) {
219 if(itExp != expected.end() || itAct != actual.end())
223 std::cout <<
"expected: " << std::endl;
224 for(
const typename V::value_type& a: expected) { a.print(
" "); }
225 std::cout <<
"\nactual: " << std::endl;
226 for(
const typename V::value_type& a: actual) { a.print(
" "); }
227 std::cout << std::endl;
239 typedef typename std::map<size_t,V2> Map;
241 if (expected.size() != actual.size())
243 typename Map::const_iterator
244 itExp = expected.begin(),
245 itAct = actual.begin();
247 for (; itExp!=expected.end() && itAct!=actual.end(); ++itExp, ++itAct) {
248 if (itExp->first != itAct->first || itExp->second != itAct->second) {
255 std::cout <<
"expected: " << std::endl;
256 for(
const typename Map::value_type& a: expected) {
257 std::cout <<
"Key: " << a.first << std::endl;
258 std::cout <<
"Value: " << a.second << std::endl;
260 std::cout <<
"\nactual: " << std::endl;
261 for(
const typename Map::value_type& a: actual) {
262 std::cout <<
"Key: " << a.first << std::endl;
263 std::cout <<
"Value: " << a.second << std::endl;
265 std::cout << std::endl;
278 if (expected.size() != actual.size())
280 typename V::const_iterator
281 itExp = expected.begin(),
282 itAct = actual.begin();
284 for (; itExp!=expected.end() && itAct!=actual.end(); ++itExp, ++itAct) {
285 if (*itExp != *itAct) {
292 std::cout <<
"expected: " << std::endl;
293 for(
const typename V::value_type& a: expected) { std::cout << a <<
" "; }
294 std::cout <<
"\nactual: " << std::endl;
295 for(
const typename V::value_type& a: actual) { std::cout << a <<
" "; }
296 std::cout << std::endl;
305inline bool assert_equal(
const std::string& expected,
const std::string& actual) {
306 if (expected == actual)
308 printf(
"Not equal:\n");
309 std::cout <<
"expected: [" << expected <<
"]\n";
310 std::cout <<
"actual: [" << actual <<
"]" << std::endl;
319 if (!actual.equals(expected, tol))
321 printf(
"Erroneously equal:\n");
322 expected.print(
"expected");
323 actual.print(
"actual");
333 std::stringstream buffer;
335 std::streambuf* old = std::cout.rdbuf(buffer.rdbuf());
341 std::string actual_ = buffer.str();
342 std::cout.rdbuf(old);
354 const std::string& s =
"") {
356 std::stringstream buffer;
358 std::streambuf* old = std::cout.rdbuf(buffer.rdbuf());
364 std::string actual_ = buffer.str();
365 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:331
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:91
bool assert_equal(const Matrix &expected, const Matrix &actual, double tol)
equals with an tolerance, prints out message if unequal
Definition Matrix.cpp:39
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:238
bool assert_inequal(const Matrix &A, const Matrix &B, double tol)
inequals with an tolerance, prints out message if within tolerance
Definition Matrix.cpp:59
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:353
std::uint64_t Key
Integer nonlinear key type.
Definition types.h:43