aboutsummaryrefslogtreecommitdiff
path: root/Client/ThirdParty/fpm/tests/common.hpp
diff options
context:
space:
mode:
Diffstat (limited to 'Client/ThirdParty/fpm/tests/common.hpp')
-rw-r--r--Client/ThirdParty/fpm/tests/common.hpp31
1 files changed, 31 insertions, 0 deletions
diff --git a/Client/ThirdParty/fpm/tests/common.hpp b/Client/ThirdParty/fpm/tests/common.hpp
new file mode 100644
index 0000000..d4dfe89
--- /dev/null
+++ b/Client/ThirdParty/fpm/tests/common.hpp
@@ -0,0 +1,31 @@
+#ifndef FPM_TESTS_COMMON_HPP
+#define FPM_TESTS_COMMON_HPP
+
+#include <fpm/fixed.hpp>
+#include <gtest/gtest.h>
+#include <iomanip>
+#include <ostream>
+
+namespace fpm
+{
+template <typename B, typename I, unsigned int F>
+void PrintTo(const fpm::fixed<B, I, F>& val, ::std::ostream* os)
+{
+ auto f = os->flags();
+ *os << static_cast<double>(val)
+ << " (0x" << std::hex << std::setw(sizeof(B) * 2) << std::setfill('0') << val.raw_value() << ")";
+ os->flags(f);
+}
+}
+
+inline ::testing::AssertionResult HasMaximumError(double value, double reference, double max_error)
+{
+ auto diff = std::abs(value - reference);
+ if (reference < 1e-10 && diff <= max_error)
+ return ::testing::AssertionSuccess();
+ if (std::abs(diff / reference) <= max_error)
+ return ::testing::AssertionSuccess();
+ return ::testing::AssertionFailure() << value << " is not within " << (max_error * 100) << "% of " << reference;
+}
+
+#endif \ No newline at end of file