From 0604aba2bfbd375a361fcc845b5655caa232a880 Mon Sep 17 00:00:00 2001 From: batsumaru <> Date: Sun, 9 Aug 2026 18:11:37 +0900 Subject: Added RapidCheck --- tests/test_fixed_point.cpp | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) (limited to 'tests/test_fixed_point.cpp') diff --git a/tests/test_fixed_point.cpp b/tests/test_fixed_point.cpp index 8c5c269..87a6ef2 100644 --- a/tests/test_fixed_point.cpp +++ b/tests/test_fixed_point.cpp @@ -1,4 +1,5 @@ #include +#include #include "fixed_point.h" TEST_CASE("fp_t addition is commutative") { @@ -96,3 +97,28 @@ TEST_CASE("fp_t division truncates precision below 1 ULP") { fp_t c = fp_t::from_raw(0); CHECK(a / b == c); } + +namespace rc { + template<> + struct Arbitrary { + static Gen arbitrary() { + return gen::map(gen::arbitrary(), + [](std::int32_t raw) { return fp_t::from_raw(raw); }); + } + }; +} + +TEST_CASE("fp_t addition is commutative for any bit pattern (fuzzed)") { + rc::prop("a + b == b + a", + [](const fp_t& a, const fp_t& b) { + RC_ASSERT(a + b == b + a); + }); +} + +TEST_CASE("fp_t division by itself is identity for any nonzero value (fuzzed)") { + rc::prop("a / a == from_int(1) when a.raw != 0", + [](const fp_t& a) { + RC_PRE(a.raw != 0); + RC_ASSERT(a / a == fp_t::from_int(1)); + }); +} -- cgit v1.3