diff options
author | chai <chaifix@163.com> | 2021-12-01 13:34:22 +0800 |
---|---|---|
committer | chai <chaifix@163.com> | 2021-12-01 13:34:22 +0800 |
commit | 09abf1b529b4226f585ecfbb20866715b901755b (patch) | |
tree | 16929f2a6bee3ad4667bdd006cfcc1e683ab7210 /Client/ThirdParty/fpm/tests/arithmetic.cpp | |
parent | 84d961f754c905b37420f4d1b3fee8f4e523e58a (diff) |
+fpm
Diffstat (limited to 'Client/ThirdParty/fpm/tests/arithmetic.cpp')
-rw-r--r-- | Client/ThirdParty/fpm/tests/arithmetic.cpp | 53 |
1 files changed, 53 insertions, 0 deletions
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<std::int32_t, std::int64_t, 12>; + + // 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 |