我一直试图在Google C++ 测试框架/gtest中找到一个断言,它等同于Boost Test Library中的BOOST_CHECK_EQUAL_COLLECTIONS断言。
然而; 没有成功。所以我的问题有两个:
编辑(稍作修改的答案):
#include <iostream>
template<typename LeftIter, typename RightIter>
::testing::AssertionResult CheckEqualCollections(LeftIter left_begin,
LeftIter left_end,
RightIter right_begin)
{
std::stringstream message;
std::size_t index(0);
bool equal(true);
for(;left_begin != left_end; left_begin++, right_begin++) {
if (*left_begin != *right_begin) {
equal = false;
message << "\n Mismatch in position " << index << ": " << *left_begin << " != " << *right_begin;
}
++index;
}
if (message.str().size()) {
message << "\n";
}
return equal ? ::testing::AssertionSuccess() :
::testing::AssertionFailure() << message.str();
}