Fix oxlint errors in NHL simulator and tests
- Replace non-null assertions (data!) with optional chaining (data?.x ?? "") - Move makeEntry helper to module scope to avoid recreating on every call Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
721b069b1c
commit
a67fe32c52
2 changed files with 18 additions and 17 deletions
|
|
@ -78,8 +78,8 @@ describe("getTeamData", () => {
|
||||||
];
|
];
|
||||||
for (const name of allTeams) {
|
for (const name of allTeams) {
|
||||||
const data = getTeamData(name);
|
const data = getTeamData(name);
|
||||||
expect(validConferences.has(data!.conference), `${name}: invalid conference`).toBe(true);
|
expect(validConferences.has(data?.conference ?? ""), `${name}: invalid conference`).toBe(true);
|
||||||
expect(validDivisions.has(data!.division), `${name}: invalid division`).toBe(true);
|
expect(validDivisions.has(data?.division ?? ""), `${name}: invalid division`).toBe(true);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
@ -122,12 +122,11 @@ describe("eloWinProbability (PARITY_FACTOR = 1000)", () => {
|
||||||
|
|
||||||
// ─── simulateProjectedPoints ──────────────────────────────────────────────────
|
// ─── simulateProjectedPoints ──────────────────────────────────────────────────
|
||||||
|
|
||||||
describe("simulateProjectedPoints", () => {
|
const makeEntry = (overrides: Partial<{
|
||||||
const makeEntry = (overrides: Partial<{
|
|
||||||
currentPoints: number;
|
currentPoints: number;
|
||||||
remainingGames: number;
|
remainingGames: number;
|
||||||
winProb: number;
|
winProb: number;
|
||||||
}> = {}) => ({
|
}> = {}) => ({
|
||||||
id: "test",
|
id: "test",
|
||||||
name: "Test Team",
|
name: "Test Team",
|
||||||
data: undefined,
|
data: undefined,
|
||||||
|
|
@ -136,7 +135,9 @@ describe("simulateProjectedPoints", () => {
|
||||||
currentPoints: overrides.currentPoints ?? 80,
|
currentPoints: overrides.currentPoints ?? 80,
|
||||||
remainingGames: overrides.remainingGames ?? 10,
|
remainingGames: overrides.remainingGames ?? 10,
|
||||||
winProb: overrides.winProb ?? 0.55,
|
winProb: overrides.winProb ?? 0.55,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe("simulateProjectedPoints", () => {
|
||||||
|
|
||||||
it("returns exactly currentPoints when no games remain", () => {
|
it("returns exactly currentPoints when no games remain", () => {
|
||||||
const entry = makeEntry({ currentPoints: 95, remainingGames: 0 });
|
const entry = makeEntry({ currentPoints: 95, remainingGames: 0 });
|
||||||
|
|
|
||||||
|
|
@ -245,7 +245,7 @@ function projectTeam(t: TeamEntry): ProjectedTeam {
|
||||||
|
|
||||||
/** Sort projected teams descending by pts, then by random tiebreaker. Mutates arr. */
|
/** Sort projected teams descending by pts, then by random tiebreaker. Mutates arr. */
|
||||||
function sortProjected(arr: ProjectedTeam[]): ProjectedTeam[] {
|
function sortProjected(arr: ProjectedTeam[]): ProjectedTeam[] {
|
||||||
return arr.sort((a, b) => b.pts - a.pts || b.tb - a.tb);
|
return arr.toSorted((a, b) => b.pts - a.pts || b.tb - a.tb);
|
||||||
}
|
}
|
||||||
|
|
||||||
// ─── Simulator ────────────────────────────────────────────────────────────────
|
// ─── Simulator ────────────────────────────────────────────────────────────────
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue