import { describe, expect, it } from "vitest"; import vectors from "../../../crates/cotton-rules/vectors/computed.json"; import { formulaValue, readingFigure, rollupValue } from "../src/engine.ts"; // RULE: a computed column adds up the same on the Worker as on the phone — // the shared vectors cotton-rules' computed tests read. describe("computed columns' arithmetic, by the shared vectors", () => { type Formula = { op: string; values: unknown[]; flip?: boolean; separator?: string; want: unknown }; type Rollup = { op: string; values: unknown[]; count?: number; want: unknown }; for (const c of vectors.formula as Formula[]) { it(`formula ${c.op} ${JSON.stringify(c.values)}${c.flip ? " flipped" : ""}`, () => { expect(formulaValue(c.op, c.values, c.flip === true, c.separator)).toEqual(c.want); }); } for (const c of vectors.rollup as Rollup[]) { it(`rollup ${c.op} ${JSON.stringify(c.values)}`, () => { expect(rollupValue(c.op, c.count ?? c.values.length, c.values)).toEqual(c.want); }); } type Figure = { value: number; decimals?: number; want: string }; for (const c of vectors.figure as Figure[]) { it(`figure ${c.value}${c.decimals !== undefined ? ` to ${c.decimals}` : ""}`, () => { expect(readingFigure(c.value, c.decimals)).toBe(c.want); }); } });