import test from "node:test"; import assert from "node:assert/strict"; import { getPositionChange } from "../src/overlays.js"; test("places gained or lost since the start - only for heats and finals started together", () => { const order = ["a", "b", "c", "d", "e"]; const final = { type: "final", startMode: "position", status: "running" }; assert.equal(getPositionChange(final, order, "e", 2), 3, "started 5th, now 2nd: +3"); assert.equal(getPositionChange(final, order, "a", 3), -2, "started 1st, now 3rd: -2"); assert.equal(getPositionChange(final, order, "c", 3), 0); assert.equal(getPositionChange(final, order, "late_entry", 1), null, "not in the start order"); assert.equal(getPositionChange({ ...final, startMode: "mass", type: "heat" }, order, "e", 1), 4); assert.equal(getPositionChange({ ...final, status: "ready" }, order, "e", 2), null, "not before the start"); assert.equal(getPositionChange({ ...final, type: "open_practice" }, order, "e", 2), null, "practice ranks on best lap"); assert.equal(getPositionChange({ ...final, type: "qualification" }, order, "e", 2), null, "qualifying has individual clocks"); assert.equal(getPositionChange({ ...final, startMode: "flying" }, order, "e", 2), null, "no common start order"); assert.equal(getPositionChange(null, order, "e", 2), null); });