Added "TestableAssertions.h" as a header file to add specializations for operations on Testable objects, like assert_equal for vectors of Testable objects. The separate header file is so that changes don't require recompiling the entire library.
parent
1c72d92365
commit
16d283d1e1
|
|
@ -19,7 +19,7 @@ check_PROGRAMS += tests/testSPQRUtil
|
|||
endif
|
||||
|
||||
# Testing
|
||||
headers += Testable.h numericalDerivative.h
|
||||
headers += Testable.h TestableAssertions.h numericalDerivative.h
|
||||
|
||||
# Lie Groups
|
||||
headers += Lie.h Lie-inl.h
|
||||
|
|
|
|||
|
|
@ -0,0 +1,34 @@
|
|||
/**
|
||||
* @file TestableAssertions.h
|
||||
* @brief Provides additional testing facilities for common data structures
|
||||
* @author Alex Cunningham
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <vector>
|
||||
#include <boost/foreach.hpp>
|
||||
#include "Testable.h"
|
||||
|
||||
namespace gtsam {
|
||||
|
||||
/**
|
||||
* Version of assert_equals to work with vectors
|
||||
*/
|
||||
template<class V>
|
||||
bool assert_equal(const std::vector<V>& expected, const std::vector<V>& actual, double tol = 1e-9) {
|
||||
if (expected.size() != actual.size()) {
|
||||
printf("Sizes not equal:\n");
|
||||
printf("expected size: %lu\n", expected.size());
|
||||
printf("actual size: %lu\n", actual.size());
|
||||
return false;
|
||||
}
|
||||
size_t i = 0;
|
||||
BOOST_FOREACH(const V& a, expected) {
|
||||
if (!assert_equal(a, expected[i++], tol))
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
} // \namespace gtsam
|
||||
Loading…
Reference in New Issue