From 80c93179b57ce472275514af70427ce550391adb Mon Sep 17 00:00:00 2001 From: Stephen Waits Date: Mon, 9 Nov 2026 13:17:12 -0700 Subject: [PATCH] test(core): bound the rounded figures against the exact value A rounded step can later return to scale 2, so the bound is four whole units in cents, not one unit at the final scale. Co-Authored-By: Claude Sonnet 5.5 --- crates/ledger-core/tests/kernel_bridge/control.rs | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/crates/ledger-core/tests/kernel_bridge/control.rs b/crates/ledger-core/tests/kernel_bridge/control.rs index 742508ca..974e40ac 100644 --- a/crates/ledger-core/tests/kernel_bridge/control.rs +++ b/crates/ledger-core/tests/kernel_bridge/control.rs @@ -96,15 +96,16 @@ fn same_or_rounded( (None, None) => {} // Rounded at a coarser scale at some step (a later step may bring // it back to scale 2): not exact, and no panic; the finding. - // The figure is still within one unit, at its own scale, of the - // exact value (`exact`, in cents). + // The figure is still close to the exact value (`exact`, in + // cents): each coarser step loses at most one unit of its scale + // (at worst the whole units, 100 cents), over at most four steps. + // (A later step can bring the scale back to 2, so the bound is + // not tied to the final scale.) (Some(g), None) => { - prop_assert!(g.scale() < 2, "{g} is not a coarser scale"); - let unit = 10i128.pow(2 - g.scale()); - let shown = g.mantissa() * unit; + let shown = g.mantissa() * 10i128.pow(2u32.saturating_sub(g.scale())); prop_assert!( - (shown - exact).abs() <= unit, - "{g} is not within one unit of {exact} cents" + g.scale() <= 2 && (shown - exact).abs() <= 400, + "{g} is not within four whole units of {exact} cents" ); } (None, Some(w)) => prop_assert!(false, "refused an exact {w}"),