From 79eca25c945a535a7a0325999034bae17da92412 Mon Sep 17 00:00:00 2001 From: dan miller Date: Fri, 19 Oct 2007 05:15:33 +0000 Subject: resubmitting ode --- libraries/ode-0.9/tests/CppTestHarness/Checks.h | 97 +++++++++++++++++++++++++ 1 file changed, 97 insertions(+) create mode 100644 libraries/ode-0.9/tests/CppTestHarness/Checks.h (limited to 'libraries/ode-0.9/tests/CppTestHarness/Checks.h') diff --git a/libraries/ode-0.9/tests/CppTestHarness/Checks.h b/libraries/ode-0.9/tests/CppTestHarness/Checks.h new file mode 100644 index 0000000..7b4c2ca --- /dev/null +++ b/libraries/ode-0.9/tests/CppTestHarness/Checks.h @@ -0,0 +1,97 @@ +#ifndef CHECKS_H +#define CHECKS_H + +#include +#include + +namespace CppTestHarness +{ + template< typename Value > + bool Check(Value const value) + { +#ifdef _MSC_VER +# pragma warning(push) +# pragma warning(disable:4127) // conditional expression is constant +# pragma warning(disable:4800) // forcing value to bool true/false, performance warning +#endif + return value; +#ifdef _MSC_VER +# pragma warning(pop) +#endif + } + + template< typename Actual, typename Expected > + bool CheckEqual(Actual const actual, Expected const expected) + { +#ifdef _MSC_VER +# pragma warning(push) +# pragma warning(disable:4127) // conditional expression is constant +#endif + return (actual == expected); +#ifdef _MSC_VER +# pragma warning(pop) +#endif + } + + template< typename Actual, typename Expected > + bool CheckArrayEqual(Actual const actual, Expected const expected, int const count) + { + for (int i = 0; i < count; ++i) + { + if (!(actual[i] == expected[i])) + return false; + } + + return true; + } + + template< typename Actual, typename Expected, typename Tolerance > + bool CheckClose(Actual const actual, Expected const expected, Tolerance const tolerance) + { + return (std::abs(double(actual) - double(expected)) <= double(tolerance)); + } + + template< typename Actual, typename Expected, typename Tolerance > + bool CheckArrayClose(Actual const actual, Expected const expected, int const count, Tolerance const tolerance) + { + for (int i = 0; i < count; ++i) + { + if (!CheckClose(actual[i], expected[i], tolerance)) + return false; + } + + return true; + } + + template< typename Actual, typename Expected > + std::string BuildFailureString(Actual const actual, Expected const expected) + { + std::stringstream failureStr; + failureStr << "Expected " << actual << " but got " << expected << std::endl; + return failureStr.str(); + } + + template< typename Actual, typename Expected > + std::string BuildFailureString(Actual const* actual, Expected const* expected, int const count) + { + std::stringstream failureStr; + int i; + + failureStr << "Expected [ "; + + for (i = 0; i < count; ++i) + failureStr << expected[i] << ' '; + + failureStr << "] but got [ "; + + for (i = 0; i < count; ++i) + failureStr << expected[i] << ' '; + + failureStr << ']' << std::endl; + + return failureStr.str(); + } +} + +#endif + -- cgit v1.1