Boost logo

Boost :

From: Rozental, Gennadiy (gennadiy.rozental_at_[hidden])
Date: 2003-09-15 13:23:26


> Hello,
> I'm just writing some test and have so far the following code:
>
> vector<string> r = split_expression("1 + 1*2");
> char* expected[] = {"1", "+", "1", "*", "2"};
>
> I'd like to compare the result with expectation, but I cannot write:
>
> BOOST_CHECK_EQUAL(r, vector<string>(expected, expected + 5));
>
> because Boost.Test wants operator<< for vector<string>. I cannot write

Use BOOST_TEST_DONT_PRINT_LOG_VALUE( vector<string> ) before your test case
with latest cvs sources to make above to work.
 
> BOOST_CHECK_EQUAL_COLLECTIONS(r.begin(), r.end(), expected);
>
> either, because if 'r' has more elements than expected, the
> test itself has
> some chance of crashing. Of course, I can first compare sizes with
> BOOST_REQUIRE, and then call BOOST_CHECK_EQUAL_COLLECTIONS,
> but this solution is not so convenient.

I may have sense to use 2 checks, cause it looks like two different types of
errors.
 
> In fact, I'm just about to use the above code to illustrance
> use of Boost.Test
> to some folks, and I'm not sure I have any good explanation
> why the check
> cannot be done in one step.
>
> Is it possible to have some macro which accept two iterator
> ranges, as opposed
> to one range and one iterator?

(I was trying to mimic STL algorithms here - they are using only one
sequence for bounds checking)

> TIA,
> Volodya

There are many different kinds of test tools that may be introduced. I am
trying to include only those that most widely usable. In your case you have
already at least 3 solution supplied by the library:

1. Use BOOST_CHECK_EQUAL and BOOST_TEST_DONT_PRINT_LOG_VALUE.
2. Use BOOST_CHECK_EQUAL for sizes BOOST_CHECK_EQUAL_COLLECTIONS in a
current form.
3. Write your own predicate with your own error messages and use
BOOST_CHECK_PREDICATE.

It should cover your case IMO. What do you think?

Gennadiy.


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk