69 lines
3.1 KiB
TypeScript
69 lines
3.1 KiB
TypeScript
|
|
import { describe, expect, it } from "vitest";
|
||
|
|
import { resolveRatings, resolveSourceElos } from "../input-policy";
|
||
|
|
import type { SimulatorManifestProfile } from "../manifest";
|
||
|
|
|
||
|
|
const profile = {
|
||
|
|
derivableInputs: { sourceElo: ["projectedWins", "sourceOdds"] },
|
||
|
|
} as Pick<SimulatorManifestProfile, "derivableInputs">;
|
||
|
|
|
||
|
|
describe("simulator input policy", () => {
|
||
|
|
it("keeps direct Elo ahead of derived values", () => {
|
||
|
|
const resolved = resolveSourceElos(
|
||
|
|
[{ participantId: "team-1", sourceElo: 1600, rating: null, sourceOdds: 2000, projectedWins: 20, projectedTablePoints: null }],
|
||
|
|
profile,
|
||
|
|
{ seasonGames: 82 }
|
||
|
|
);
|
||
|
|
|
||
|
|
expect(resolved.get("team-1")).toMatchObject({ sourceElo: 1600, method: "direct" });
|
||
|
|
});
|
||
|
|
|
||
|
|
it("derives Elo from projected wins when Elo is missing", () => {
|
||
|
|
const resolved = resolveSourceElos(
|
||
|
|
[{ participantId: "team-1", sourceElo: null, rating: null, sourceOdds: null, projectedWins: 60, projectedTablePoints: null }],
|
||
|
|
profile,
|
||
|
|
{ seasonGames: 82, parityFactor: 400 }
|
||
|
|
);
|
||
|
|
|
||
|
|
expect(resolved.get("team-1")?.method).toBe("projectedWins");
|
||
|
|
expect(resolved.get("team-1")?.sourceElo).toBeGreaterThan(1500);
|
||
|
|
});
|
||
|
|
|
||
|
|
it("blocks missing Elo unless a fallback strategy is configured", () => {
|
||
|
|
const inputs = [{ participantId: "team-1", sourceElo: null, rating: null, sourceOdds: null, projectedWins: null, projectedTablePoints: null }];
|
||
|
|
|
||
|
|
expect(resolveSourceElos(inputs, profile, {}).has("team-1")).toBe(false);
|
||
|
|
expect(resolveSourceElos(inputs, profile, {
|
||
|
|
inputPolicy: { missingEloStrategy: "fallbackElo", fallbackElo: 1375 },
|
||
|
|
}).get("team-1")).toMatchObject({ sourceElo: 1375, method: "fallbackElo" });
|
||
|
|
});
|
||
|
|
|
||
|
|
it("supports worst-known-minus tail fallback", () => {
|
||
|
|
const resolved = resolveSourceElos(
|
||
|
|
[
|
||
|
|
{ participantId: "known-1", sourceElo: 1500, rating: null, sourceOdds: null, projectedWins: null, projectedTablePoints: null },
|
||
|
|
{ participantId: "known-2", sourceElo: 1430, rating: null, sourceOdds: null, projectedWins: null, projectedTablePoints: null },
|
||
|
|
{ participantId: "tail", sourceElo: null, rating: null, sourceOdds: null, projectedWins: null, projectedTablePoints: null },
|
||
|
|
],
|
||
|
|
profile,
|
||
|
|
{ inputPolicy: { missingEloStrategy: "worstKnownMinus", fallbackEloDelta: 30 } }
|
||
|
|
);
|
||
|
|
|
||
|
|
expect(resolved.get("tail")).toMatchObject({ sourceElo: 1400, method: "worstKnownMinus" });
|
||
|
|
});
|
||
|
|
|
||
|
|
it("derives ratings from futures odds when the profile allows it", () => {
|
||
|
|
const resolved = resolveRatings(
|
||
|
|
[
|
||
|
|
{ participantId: "favorite", sourceElo: null, rating: null, sourceOdds: 300, projectedWins: null, projectedTablePoints: null },
|
||
|
|
{ participantId: "longshot", sourceElo: null, rating: null, sourceOdds: 20000, projectedWins: null, projectedTablePoints: null },
|
||
|
|
],
|
||
|
|
{ derivableInputs: { rating: ["sourceOdds"] } },
|
||
|
|
{ inputPolicy: { ratingMin: -10, ratingMax: 35 } }
|
||
|
|
);
|
||
|
|
|
||
|
|
expect(resolved.get("favorite")?.method).toBe("sourceOdds");
|
||
|
|
expect(resolved.get("longshot")?.method).toBe("sourceOdds");
|
||
|
|
expect(resolved.get("favorite")?.rating).toBeGreaterThan(resolved.get("longshot")?.rating ?? 999);
|
||
|
|
});
|
||
|
|
});
|