Update of /cvsroot/cppunit/cppunit/examples/cppunittest
In directory sc8-pr-cvs4.sourceforge.net:/tmp/cvs-serv12080/examples/cppunittest
Modified Files:
Makefile.am TestAssertTest.cpp TestAssertTest.h
Added Files:
assertion_traitsTest.cpp assertion_traitsTest.h
Log Message:
Add tests of the precision generated by
assertion_traits<double>::toString().
Index: TestAssertTest.h
===================================================================
RCS file: /cvsroot/cppunit/cppunit/examples/cppunittest/TestAssertTest.h,v
retrieving revision 1.7
retrieving revision 1.8
diff -C2 -d -r1.7 -r1.8
*** TestAssertTest.h 27 Jan 2007 15:50:11 -0000 1.7
--- TestAssertTest.h 31 Jan 2007 05:27:07 -0000 1.8
***************
*** 17,20 ****
--- 17,21 ----
CPPUNIT_TEST( testAssertMessageFalse );
CPPUNIT_TEST( testAssertDoubleEquals );
+ CPPUNIT_TEST( testAssertDoubleEqualsPrecision );
CPPUNIT_TEST( testAssertDoubleNonFinite );
CPPUNIT_TEST( testFail );
***************
*** 44,47 ****
--- 45,49 ----
void testAssertDoubleEquals();
+ void testAssertDoubleEqualsPrecision();
void testAssertDoubleNonFinite();
--- NEW FILE: assertion_traitsTest.cpp ---
#include <cppunit/TestAssert.h>
#include "CoreSuite.h"
#include "assertion_traitsTest.h"
CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( assertion_traitsTest,
coreSuiteName() );
assertion_traitsTest::assertion_traitsTest()
{
}
void
assertion_traitsTest::test_toString()
{
CPPUNIT_ASSERT_EQUAL( std::string( "abc" ),
CPPUNIT_NS::assertion_traits<char*>::toString( "abc" ) );
CPPUNIT_ASSERT_EQUAL( std::string( "33" ),
CPPUNIT_NS::assertion_traits<int>::toString( 33 ) );
// Test that assertion_traits<double>::toString() produces
// more than the standard 6 digits of precision.
CPPUNIT_ASSERT_EQUAL( std::string( "33.1" ),
CPPUNIT_NS::assertion_traits<double>::toString( 33.1 ) );
CPPUNIT_ASSERT_EQUAL( std::string( "33.001" ),
CPPUNIT_NS::assertion_traits<double>::toString( 33.001 ) );
CPPUNIT_ASSERT_EQUAL( std::string( "33.00001" ),
CPPUNIT_NS::assertion_traits<double>::toString( 33.00001 ) );
CPPUNIT_ASSERT_EQUAL( std::string( "33.0000001" ),
CPPUNIT_NS::assertion_traits<double>::toString( 33.0000001 ) );
CPPUNIT_ASSERT_EQUAL( std::string( "33.0000000001" ),
CPPUNIT_NS::assertion_traits<double>::toString( 33.0000000001 ) );
}
Index: Makefile.am
===================================================================
RCS file: /cvsroot/cppunit/cppunit/examples/cppunittest/Makefile.am,v
retrieving revision 1.25
retrieving revision 1.26
diff -C2 -d -r1.25 -r1.26
*** Makefile.am 7 May 2003 20:07:16 -0000 1.25
--- Makefile.am 31 Jan 2007 05:27:07 -0000 1.26
***************
*** 7,10 ****
--- 7,12 ----
cppunittestmain_SOURCES = \
+ assertion_traitsTest.cpp \
+ assertion_traitsTest.h \
BaseTestCase.cpp \
BaseTestCase.h \
--- NEW FILE: assertion_traitsTest.h ---
#ifndef ASSERTIONTRAITSTEST_H
#define ASSERTIONTRAITSTEST_H
#include <cppunit/extensions/HelperMacros.h>
class assertion_traitsTest : public CPPUNIT_NS::TestFixture
{
CPPUNIT_TEST_SUITE( assertion_traitsTest );
CPPUNIT_TEST( test_toString );
CPPUNIT_TEST_SUITE_END();
public:
assertion_traitsTest();
void test_toString();
private:
assertion_traitsTest( const assertion_traitsTest © );
void operator =( const assertion_traitsTest © );
private:
};
#endif
Index: TestAssertTest.cpp
===================================================================
RCS file: /cvsroot/cppunit/cppunit/examples/cppunittest/TestAssertTest.cpp,v
retrieving revision 1.12
retrieving revision 1.13
diff -C2 -d -r1.12 -r1.13
*** TestAssertTest.cpp 27 Jan 2007 15:50:11 -0000 1.12
--- TestAssertTest.cpp 31 Jan 2007 05:27:07 -0000 1.13
***************
*** 136,140 ****
}
-
void
TestAssertTest::testAssertMessageTrue()
--- 136,139 ----
***************
*** 174,177 ****
--- 173,196 ----
}
+ /*
+ * Test that the error message from CPPUNIT_ASSERT_DOUBLES_EQUAL()
+ * has more than the default 6 digits of precision.
+ */
+ void
+ TestAssertTest::testAssertDoubleEqualsPrecision()
+ {
+ std::string failure( "2.000000001" );
+ try
+ {
+ CPPUNIT_ASSERT_DOUBLES_EQUAL( 1.0, 2.000000001, 1 );
+ }
+ catch( CPPUNIT_NS::Exception &e )
+ {
+ checkMessageContains( &e, failure );
+ return;
+ }
+ CPPUNIT_FAIL( "Expected assertion failure" );
+ }
+
void
TestAssertTest::testAssertDoubleNonFinite()
|