From 3f0f3a55284b20278e462077b604c5e82278c097 Mon Sep 17 00:00:00 2001 From: Gabriel Comte Date: Mon, 30 Mar 2026 10:18:40 +0200 Subject: [PATCH] Fix flaky round_value property test The test compared round_value output against a recomputation that could differ by 1 ULP for large values due to f64 precision limits. Replace with an idempotency check: round(round(x)) == round(x). --- src/currency/btc.rs | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/src/currency/btc.rs b/src/currency/btc.rs index 57a0fc2..e73f6f5 100644 --- a/src/currency/btc.rs +++ b/src/currency/btc.rs @@ -89,17 +89,15 @@ mod tests { } #[test] - fn round_value_has_correct_decimal_places( + fn round_value_is_idempotent( amount in 0.0_f64..1.0e8, unit in arb_btc_unit(), ) { - let rounded = unit.round_value(amount); - let factor = 10_f64.powi(unit.decimal_places().into()); - let check = (rounded * factor).round() / factor; - let diff = (rounded - check).abs(); + let once = unit.round_value(amount); + let twice = unit.round_value(once); prop_assert!( - diff < 1.0e-10, - "round_value produced too many decimal places: {rounded} (expected {check})" + (once - twice).abs() < f64::EPSILON, + "round_value is not idempotent: round({amount}) = {once}, round({once}) = {twice}" ); } }