diff --git a/app/services/simulations/__tests__/nhl-simulator.test.ts b/app/services/simulations/__tests__/nhl-simulator.test.ts index 51f8115..80e2029 100644 --- a/app/services/simulations/__tests__/nhl-simulator.test.ts +++ b/app/services/simulations/__tests__/nhl-simulator.test.ts @@ -78,8 +78,8 @@ describe("getTeamData", () => { ]; for (const name of allTeams) { const data = getTeamData(name); - expect(validConferences.has(data!.conference), `${name}: invalid conference`).toBe(true); - expect(validDivisions.has(data!.division), `${name}: invalid division`).toBe(true); + expect(validConferences.has(data?.conference ?? ""), `${name}: invalid conference`).toBe(true); + expect(validDivisions.has(data?.division ?? ""), `${name}: invalid division`).toBe(true); } }); @@ -122,21 +122,22 @@ describe("eloWinProbability (PARITY_FACTOR = 1000)", () => { // ─── simulateProjectedPoints ────────────────────────────────────────────────── +const makeEntry = (overrides: Partial<{ + currentPoints: number; + remainingGames: number; + winProb: number; +}> = {}) => ({ + id: "test", + name: "Test Team", + data: undefined, + conference: "Western" as const, + division: "Central", + currentPoints: overrides.currentPoints ?? 80, + remainingGames: overrides.remainingGames ?? 10, + winProb: overrides.winProb ?? 0.55, +}); + describe("simulateProjectedPoints", () => { - const makeEntry = (overrides: Partial<{ - currentPoints: number; - remainingGames: number; - winProb: number; - }> = {}) => ({ - id: "test", - name: "Test Team", - data: undefined, - conference: "Western" as const, - division: "Central", - currentPoints: overrides.currentPoints ?? 80, - remainingGames: overrides.remainingGames ?? 10, - winProb: overrides.winProb ?? 0.55, - }); it("returns exactly currentPoints when no games remain", () => { const entry = makeEntry({ currentPoints: 95, remainingGames: 0 }); diff --git a/app/services/simulations/nhl-simulator.ts b/app/services/simulations/nhl-simulator.ts index 2b84058..a79e7a9 100644 --- a/app/services/simulations/nhl-simulator.ts +++ b/app/services/simulations/nhl-simulator.ts @@ -245,7 +245,7 @@ function projectTeam(t: TeamEntry): ProjectedTeam { /** Sort projected teams descending by pts, then by random tiebreaker. Mutates arr. */ 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 ────────────────────────────────────────────────────────────────