diff options
| author | batsumaru <> | 2026-08-09 18:11:37 +0900 |
|---|---|---|
| committer | batsumaru <> | 2026-08-09 18:11:37 +0900 |
| commit | 0604aba2bfbd375a361fcc845b5655caa232a880 (patch) | |
| tree | 29223dba533f64ca9baeb2261e0634ab467b1001 /tests/test_fixed_point.cpp | |
| parent | cef49d4a396866fb5eef9ffa7a5a54b3bc0cb8af (diff) | |
Added RapidCheck
Diffstat (limited to 'tests/test_fixed_point.cpp')
| -rw-r--r-- | tests/test_fixed_point.cpp | 26 |
1 files changed, 26 insertions, 0 deletions
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 <catch2/catch_test_macros.hpp> +#include <rapidcheck/catch.h> #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<fp_t> { + static Gen<fp_t> arbitrary() { + return gen::map(gen::arbitrary<std::int32_t>(), + [](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)); + }); +} |
