23 #include <boost/optional.hpp> 34 if(expected != actual) {
35 std::cout <<
"Not equal:\nexpected: " << expected <<
"\nactual: " << actual << std::endl;
50 const boost::optional<V>& actual,
double tol = 1e-9) {
51 if (!expected && actual) {
52 std::cout <<
"expected is boost::none, while actual is not" << std::endl;
55 if (expected && !actual) {
56 std::cout <<
"actual is boost::none, while expected is not" << std::endl;
59 if (!expected && !actual)
65 bool assert_equal(
const V& expected,
const boost::optional<V>& actual,
double tol = 1e-9) {
67 std::cout <<
"actual is boost::none" << std::endl;
74 bool assert_equal(
const V& expected,
const boost::optional<const V&>& actual,
double tol = 1e-9) {
76 std::cout <<
"actual is boost::none" << std::endl;
87 bool assert_equal(
const std::vector<V>& expected,
const std::vector<V>& actual,
double tol = 1e-9) {
89 if (expected.size() != actual.size())
93 for(
const V& a: expected) {
101 std::cout <<
"expected: " << std::endl;
102 for(
const V& a: expected) { std::cout << a <<
" "; }
103 std::cout <<
"\nactual: " << std::endl;
104 for(
const V& a: actual) { std::cout << a <<
" "; }
105 std::cout << std::endl;
115 template<
class V1,
class V2>
117 typedef typename std::map<V1,V2> Map;
119 if (expected.size() != actual.size())
121 typename Map::const_iterator
122 itExp = expected.begin(),
123 itAct = actual.begin();
125 for (; itExp!=expected.end() && itAct!=actual.end(); ++itExp, ++itAct) {
134 std::cout <<
"expected: " << std::endl;
135 for(
const typename Map::value_type& a: expected) {
136 a.first.print(
"key");
137 a.second.print(
" value");
139 std::cout <<
"\nactual: " << std::endl;
140 for(
const typename Map::value_type& a: actual) {
141 a.first.print(
"key");
142 a.second.print(
" value");
144 std::cout << std::endl;
155 typedef typename std::map<size_t,V2> Map;
157 if (expected.size() != actual.size())
159 typename Map::const_iterator
160 itExp = expected.begin(),
161 itAct = actual.begin();
163 for (; itExp!=expected.end() && itAct!=actual.end(); ++itExp, ++itAct) {
164 if (itExp->first != itAct->first ||
172 std::cout <<
"expected: " << std::endl;
173 for(
const typename Map::value_type& a: expected) {
174 std::cout <<
"Key: " << a.first << std::endl;
175 a.second.print(
" value");
177 std::cout <<
"\nactual: " << std::endl;
178 for(
const typename Map::value_type& a: actual) {
179 std::cout <<
"Key: " << a.first << std::endl;
180 a.second.print(
" value");
182 std::cout << std::endl;
191 template<
class V1,
class V2>
193 const std::vector<std::pair<V1,V2> >& actual,
double tol = 1e-9) {
194 typedef typename std::vector<std::pair<V1,V2> > VectorPair;
196 if (expected.size() != actual.size())
198 typename VectorPair::const_iterator
199 itExp = expected.begin(),
200 itAct = actual.begin();
202 for (; itExp!=expected.end() && itAct!=actual.end(); ++itExp, ++itAct) {
211 std::cout <<
"expected: " << std::endl;
212 for(
const typename VectorPair::value_type& a: expected) {
213 a.first.print(
" first ");
214 a.second.print(
" second");
216 std::cout <<
"\nactual: " << std::endl;
217 for(
const typename VectorPair::value_type& a: actual) {
218 a.first.print(
" first ");
219 a.second.print(
" second");
221 std::cout << std::endl;
234 typename V::const_iterator
235 itExp = expected.begin(),
236 itAct = actual.begin();
238 for (; itExp!=expected.end() && itAct!=actual.end(); ++itExp, ++itAct) {
244 if(itExp != expected.end() || itAct != actual.end())
248 std::cout <<
"expected: " << std::endl;
249 for(
const typename V::value_type& a: expected) { a.print(
" "); }
250 std::cout <<
"\nactual: " << std::endl;
251 for(
const typename V::value_type& a: actual) { a.print(
" "); }
252 std::cout << std::endl;
264 typedef typename std::map<size_t,V2> Map;
266 if (expected.size() != actual.size())
268 typename Map::const_iterator
269 itExp = expected.begin(),
270 itAct = actual.begin();
272 for (; itExp!=expected.end() && itAct!=actual.end(); ++itExp, ++itAct) {
273 if (itExp->first != itAct->first || itExp->second != itAct->second) {
280 std::cout <<
"expected: " << std::endl;
281 for(
const typename Map::value_type& a: expected) {
282 std::cout <<
"Key: " << a.first << std::endl;
283 std::cout <<
"Value: " << a.second << std::endl;
285 std::cout <<
"\nactual: " << std::endl;
286 for(
const typename Map::value_type& a: actual) {
287 std::cout <<
"Key: " << a.first << std::endl;
288 std::cout <<
"Value: " << a.second << std::endl;
290 std::cout << std::endl;
303 if (expected.size() != actual.size())
305 typename V::const_iterator
306 itExp = expected.begin(),
307 itAct = actual.begin();
309 for (; itExp!=expected.end() && itAct!=actual.end(); ++itExp, ++itAct) {
310 if (*itExp != *itAct) {
317 std::cout <<
"expected: " << std::endl;
318 for(
const typename V::value_type& a: expected) { std::cout << a <<
" "; }
319 std::cout <<
"\nactual: " << std::endl;
320 for(
const typename V::value_type& a: actual) { std::cout << a <<
" "; }
321 std::cout << std::endl;
330 inline bool assert_equal(
const std::string& expected,
const std::string& actual) {
331 if (expected == actual)
333 printf(
"Not equal:\n");
334 std::cout <<
"expected: [" << expected <<
"]\n";
335 std::cout <<
"actual: [" << actual <<
"]" << std::endl;
344 if (!actual.equals(expected, tol))
346 printf(
"Erroneously equal:\n");
347 expected.print(
"expected");
348 actual.print(
"actual");
bool assert_equal(const Matrix &expected, const Matrix &actual, double tol)
equals with an tolerance, prints out message if unequal
Definition: Matrix.cpp:42
std::uint64_t Key
Integer nonlinear key type.
Definition: types.h:57
Included from all GTSAM files.
Global functions in a separate testing namespace.
Definition: chartTesting.h:28
Concept check for values that can be used in unit tests.
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_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:263
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:116