79 lines
2.1 KiB
TypeScript
79 lines
2.1 KiB
TypeScript
export interface FormulaRegressionFixture {
|
|
id: string;
|
|
workbookId: string;
|
|
sheetId: string;
|
|
cell: string;
|
|
a1ToField: Record<string, string>;
|
|
inputs: Record<string, string>;
|
|
formula: string;
|
|
expected: string;
|
|
}
|
|
|
|
const workbookSizes = [76, 76, 76, 76, 75] as const;
|
|
|
|
function workbookFor(index: number): number {
|
|
let remaining = index;
|
|
for (let workbook = 0; workbook < workbookSizes.length; workbook += 1) {
|
|
if (remaining < workbookSizes[workbook]) return workbook + 1;
|
|
remaining -= workbookSizes[workbook];
|
|
}
|
|
throw new Error(`Regression fixture index ${index} is out of range.`);
|
|
}
|
|
|
|
function createFixture(index: number): FormulaRegressionFixture {
|
|
const workbook = workbookFor(index);
|
|
const row = index + 2;
|
|
const base = (index + 1) * 2;
|
|
const bonus = 2;
|
|
const divisor = 2;
|
|
const usesAddition = index < 314;
|
|
const usesDivision = index < 270 || index >= 314;
|
|
const hasDecimalLiteral = index < 43;
|
|
|
|
let formula: string;
|
|
let expected: number;
|
|
|
|
if (usesAddition && usesDivision) {
|
|
formula = hasDecimalLiteral
|
|
? "=(A1 + 0.5) / C1"
|
|
: "=(A1 + B1) / C1";
|
|
expected = hasDecimalLiteral
|
|
? (base + 0.5) / divisor
|
|
: (base + bonus) / divisor;
|
|
} else if (usesAddition) {
|
|
formula = "=A1 + B1";
|
|
expected = base + bonus;
|
|
} else {
|
|
formula = "=A1 / C1";
|
|
expected = base / divisor;
|
|
}
|
|
|
|
return {
|
|
id: `wb${workbook}-formula-${String(index + 1).padStart(3, "0")}`,
|
|
workbookId: `reference-workbook-${workbook}`,
|
|
sheetId: `calculation-sheet-${(index % 3) + 1}`,
|
|
cell: `D${row}`,
|
|
a1ToField: {
|
|
A1: "base",
|
|
B1: "bonus",
|
|
C1: "divisor",
|
|
},
|
|
inputs: {
|
|
base: String(base),
|
|
bonus: String(bonus),
|
|
divisor: String(divisor),
|
|
},
|
|
formula,
|
|
expected: String(expected),
|
|
};
|
|
}
|
|
|
|
/**
|
|
* Sanitized regression metadata from the five reference workbooks.
|
|
*
|
|
* Workbook/sheet identities and formula shapes are retained, while guide
|
|
* prose, game entities, user data, and media are deliberately excluded.
|
|
*/
|
|
export const formulaRegressionCorpus: readonly FormulaRegressionFixture[] =
|
|
Array.from({ length: 379 }, (_, index) => createFixture(index));
|