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