Boost C++ Libraries Home Libraries People FAQ More

PrevUpHomeNext

BOOST_level_EQUAL_COLLECTIONS

BOOST_level_EQUAL_COLLECTIONS(lhs_begin, lhs_end, rhs_begin, rhs_end) compares two collections for equality. Two collections are considered equal if they have the same number of elements and the elements compare equal by operator==. The elements are obtained through the supplied iterators on the collections. The diagnostic message is constructed from applying operator<< to each of the elements in the collections.

[Important] Important

If you get a strange compile error when using BOOST_EQUAL_COLLECTIONS, check that the appropriate operator== and operator<< are defined for the element type in the collection. If you define these operators in your test code, keep in mind argument-dependent lookup of types based on enclosing namespaces and the namespaces opened by test suites. The need to define operator<< can be eliminated by using BOOST_TEST_DONT_PRINT_LOG_VALUE.

Example

static std::list<int> generate_list()
{
    std::list<int> l;
    l.push_front(3);
    l.push_front(2);
    l.push_front(1);

    return l;
}

BOOST_AUTO_TEST_CASE(example_equal_collections)
{
    std::vector<int> expected;
    expected.push_back(1);
    expected.push_back(2);
    expected.push_back(3);

    std::list<int> actual = generate_list();

    BOOST_REQUIRE_EQUAL_COLLECTIONS(
        expected.begin(), expected.end(),
        actual.begin(), actual.end());
}

BOOST_AUTO_TEST_CASE(example_equal_collections_pod)
{
    int const expected[] = { 1, 2, 3 };

    std::list<int> actual = generate_list();

    BOOST_REQUIRE_EQUAL_COLLECTIONS(
        &expected[0], &expected[sizeof(expected)/sizeof(expected[0])],
        actual.begin(), actual.end());
}


PrevUpHomeNext