Test the DNS fix against the other qualifying points systems too

The user asked whether the DNS fix had actually been tested against
the different points systems, not just the default one. It hadn't -
buildQualifyingStandings had never been exercised end to end with
qualifyingPointsTable "field_desc"/"ifmar" (high-points-win scoring)
or qualifyingScoring "best" (ranked by time, not points) at all,
DNS or otherwise.

Added two tests: a DNS driver scored under the high-points field_desc
table (confirms the DNS row still ranks last under an inverted sort
direction, and isn't scored as either zero or the winner's points),
and one under "best time" qualifying (confirms a bad DNS heat can't
contaminate a driver's genuine best result, since bestRank/
bestRoundMetric take the driver's single best heat, not an average).
Both passed immediately, confirming the fix already handled these
correctly - this closes a real, previously-untested gap in confidence
rather than fixing a new bug.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
larssand
2026-09-10 17:48:23 +02:00
parent 3232dff25a
commit e9883188fe

View File

@@ -701,6 +701,83 @@ test("a driver who DNS'd in one heat but raced normally in the others is still f
assert.equal(driverTwo.countedPoints.length, 3, "all three heats count toward the score, including the DNS one - it isn't excluded or silently skipped");
});
function buildQualifyingStandingsForTest(event, sessions, rowsBySession, entrants) {
return buildQualifyingStandings(event, {
getSessionsForEvent: () => sessions,
buildLeaderboard: (session) => rowsBySession[session.id],
getSessionEntrants: () => entrants,
isHighPointsTable,
getQualifyingPointsValue,
compareNumberSet,
buildQualifyingTieBreakNote: (row, tieBreak) => buildQualifyingTieBreakNoteLogic(row, tieBreak, { t: testTranslate, formatLap: testFormatLap }),
formatLap: testFormatLap,
formatRaceClock: testFormatRaceClock,
t: testTranslate,
hasQualifyingPrimaryTie,
});
}
test("a DNS driver is scored correctly under a high-points table (field_desc), not just the default low-points one", () => {
const sessions = [
{ id: "h1", type: "qualification", name: "Q1 H1", status: "finished" },
{ id: "h2", type: "qualification", name: "Q2 H1", status: "finished" },
{ id: "h3", type: "qualification", name: "Q3 H1", status: "finished" },
];
const entrants = [{ id: "driver_a", name: "A" }, { id: "driver_b", name: "B" }];
const rowsBySession = {
// driver_a DNS'd heat 1 (driver_b is the only real finisher there), then won heats 2
// and 3 outright with driver_b second both times.
h1: [{ driverId: "driver_b", driverName: "B", comparisonMs: 16000, resultDisplay: "16.000" }],
h2: [
{ driverId: "driver_a", driverName: "A", comparisonMs: 15500, resultDisplay: "15.500" },
{ driverId: "driver_b", driverName: "B", comparisonMs: 16200, resultDisplay: "16.200" },
],
h3: [
{ driverId: "driver_a", driverName: "A", comparisonMs: 15400, resultDisplay: "15.400" },
{ driverId: "driver_b", driverName: "B", comparisonMs: 16100, resultDisplay: "16.100" },
],
};
const standings = buildQualifyingStandingsForTest(
{ id: "event_1", raceConfig: { qualifyingPointsTable: "field_desc", countedQualRounds: 3 } },
sessions,
rowsBySession,
entrants
);
// field_desc in a 2-driver field: 1st = 2 points, 2nd (or DNS, ranked after the field) = 1.
const driverA = standings.find((row) => row.driverId === "driver_a");
const driverB = standings.find((row) => row.driverId === "driver_b");
assert.equal(driverA.totalScore, 1 + 2 + 2, "1 point for the DNS heat (ranked last, not zero and not the winner's points), 2 for each heat won");
assert.equal(driverB.totalScore, 2 + 1 + 1, "2 points for winning the DNS heat by default, 1 for each 2nd place");
assert.equal(standings[0].driverId, "driver_a", "two outright wins plus a DNS still beats three consistent 2nd places under a high-points table");
});
test("a DNS driver is scored correctly under \"best time\" qualifying (not points-based) - a bad DNS heat never contaminates their best result", () => {
const sessions = [
{ id: "h1", type: "qualification", name: "Q1 H1", status: "finished" },
{ id: "h2", type: "qualification", name: "Q2 H1", status: "finished" },
];
const entrants = [{ id: "driver_a", name: "A" }, { id: "driver_b", name: "B" }];
const rowsBySession = {
h1: [{ driverId: "driver_b", driverName: "B", comparisonMs: 20000, resultDisplay: "20.000" }], // driver_a DNS
h2: [
{ driverId: "driver_a", driverName: "A", comparisonMs: 15000, resultDisplay: "15.000" }, // driver_a's genuine best time
{ driverId: "driver_b", driverName: "B", comparisonMs: 16000, resultDisplay: "16.000" },
],
};
const standings = buildQualifyingStandingsForTest(
{ id: "event_1", raceConfig: { qualifyingScoring: "best" } },
sessions,
rowsBySession,
entrants
);
const driverA = standings.find((row) => row.driverId === "driver_a");
assert.equal(driverA.bestRank, 1, "driver_a's single best placing (1st in heat 2) is what counts, unaffected by the DNS heat's last place");
assert.equal(driverA.bestRoundMetric, 15000, "their genuine 15.000s best time, not inflated by the DNS heat's Number.MAX_SAFE_INTEGER placeholder");
assert.equal(standings[0].driverId, "driver_a", "ranks ahead of driver_b, who never beat a 16.000s best");
});
test("session channel statistics summarize splits and pit stops per competitor", () => {
const result = {
competitors: {