From d9d49ebc22cab712043d1fb6385efa6bdd6e0a81 Mon Sep 17 00:00:00 2001 From: Studio Date: Fri, 27 Nov 2026 16:19:50 -0500 Subject: [PATCH] T-50: tests --- ...security-master-instrument-stage-a.test.ts | 33 ++++++------------- 1 file changed, 10 insertions(+), 23 deletions(-) diff --git a/test/unit/security-master-instrument-stage-a.test.ts b/test/unit/security-master-instrument-stage-a.test.ts index 171bfc4b..e888dc15 100644 --- a/test/unit/security-master-instrument-stage-a.test.ts +++ b/test/unit/security-master-instrument-stage-a.test.ts @@ -23,7 +23,6 @@ const stageASourcePath = fileURLToPath( const ISIN_SCHEMA_PATTERN = /^[A-Z]{2}[A-Z0-9]{9}[0-9]$/; const ALLOWED_METHODS = new Set(['tier1_isin', 'tier2_cusip']); -const CUSIP_ALNUM = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ'; function assertConservationAndSchema(result: StageAMatchResult, inputLength: number): void { expect(result.stats.totalInputRecords).toBe(inputLength); @@ -83,17 +82,22 @@ function shuffleWithSeed(items: readonly T[], seed: number): T[] { return copy; } -function computeCusipWithCheckDigit(base8: string): string { +// Shared fixture: appends the CUSIP check digit; supports alphanumeric and private-placement (*@#) bases. +const CUSIP_CHARSET = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ*@#'; + +function withCusipCheckDigit(base8: string): string { let sum = 0; for (let i = 0; i < 8; i++) { - let val = CUSIP_ALNUM.indexOf(base8.charAt(i)); + let val = CUSIP_CHARSET.indexOf(base8.charAt(i)); + if (val < 0) { + throw new Error(`Unsupported CUSIP character in ${base8}`); + } if ((i & 1) === 1) { val *= 2; } sum += Math.floor(val / 10) + (val % 10); } - const checkDigit = (10 - (sum % 10)) % 10; - return base8 + String(checkDigit); + return base8 + String((10 - (sum % 10)) % 10); } describe('security master Pass 3 Stage A instrument matcher', () => { @@ -599,7 +603,7 @@ describe('security master Pass 3 Stage A instrument matcher', () => { const validIsins: string[] = new Array(UNIQUE_INSTRUMENTS); for (let i = 0; i < UNIQUE_INSTRUMENTS; i++) { const base8 = String(10000000 + i); - const cusip = computeCusipWithCheckDigit(base8); + const cusip = withCusipCheckDigit(base8); const country = (i & 1) === 0 ? 'US' : 'CA'; const isin = cusipToIsin(cusip, country); if (isin === null) { @@ -712,23 +716,6 @@ describe('security master Pass 3 Stage A instrument matcher', () => { }); }); -const CUSIP_CHARSET = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ*@#'; - -function withCusipCheckDigit(base8: string): string { - let sum = 0; - for (let i = 0; i < 8; i++) { - let val = CUSIP_CHARSET.indexOf(base8.charAt(i)); - if (val < 0) { - throw new Error(`Unsupported CUSIP character in ${base8}`); - } - if ((i & 1) === 1) { - val *= 2; - } - sum += Math.floor(val / 10) + (val % 10); - } - return base8 + String((10 - (sum % 10)) % 10); -} - function deepFreezeRecords(records: StageASourceRecord[]): readonly StageASourceRecord[] { for (const record of records) { Object.freeze(record);