diff options
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 |