Re: [Cppunit-devel] equality of const objects
Brought to you by:
blep
|
From: Baptiste L. <gai...@fr...> - 2001-10-02 12:19:51
|
Quoting Duane Murphy <du...@us...>:
> The problem with the above change to assertEquals is that it is
> embedded
> in a template class that also defines the toString operations on one
> type. This has to be solved also.
Indeed I'm more bothered with that problem than with the const issue (doesn't
raise as often).
With VC++, you need to write:
std::string str( "123" );
std::vector v;
CPPUNIT_ASSERT_EQUAL( 3, int(str.length()) );
CPPUNIT_ASSERT_EQUAL( std::string("123"), str );
CPPUNIT_ASSERT_EQUAL( 0, int(v.size()) );
Which I find make the test much harder to read than:
CPPUNIT_ASSERT_EQUAL( 3, str.length() );
CPPUNIT_ASSERT_EQUAL( "123", str );
CPPUNIT_ASSERT_EQUAL( 0, v.size() );
>
> A couple of suggestions:
> (1) seperate the class into two template classes
> (2) Dont use a template class just template functions
> (3) Use class template methods (I have the terminology wrong for
> sure).
> There may be a limitation with some compilers using this method.
(3) is to be avoided if we have alternative. VC++ template method support is
shacky (TestAssert used to be a class and the assertEquals template method
caused Compiler-error).
(2) I'm not sure. I think template class are more supported than template
function by many compiler. Could any one confirm this ?
(1) Separating the equality test from the string conversion is something I'm
thinking about. Outputing a message containing an object has must more
application than just equality assertion. Thanks to the extra info, we can just
deduce what is wrong and we don't have to run the debugger. An object dump
often provide a better view of the object than the one you get with the
debugger.
For example, we might want:
CPPUNIT_DETAIL_ASSERT( date.isValid(), date );
which would behave like a standard assertion, but also dump the specified
object.
Another example, I've a tools utility function that check if 2 unordered
collections contains the same elements (they may not be at the same position in
the collection):
checkCollectionContainsIdenticalItems( expectedCollection, actualCollection,
my_equal_predicate() );
When it asserts, it does it with a message listing the expected item that
were not in the actual collection, and those that should not be in the
actualCollection. That function would use the string dump service but not
the 'equality' service (depending of the context, the presence of an item can
change: they must have the same 'key', or all their attributes need to be
equals...)
Well, the point is that the 'dump object to string' service has a much wider
range of use than just ASSERT_EQUAL.
Baptiste.
>
> Anyhow, just some suggestions.
>
> .Duane
>
>
> _______________________________________________
> Cppunit-devel mailing list
> Cpp...@li...
> https://lists.sourceforge.net/lists/listinfo/cppunit-devel
>
---
Baptiste Lepilleur <gai...@fr...>
http://gaiacrtn.free.fr/index.html
Language: English, French
|