Calculation logic unit-tested with edge cases
Why it matters
Financial calculation functions — rounding, interest accrual, fee application — are high-stakes and frequently modified. Without unit tests that cover zero amounts, min/max boundary values, and rounding-boundary inputs like $10.005, a refactor that silently changes behavior at those boundaries will ship undetected. ISO 25010 maintainability requires that critical business logic be verifiable without running the full application. Missing edge-case coverage is the most common root cause of financial bugs found only in production, often after incorrect charges have been issued.
Severity rationale
Info because absent tests don't cause immediate failures but increase the probability of undetected regressions in financial calculation logic during future changes.
Remediation
Create src/lib/finance.test.ts (or equivalent) and include at minimum three edge-case categories: zero inputs, boundary amounts, and rounding midpoints.
// src/lib/finance.test.ts
import { calculateInterest, roundInterestCents } from './finance';
describe('calculateInterest', () => {
it('returns 0 for zero principal', () =>
expect(calculateInterest(0, 0.05)).toBe(0));
it('handles maximum allowed amount', () =>
expect(calculateInterest(99999, 0.05)).toBeGreaterThan(0));
it('applies banker rounding at 0.5 cent boundary', () =>
expect(roundInterestCents(100.5)).toBe(100)); // rounds to even
it('produces integer output', () =>
expect(Number.isInteger(roundInterestCents(10.335))).toBe(true));
});
Run tests in CI via npm test and gate merges on the test step passing.
DetectionPro
The detection method for this pattern is part of AuditBuffet Pro.
The full method (what to look for, pass and fail conditions, and how results get reported) ships inside the Financial Form Validation Audit. The pattern definition, severity rationale, and remediation remain openly licensed under CC-BY-4.0.
External references
- iso-25010:2011 · maintainability — Maintainability — Testability
Taxons
History
- 2026-04-18·v1.0.0·Initial import from finserv-form-validation·automated