summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/test_fixed_point.cpp20
1 files changed, 20 insertions, 0 deletions
diff --git a/tests/test_fixed_point.cpp b/tests/test_fixed_point.cpp
index b116340..6d1a594 100644
--- a/tests/test_fixed_point.cpp
+++ b/tests/test_fixed_point.cpp
@@ -17,6 +17,13 @@ TEST_CASE("fp_t subtraction anti-commutative") {
REQUIRE(a.raw != 0);
}
+TEST_CASE("fp_t multiplication is commutative") {
+ fp_t a = fp_t::from_int(2);
+ fp_t b = fp_t::from_int(5);
+ CHECK(a * b == b * a);
+ REQUIRE(a.raw != 1);
+}
+
TEST_CASE("fp_t addition overflows") {
fp_t a = fp_t::from_raw(INT32_MAX);
fp_t b = fp_t::from_raw(1);
@@ -30,3 +37,16 @@ TEST_CASE("fp_t subtraction underflows") {
fp_t c = fp_t::from_raw(INT32_MAX);
CHECK(a - b == c);
}
+
+TEST_CASE("fp_t multiplication overflows") {
+ fp_t a = fp_t::from_raw(INT32_MAX);
+ fp_t b = fp_t::from_int(2);
+ fp_t c = fp_t::from_raw(-2);
+ CHECK(a * b == c);
+}
+
+TEST_CASE("fp_t multiplication drops percision under 1 ULP") {
+ fp_t a = fp_t::from_raw(1);
+ fp_t b = fp_t::from_raw(0);
+ CHECK(a * a == b);
+}