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/arithmetic_int.cpp | 45 ++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 Client/ThirdParty/fpm/tests/arithmetic_int.cpp (limited to 'Client/ThirdParty/fpm/tests/arithmetic_int.cpp') diff --git a/Client/ThirdParty/fpm/tests/arithmetic_int.cpp b/Client/ThirdParty/fpm/tests/arithmetic_int.cpp new file mode 100644 index 0000000..be9c176 --- /dev/null +++ b/Client/ThirdParty/fpm/tests/arithmetic_int.cpp @@ -0,0 +1,45 @@ +#include "common.hpp" + +TEST(arithmethic_int, addition) +{ + using P = fpm::fixed_24_8; + + EXPECT_EQ(P(10.5), P(3.5) + 7); +} + +TEST(arithmethic_int, subtraction) +{ + using P = fpm::fixed_24_8; + + EXPECT_EQ(P(-3.5), P(3.5) - 7); +} + +TEST(arithmethic_int, multiplication) +{ + using P = fpm::fixed_24_8; + + EXPECT_EQ(P(-24.5), P(3.5) * -7); +} + +TEST(arithmethic_int, division) +{ + using P = fpm::fixed_24_8; + + EXPECT_EQ(P(3.5 / 7), P(3.5) / 7); + EXPECT_EQ(P(-3.5 / 7), P(-3.5) / 7); + EXPECT_EQ(P(3.5 / -7), P(3.5) / -7); + EXPECT_EQ(P(-3.5 / -7), P(-3.5) / -7); + +#ifndef NDEBUG + EXPECT_DEATH(P(1) / 0, ""); +#endif +} + +TEST(arithmethic_int, division_range) +{ + using P = fpm::fixed; + + // These calculation will overflow and produce + // wrong results without the intermediate type. + EXPECT_EQ(P(32), P(256) / 8); +} \ No newline at end of file -- cgit v1.1-26-g67d0