summaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorSteve M. Robbins <smr@sumost.ca>2007-01-31 04:27:07 +0000
committerSteve M. Robbins <smr@sumost.ca>2007-01-31 04:27:07 +0000
commit3ca9c5d071cb8162c89fd514a6116ee6b450d763 (patch)
treede4b81cfb45d77392217dbaf8ef26414250ad65a /examples
parent92e722a21bb507165d4895c9a9aa92e53a1241ec (diff)
downloadcppunit-3ca9c5d071cb8162c89fd514a6116ee6b450d763.tar.gz
Add tests of the precision generated by
assertion_traits<double>::toString().
Diffstat (limited to 'examples')
-rw-r--r--examples/cppunittest/Makefile.am2
-rw-r--r--examples/cppunittest/TestAssertTest.cpp21
-rw-r--r--examples/cppunittest/TestAssertTest.h2
-rw-r--r--examples/cppunittest/assertion_traitsTest.cpp35
-rw-r--r--examples/cppunittest/assertion_traitsTest.h27
5 files changed, 86 insertions, 1 deletions
diff --git a/examples/cppunittest/Makefile.am b/examples/cppunittest/Makefile.am
index 0b22541..3060a6c 100644
--- a/examples/cppunittest/Makefile.am
+++ b/examples/cppunittest/Makefile.am
@@ -6,6 +6,8 @@ check_PROGRAMS = $(TESTS)
INCLUDES = -I$(top_builddir)/include -I$(top_srcdir)/include
cppunittestmain_SOURCES = \
+ assertion_traitsTest.cpp \
+ assertion_traitsTest.h \
BaseTestCase.cpp \
BaseTestCase.h \
CoreSuite.h \
diff --git a/examples/cppunittest/TestAssertTest.cpp b/examples/cppunittest/TestAssertTest.cpp
index 8719440..3b621ed 100644
--- a/examples/cppunittest/TestAssertTest.cpp
+++ b/examples/cppunittest/TestAssertTest.cpp
@@ -135,7 +135,6 @@ TestAssertTest::testAssertEqual()
CPPUNIT_ASSERT_ASSERTION_FAIL( CPPUNIT_ASSERT_EQUAL( 1, 2 ) );
}
-
void
TestAssertTest::testAssertMessageTrue()
{
@@ -173,6 +172,26 @@ TestAssertTest::testAssertDoubleEquals()
CPPUNIT_ASSERT_ASSERTION_FAIL( CPPUNIT_ASSERT_DOUBLES_EQUAL( 1.2, 1.1, 0.09 ) );
}
+/*
+ * 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()
{
diff --git a/examples/cppunittest/TestAssertTest.h b/examples/cppunittest/TestAssertTest.h
index a024573..a672d38 100644
--- a/examples/cppunittest/TestAssertTest.h
+++ b/examples/cppunittest/TestAssertTest.h
@@ -16,6 +16,7 @@ class TestAssertTest : public CPPUNIT_NS::TestFixture
CPPUNIT_TEST( testAssertMessageTrue );
CPPUNIT_TEST( testAssertMessageFalse );
CPPUNIT_TEST( testAssertDoubleEquals );
+ CPPUNIT_TEST( testAssertDoubleEqualsPrecision );
CPPUNIT_TEST( testAssertDoubleNonFinite );
CPPUNIT_TEST( testFail );
CPPUNIT_TEST_SUITE_END();
@@ -43,6 +44,7 @@ public:
void testAssertMessageFalse();
void testAssertDoubleEquals();
+ void testAssertDoubleEqualsPrecision();
void testAssertDoubleNonFinite();
void testAssertLongEquals();
diff --git a/examples/cppunittest/assertion_traitsTest.cpp b/examples/cppunittest/assertion_traitsTest.cpp
new file mode 100644
index 0000000..b02c732
--- /dev/null
+++ b/examples/cppunittest/assertion_traitsTest.cpp
@@ -0,0 +1,35 @@
+#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 ) );
+}
diff --git a/examples/cppunittest/assertion_traitsTest.h b/examples/cppunittest/assertion_traitsTest.h
new file mode 100644
index 0000000..207d943
--- /dev/null
+++ b/examples/cppunittest/assertion_traitsTest.h
@@ -0,0 +1,27 @@
+#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 &copy );
+ void operator =( const assertion_traitsTest &copy );
+
+private:
+};
+
+#endif
+