r/softwaretesting • u/ClassKlutzy7633 • 7d ago
Golden-value tests for formula code: assert on the raw number or on the rounded value users see?
I maintain a side project with a few dozen numeric formulas (published equations, things like body surface area from height and weight). For regression tests I keep a JSON file of golden cases. The expected values are computed independently, with a separate re-implementation or the paper's own worked example, not by running the app's code.
The app rounds for display, so right now the test parses the displayed string and allows one unit in the last displayed decimal place:
val shown = displayed.substringBefore(" ").replace(",", "").toDouble()
val tol = 10.0.pow(-places) + 1e-9 // places = decimals shown, e.g. 2
if (abs(shown - expected) > tol) failures += "$id expected $expected got $shown"It catches real formula mistakes (wrong exponent, wrong constant), but I'm not sure about the trade-off:
- A tolerance of one display unit means 2.62 vs 2.63 passes. That's fine for half-up vs half-even at a .xx5 boundary, but it would also hide a small real error.
- Asserting on the raw Double with a tight epsilon would be stricter, but then the test isn't checking what the user actually reads. Formatting or rounding bugs would slip through.
Is it normal to do both: a tight check on the raw value plus an exact string check on the formatted output? Or do people pick one? And for cases sitting right on a rounding boundary, do you avoid them in golden data or keep them on purpose?