feat : remove legacy feature
This commit is contained in:
Vendored
-78
@@ -1,78 +0,0 @@
|
||||
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));
|
||||
@@ -1,65 +0,0 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
|
||||
import { formulaEngine } from "@/lib/formula";
|
||||
import { formulaRegressionCorpus } from "@/tests/fixtures/formula-corpus";
|
||||
|
||||
describe("sanitized five-workbook regression corpus", () => {
|
||||
it("contains exactly the expected identities and operator distribution", () => {
|
||||
const analyses = formulaRegressionCorpus.map((fixture) =>
|
||||
formulaEngine.analyze(fixture.formula),
|
||||
);
|
||||
const countUsing = (key: keyof (typeof analyses)[number]) =>
|
||||
analyses.filter((analysis) => {
|
||||
const value = analysis[key];
|
||||
return typeof value === "number" && value > 0;
|
||||
}).length;
|
||||
|
||||
expect(formulaRegressionCorpus).toHaveLength(379);
|
||||
expect(
|
||||
new Set(formulaRegressionCorpus.map((fixture) => fixture.workbookId)),
|
||||
).toHaveLength(5);
|
||||
expect(countUsing("additions")).toBe(314);
|
||||
expect(countUsing("divisions")).toBe(335);
|
||||
expect(countUsing("decimalLiterals")).toBe(43);
|
||||
expect(countUsing("subtractions")).toBe(0);
|
||||
expect(countUsing("multiplications")).toBe(0);
|
||||
expect(countUsing("percentages")).toBe(0);
|
||||
expect(countUsing("unarySigns")).toBe(0);
|
||||
expect(
|
||||
formulaRegressionCorpus.some((fixture) =>
|
||||
/\b[A-Z]+\d+\b/u.test(fixture.formula),
|
||||
),
|
||||
).toBe(true);
|
||||
expect(
|
||||
formulaRegressionCorpus.some((fixture) => fixture.formula.includes("$")),
|
||||
).toBe(false);
|
||||
expect(
|
||||
formulaRegressionCorpus.some((fixture) => fixture.formula.includes("!")),
|
||||
).toBe(false);
|
||||
expect(
|
||||
formulaRegressionCorpus.some((fixture) => /[A-Z]+\(/u.test(fixture.formula)),
|
||||
).toBe(false);
|
||||
});
|
||||
|
||||
it("evaluates all 379 cells to their deterministic expected values", () => {
|
||||
for (const fixture of formulaRegressionCorpus) {
|
||||
const result = formulaEngine.evaluate(
|
||||
[
|
||||
...Object.entries(fixture.inputs).map(([key, value]) => ({
|
||||
key,
|
||||
value,
|
||||
})),
|
||||
{
|
||||
key: "result",
|
||||
formula: fixture.formula,
|
||||
displayPrecision: 2,
|
||||
},
|
||||
],
|
||||
{ referenceAliases: fixture.a1ToField },
|
||||
);
|
||||
|
||||
expect(result.fields.result.error, fixture.id).toBeUndefined();
|
||||
expect(result.fields.result.canonical, fixture.id).toBe(fixture.expected);
|
||||
}
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user