aboutsummaryrefslogtreecommitdiff
path: root/Client/ThirdParty/fpm/tests/arithmetic_int.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'Client/ThirdParty/fpm/tests/arithmetic_int.cpp')
-rw-r--r--Client/ThirdParty/fpm/tests/arithmetic_int.cpp45
1 files changed, 45 insertions, 0 deletions
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<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) / 8);
+} \ No newline at end of file