Skip to content

Commit

Permalink
Fix "losses against" tiebreaker calculation with dropped teams Closes #…
Browse files Browse the repository at this point in the history
  • Loading branch information
Sendouc committed Dec 20, 2024
1 parent 938a4f4 commit 00035cb
Show file tree
Hide file tree
Showing 3 changed files with 15,113 additions and 1 deletion.
40 changes: 40 additions & 0 deletions app/features/tournament-bracket/core/Bracket.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import { describe, expect, it } from "vitest";
import { Tournament } from "./Tournament";
import { LOW_INK_DECEMBER_2024 } from "./tests/mocks-li";
import invariant from "../../../utils/invariant";

const TEAM_ERROR_404_ID = 17354;
const TEAM_THIS_IS_FINE_ID = 17513;

describe("swiss standings", () => {
it("should calculate losses against tied", () => {
const tournament = new Tournament({
...LOW_INK_DECEMBER_2024(),
simulateBrackets: false,
});

const standing = tournament
.bracketByIdx(0)
?.currentStandings(false)
.find((standing) => standing.team.id === TEAM_THIS_IS_FINE_ID);

invariant(standing, "Standing not found");

expect(standing.stats?.lossesAgainstTied).toBe(1);
});

it("should ignore early dropped out teams for standings (losses against tied)", () => {
const tournament = new Tournament({
...LOW_INK_DECEMBER_2024(),
simulateBrackets: false,
});

const standing = tournament
.bracketByIdx(0)
?.currentStandings(false)
.find((standing) => standing.team.id === TEAM_ERROR_404_ID);
invariant(standing, "Standing not found");

expect(standing.stats?.lossesAgainstTied).toBe(0); // they lost against "Tidy Tidings" but that team dropped out before final round
});
});
8 changes: 7 additions & 1 deletion app/features/tournament-bracket/core/Bracket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1388,7 +1388,13 @@ class SwissBracket extends Bracket {
for (const team of teams) {
for (const team2 of teams) {
if (team.id === team2.id) continue;
if (team.setWins !== team2.setWins) continue;
if (
team.setWins !== team2.setWins ||
// check also set losses to account for dropped teams
team.setLosses !== team2.setLosses
) {
continue;
}

// they are different teams and are tied, let's check who won

Expand Down
Loading

0 comments on commit 00035cb

Please sign in to comment.