* Format a comparison failure message showing where the digits diverge.
( label: string, ours: string, theirs: string, matchDigits: number )
| 59 | * Format a comparison failure message showing where the digits diverge. |
| 60 | */ |
| 61 | function diffMessage( |
| 62 | label: string, |
| 63 | ours: string, |
| 64 | theirs: string, |
| 65 | matchDigits: number |
| 66 | ): string { |
| 67 | const ourDigits = significantDigits(ours); |
| 68 | const theirDigits = significantDigits(theirs); |
| 69 | |
| 70 | // Find first divergence point |
| 71 | let divergeAt = -1; |
| 72 | const len = Math.min(ourDigits.length, theirDigits.length, matchDigits); |
| 73 | for (let i = 0; i < len; i++) { |
| 74 | if (ourDigits[i] !== theirDigits[i]) { |
| 75 | divergeAt = i; |
| 76 | break; |
| 77 | } |
| 78 | } |
| 79 | |
| 80 | return [ |
| 81 | `${label}: digits diverge at position ${divergeAt} (of ${matchDigits} required)`, |
| 82 | ` BigDecimal: ${ours}`, |
| 83 | ` Decimal.js: ${theirs}`, |
| 84 | ` BD digits: ${ourDigits.slice(0, matchDigits)}`, |
| 85 | ` DJ digits: ${theirDigits.slice(0, matchDigits)}`, |
| 86 | ].join('\n'); |
| 87 | } |
| 88 | |
| 89 | // ---------- Test runner ---------- |
| 90 |
no test coverage detected