summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBent Bisballe Nyeng <deva@aasimon.org>2018-06-16 19:51:55 +0200
committerBent Bisballe Nyeng <deva@aasimon.org>2018-06-16 19:51:55 +0200
commitd0a09866f4326062dc82fda43b476412e57462f2 (patch)
tree416943134cc098d9acffd638506dbd4d7f2f17e3
parent9f90e689af4730d37c7d1fffb1821145aeb88d1f (diff)
Use empsilon comparison for doubles.
-rw-r--r--test/dgunit.h13
1 files changed, 13 insertions, 0 deletions
diff --git a/test/dgunit.h b/test/dgunit.h
index a010092..358c70d 100644
--- a/test/dgunit.h
+++ b/test/dgunit.h
@@ -34,6 +34,7 @@
#include <string>
#include <sstream>
#include <fstream>
+#include <cmath>
class DGUnit
{
@@ -173,6 +174,18 @@ protected:
#define DGUNIT_ASSERT(value) \
dg_assert(value, #value, __FILE__, __LINE__)
+ void assert_equal(double expected, double value,
+ const char* file, std::size_t line)
+ {
+ if(std::fabs(expected - value) > 0.0000001)
+ {
+ std::stringstream ss;
+ ss << "equality assertion failed\n"
+ "- Expected: " << expected << "\n"
+ "- Actual : " << value << "\n";
+ throw test_result{"", file, line, ss.str()};
+ }
+ }
template<typename T>
void assert_equal(T expected, T value,
const char* file, std::size_t line)