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 <noreply@anthropic.com>
This commit is contained in:
1 parent
c20ccbeab4
commit
80c93179b5
1 file changed
+8
-7
@@ -96,15 +96,16 @@ fn same_or_rounded(
|
|||||||
(None, None) => {}
|
(None, None) => {}
|
||||||
// Rounded at a coarser scale at some step (a later step may bring
|
// 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.
|
// 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
|
// The figure is still close to the exact value (`exact`, in
|
||||||
// exact value (`exact`, in cents).
|
// 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) => {
|
(Some(g), None) => {
|
||||||
prop_assert!(g.scale() < 2, "{g} is not a coarser scale");
|
let shown = g.mantissa() * 10i128.pow(2u32.saturating_sub(g.scale()));
|
||||||
let unit = 10i128.pow(2 - g.scale());
|
|
||||||
let shown = g.mantissa() * unit;
|
|
||||||
prop_assert!(
|
prop_assert!(
|
||||||
(shown - exact).abs() <= unit,
|
g.scale() <= 2 && (shown - exact).abs() <= 400,
|
||||||
"{g} is not within one unit of {exact} cents"
|
"{g} is not within four whole units of {exact} cents"
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
(None, Some(w)) => prop_assert!(false, "refused an exact {w}"),
|
(None, Some(w)) => prop_assert!(false, "refused an exact {w}"),
|
||||||
|
|||||||
Reference in new issue
Block a user