summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/test_fixed_point.cpp26
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));
+ });
+}