* Run a precision comparison and return a summary string for snapshot testing. * * `ourFn` computes the BigDecimal result at the given precision. * `refFn` computes the reference result (decimal.js or exact) at the given precision.
( label: string, precisions: number[], ourFn: (prec: number) => string, refFn: (prec: number) => string )
| 70 | * `refFn` computes the reference result (decimal.js or exact) at the given precision. |
| 71 | */ |
| 72 | function precisionReport( |
| 73 | label: string, |
| 74 | precisions: number[], |
| 75 | ourFn: (prec: number) => string, |
| 76 | refFn: (prec: number) => string |
| 77 | ): string { |
| 78 | const lines: string[] = [label]; |
| 79 | for (const prec of precisions) { |
| 80 | const ours = ourFn(prec); |
| 81 | const ref = refFn(prec); |
| 82 | const digits = matchingDigits(ours, ref); |
| 83 | lines.push(` prec=${prec}: ${digits} matching digits (of ${prec})`); |
| 84 | } |
| 85 | return lines.join('\n'); |
| 86 | } |
| 87 | |
| 88 | // ---------- Tests ---------- |
| 89 |
no test coverage detected