Boost logo

Boost :

From: Vladimir Prus (ghost_at_[hidden])
Date: 2003-09-16 01:33:21


Rozental, Gennadiy wrote:

>> 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.

That's a nice addition! But seems like it's not documented yet? I cannot
find it in http://boost-consulting.com/boost/libs/test/doc/ nor in my
working copy.

>> 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.

I tend to disagree here.

>> 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)

Yes, I understand that motivation.

> 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.

This seems like a good approach.

> 2. Use BOOST_CHECK_EQUAL for sizes BOOST_CHECK_EQUAL_COLLECTIONS in a
> current form.

There's still a gotcha: if I use BOOST_CHECK_EQUAL for size then
BOOST_CHECK_EQUAL_COLLECTIONS will still be executed, even if sizes are
different, and can crash.

> 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?

I'll try to go with the first option for a while.

Thanks,
Volodya


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