MCPcopy Create free account
hub / github.com/cortex-js/compute-engine / diffMessage

Function diffMessage

test/big-decimal/cross-validation.test.ts:61–87  ·  view source on GitHub ↗

* Format a comparison failure message showing where the digits diverge.

(
  label: string,
  ours: string,
  theirs: string,
  matchDigits: number
)

Source from the content-addressed store, hash-verified

59 * Format a comparison failure message showing where the digits diverge.
60 */
61function 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

Callers 1

Calls 2

significantDigitsFunction · 0.85
sliceMethod · 0.65

Tested by

no test coverage detected