summaryrefslogtreecommitdiff
path: root/tests/test_fixed_point.cpp
diff options
context:
space:
mode:
authorbatsumaru <>2026-08-09 12:00:27 +0900
committerbatsumaru <>2026-08-09 12:00:27 +0900
commit9d4f68606c919791d44e86e7a50812c29be32fa3 (patch)
tree7228c33d006f994f5b45f6634af40d4c08bf6c7c /tests/test_fixed_point.cpp
parent5a0e17e6a406805e830fc78b681656d0c7e88748 (diff)
Add fp_t subtraction
Diffstat (limited to 'tests/test_fixed_point.cpp')
-rw-r--r--tests/test_fixed_point.cpp16
1 files changed, 16 insertions, 0 deletions
diff --git a/tests/test_fixed_point.cpp b/tests/test_fixed_point.cpp
index b3d3e78..b116340 100644
--- a/tests/test_fixed_point.cpp
+++ b/tests/test_fixed_point.cpp
@@ -8,9 +8,25 @@ TEST_CASE("fp_t addition is commutative") {
REQUIRE(a.raw != 0);
}
+TEST_CASE("fp_t subtraction anti-commutative") {
+ fp_t a = fp_t::from_int(3);
+ fp_t b = fp_t::from_int(2);
+ fp_t c = fp_t::from_int(1);
+ fp_t d = fp_t::from_int(-1);
+ CHECK((a - b == c && b - a == d));
+ REQUIRE(a.raw != 0);
+}
+
TEST_CASE("fp_t addition overflows") {
fp_t a = fp_t::from_raw(INT32_MAX);
fp_t b = fp_t::from_raw(1);
fp_t c = fp_t::from_raw(INT32_MIN);
CHECK(a + b == c);
}
+
+TEST_CASE("fp_t subtraction underflows") {
+ fp_t a = fp_t::from_raw(INT32_MIN);
+ fp_t b = fp_t::from_raw(1);
+ fp_t c = fp_t::from_raw(INT32_MAX);
+ CHECK(a - b == c);
+}