Added assert_container_equal for vectors of pairs of testable objects, output formatting

release/4.3a0
Alex Cunningham 2011-03-16 19:22:42 +00:00
parent 38b89db219
commit 1224c9550b
1 changed files with 47 additions and 9 deletions

View File

@ -56,9 +56,9 @@ bool assert_equal(const std::vector<V>& expected, const std::vector<V>& actual,
}
}
if(!match) {
std::cout << "expected: ";
std::cout << "expected: " << std::endl;
BOOST_FOREACH(const V& a, expected) { std::cout << a << " "; }
std::cout << "\nactual: ";
std::cout << "\nactual: " << std::endl;
BOOST_FOREACH(const V& a, actual) { std::cout << a << " "; }
std::cout << std::endl;
return false;
@ -89,12 +89,12 @@ bool assert_container_equal(const std::map<V1,V2>& expected, const std::map<V1,V
}
}
if(!match) {
std::cout << "expected: ";
std::cout << "expected: " << std::endl;
BOOST_FOREACH(const typename Map::value_type& a, expected) {
a.first.print("key");
a.second.print(" value");
}
std::cout << "\nactual: ";
std::cout << "\nactual: " << std::endl;
BOOST_FOREACH(const typename Map::value_type& a, actual) {
a.first.print("key");
a.second.print(" value");
@ -132,7 +132,7 @@ bool assert_container_equal(const std::map<size_t,V2>& expected, const std::map<
std::cout << "Key: " << a.first << std::endl;
a.second.print(" value");
}
std::cout << "\nactual: ";
std::cout << "\nactual: " << std::endl;
BOOST_FOREACH(const typename Map::value_type& a, actual) {
std::cout << "Key: " << a.first << std::endl;
a.second.print(" value");
@ -143,6 +143,44 @@ bool assert_container_equal(const std::map<size_t,V2>& expected, const std::map<
return true;
}
/**
* Function for comparing vector of pairs (testable, testable)
*/
template<class V1, class V2>
bool assert_container_equal(const std::vector<V1,V2>& expected, const std::vector<V1,V2>& actual, double tol = 1e-9) {
typedef typename std::vector<V1,V2> VectorPair;
bool match = true;
if (expected.size() != actual.size())
match = false;
typename VectorPair::const_iterator
itExp = expected.begin(),
itAct = actual.begin();
if(match) {
for (; itExp!=expected.end() && itAct!=actual.end(); ++itExp, ++itAct) {
if (!assert_equal(itExp->first, itAct->first, tol) ||
!assert_equal(itExp->second, itAct->second, tol)) {
match = false;
break;
}
}
}
if(!match) {
std::cout << "expected: " << std::endl;
BOOST_FOREACH(const typename VectorPair::value_type& a, expected) {
a.first.print( " first ");
a.second.print(" second");
}
std::cout << "\nactual: " << std::endl;
BOOST_FOREACH(const typename VectorPair::value_type& a, actual) {
a.first.print( " first ");
a.second.print(" second");
}
std::cout << std::endl;
return false;
}
return true;
}
/**
* General function for comparing containers of testable objects
@ -164,9 +202,9 @@ bool assert_container_equal(const V& expected, const V& actual, double tol = 1e-
}
}
if(!match) {
std::cout << "expected: ";
std::cout << "expected: " << std::endl;
BOOST_FOREACH(const typename V::value_type& a, expected) { a.print(" "); }
std::cout << "\nactual: ";
std::cout << "\nactual: " << std::endl;
BOOST_FOREACH(const typename V::value_type& a, actual) { a.print(" "); }
std::cout << std::endl;
return false;
@ -194,9 +232,9 @@ bool assert_container_equality(const V& expected, const V& actual, double tol =
}
}
if(!match) {
std::cout << "expected: ";
std::cout << "expected: " << std::endl;
BOOST_FOREACH(const typename V::value_type& a, expected) { std::cout << a << " "; }
std::cout << "\nactual: ";
std::cout << "\nactual: " << std::endl;
BOOST_FOREACH(const typename V::value_type& a, actual) { std::cout << a << " "; }
std::cout << std::endl;
return false;