Boost C++ Libraries

...one of the most highly regarded and expertly designed C++ library projects in the world. Herb Sutter and Andrei Alexandrescu, C++ Coding Standards

This is the documentation for an old version of Boost. Click here to view this page for the latest version.
PrevUpHomeNext

BOOST_<level>_EQUAL_COLLECTIONS

BOOST_WARN_EQUAL_COLLECTIONS(left_begin, left_end, right_begin, right_end);
BOOST_CHECK_EQUAL_COLLECTIONS(left_begin, left_end, right_begin, right_end);
BOOST_REQUIRE_EQUAL_COLLECTIONS(left_begin, left_end, right_begin, right_end);

These tools are used to perform an element by element comparison of two collections. They print all mismatched positions, collection elements at these positions and check that the collections have the same size. The first two parameters designate begin and end of the first collection. The two last parameters designate begin and end of the second collection.

Example: BOOST_<level>_EQUAL_COLLECTIONS usage

Code

#define BOOST_TEST_MODULE example
#include <boost/test/included/unit_test.hpp>

BOOST_AUTO_TEST_CASE( test )
{
  int col1 [] = { 1, 2, 3, 4, 5, 6, 7 };
  int col2 [] = { 1, 2, 4, 4, 5, 7, 7 };

  BOOST_CHECK_EQUAL_COLLECTIONS( col1, col1+7, col2, col2+7 );
}

Output

> example
Running 1 test case...
test.cpp(11): error in "test": check { col1, col1+7 } == { col2, col2+7 } has failed.
Mismatch in a position 2: 3 != 4
Mismatch in a position 5: 6 != 7

*** 1 failures is detected in test suite "example"

See also:


PrevUpHomeNext