Unit Tests

- Added new "is" method for double-precision floating point comparison,
  with tolerance value.
This commit is contained in:
Paul Beckingham 2011-01-04 16:29:31 -05:00
parent 9429c96172
commit 2bee2f4aa5
2 changed files with 32 additions and 2 deletions

View file

@ -27,6 +27,7 @@
#include <iostream>
#include <iomanip>
#include <string.h>
#include <math.h>
#include <main.h>
#include <util.h>
#include <text.h>
@ -270,7 +271,35 @@ void UnitTest::is (double actual, double expected, const std::string& name)
}
///////////////////////////////////////////////////////////////////////////////
void UnitTest::is (char actual, char expected, const std::string& name)
void UnitTest::is (double actual, double expected, double tolerance, const std::string& name)
{
++mCounter;
if (fabs (actual - expected) <= tolerance)
{
++mPassed;
std::cout << "ok "
<< mCounter
<< " - "
<< name
<< "\n";
}
else
{
++mFailed;
std::cout << "not ok "
<< mCounter
<< " - "
<< name
<< "\n# expected: "
<< expected
<< "\n# got: "
<< actual
<< "\n";
}
}
///////////////////////////////////////////////////////////////////////////////
void UnitTest::is (unsigned char actual, unsigned char expected, const std::string& name)
{
++mCounter;
if (actual == expected)

View file

@ -44,7 +44,8 @@ public:
void is (size_t, size_t, const std::string&);
void is (int, int, const std::string&);
void is (double, double, const std::string&);
void is (char, char, const std::string&);
void is (double, double, double, const std::string&);
void is (unsigned char, unsigned char, const std::string&);
void is (const std::string&, const std::string&, const std::string&);
void is (const char*, const char*, const std::string&);
void diag (const std::string&);