From 09abf1b529b4226f585ecfbb20866715b901755b Mon Sep 17 00:00:00 2001 From: chai Date: Wed, 1 Dec 2021 13:34:22 +0800 Subject: +fpm --- Client/ThirdParty/fpm/tests/common.hpp | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 Client/ThirdParty/fpm/tests/common.hpp (limited to 'Client/ThirdParty/fpm/tests/common.hpp') 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 +#include +#include +#include + +namespace fpm +{ +template +void PrintTo(const fpm::fixed& val, ::std::ostream* os) +{ + auto f = os->flags(); + *os << static_cast(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 -- cgit v1.1-26-g67d0