T-50: tests
This commit is contained in:
parent
315ec0367e
commit
d9d49ebc22
1 changed files with 10 additions and 23 deletions
|
|
@ -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<T>(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<string>(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);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue