mirror of
https://github.com/Sendouc/sendou.ink.git
synced 2026-09-12 06:06:28 -05:00
Fix "losses against" tiebreaker calculation with dropped teams Closes #1989
This commit is contained in:
40
app/features/tournament-bracket/core/Bracket.test.ts
Normal file
40
app/features/tournament-bracket/core/Bracket.test.ts
Normal file
@@ -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
|
||||
});
|
||||
});
|
||||
@@ -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
|
||||
|
||||
|
||||
15066
app/features/tournament-bracket/core/tests/mocks-li.ts
Normal file
15066
app/features/tournament-bracket/core/tests/mocks-li.ts
Normal file
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user