diff options
| author | Bastiaan Bakker <bastiaan.bakker@lifeline.nl> | 2001-05-15 19:17:02 +0000 |
|---|---|---|
| committer | Bastiaan Bakker <bastiaan.bakker@lifeline.nl> | 2001-05-15 19:17:02 +0000 |
| commit | f8bcdad1ad2db2a4736927667f98a5bc83467d92 (patch) | |
| tree | 7006d5e7abd449a6c2abbab506fd44abd1e33d46 /src/cppunit/TestAssert.cpp | |
| parent | 5ffe3d0c85f84b451bc0abf05e431a9b3188705d (diff) | |
| download | cppunit-f8bcdad1ad2db2a4736927667f98a5bc83467d92.tar.gz | |
Forgotten in CppUnitW 1.2 merge.
Diffstat (limited to 'src/cppunit/TestAssert.cpp')
| -rw-r--r-- | src/cppunit/TestAssert.cpp | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/src/cppunit/TestAssert.cpp b/src/cppunit/TestAssert.cpp new file mode 100644 index 0000000..caa7596 --- /dev/null +++ b/src/cppunit/TestAssert.cpp @@ -0,0 +1,56 @@ +#include <cmath> + +#include "cppunit/TestAssert.h" +#include "estring.h" + +namespace CppUnit { + +/// Check for a failed general assertion +void TestAssert::assertImplementation (bool condition, + std::string conditionExpression, + long lineNumber, + std::string fileName) +{ + if (!condition) + throw Exception (conditionExpression, lineNumber, fileName); +} + + +/// Check for a failed equality assertion +void TestAssert::assertEquals (long expected, + long actual, + long lineNumber, + std::string fileName) +{ + if (expected != actual) + assertImplementation (false, notEqualsMessage(expected, actual), lineNumber, fileName); +} + + +/// Check for a failed equality assertion +void TestAssert::assertEquals (double expected, + double actual, + double delta, + long lineNumber, + std::string fileName) +{ + if (fabs (expected - actual) > delta) + assertImplementation (false, notEqualsMessage(expected, actual), lineNumber, fileName); + +} + + +/// Build a message about a failed equality check +std::string TestAssert::notEqualsMessage (long expected, long actual) +{ + return "expected: " + estring (expected) + " but was: " + estring (actual); +} + + +/// Build a message about a failed equality check +std::string TestAssert::notEqualsMessage (double expected, double actual) +{ + return "expected: " + estring (expected) + " but was: " + estring (actual); +} + +} // namespace TestAssert |
