Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to pass STL containers as arguments to BOOST_CHECK_EQUAL?

For example, say we have this class which we want to test:

struct TestMe {
  vector<int> getSomething();
}

And the test function is made of:

...
vector<int> Expected;
TestMe TM;
...
Result = TM.getSomething();
BOOST_CHECK_EQUAL(Result, Expected);
...

STL vector provides a free operator==, but it does not provide an operator <<, so this code does not compile. How can I get this to work? Can i define my own operator << ? What would its implementation look like? Extra credit to the most generic solution :)

like image 994
zr. Avatar asked Jan 29 '11 10:01

zr.


1 Answers

I think you should use BOOST_CHECK_EQUAL_COLLECTIONS, this tests each element and also prints where the mismatches are:

BOOST_CHECK_EQUAL_COLLECTIONS(Result.begin(), Result.end(), Expected.begin(), Expected.end());
like image 200
Philipp Avatar answered Nov 15 '22 05:11

Philipp