How to compare vectors with Boost.Test?

Viewed 17127

I am using Boost Test to unit test some C++ code.

I have a vector of values that I need to compare with expected results, but I don't want to manually check the values in a loop:

BOOST_REQUIRE_EQUAL(values.size(), expected.size());

for( int i = 0; i < size; ++i )
{
    BOOST_CHECK_EQUAL(values[i], expected[i]);
}

The main problem is that the loop check doesn't print the index, so it requires some searching to find the mismatch.

I could use std::equal or std::mismatch on the two vectors, but that will require a lot of boilerplate as well.

Is there a cleaner way to do this?

5 Answers
Related