mirror of
https://github.com/Sendouc/sendou.ink.git
synced 2026-07-26 05:06:03 -05:00
Fix best of calculation for low number of teams
This commit is contained in:
parent
1c62802ae0
commit
de19bcaddc
|
|
@ -8,6 +8,12 @@ export function resolveBestOfs(
|
|||
// 3 is default
|
||||
const result: [bestOf: 5 | 7, id: number][] = [];
|
||||
|
||||
// special case: only 2 teams
|
||||
if (matches.length === 1) {
|
||||
result.push([7, matches[0]!.matchId]);
|
||||
return result;
|
||||
}
|
||||
|
||||
/// Best of 7
|
||||
|
||||
// 1) Grand Finals
|
||||
|
|
@ -45,7 +51,8 @@ export function resolveBestOfs(
|
|||
);
|
||||
|
||||
const losersFinals = matches.filter(
|
||||
(match) => match.roundNumber === maxLosersRoundNumber
|
||||
(match) =>
|
||||
match.roundNumber === maxLosersRoundNumber && match.groupNumber === 2
|
||||
);
|
||||
invariant(losersFinals.length === 1, "losersFinals must be 1");
|
||||
|
||||
|
|
|
|||
61
app/features/tournament-bracket/core/bestOf.test.ts
Normal file
61
app/features/tournament-bracket/core/bestOf.test.ts
Normal file
|
|
@ -0,0 +1,61 @@
|
|||
import { suite } from "uvu";
|
||||
import * as assert from "uvu/assert";
|
||||
import { resolveBestOfs } from "./bestOf.server";
|
||||
|
||||
const ResolveBestOfs = suite("resolveBestOfs()");
|
||||
|
||||
const count = (bestOfs: [bestOf: 5 | 7, id: number][], target: 5 | 7) =>
|
||||
bestOfs.reduce((acc, cur) => acc + (cur[0] === target ? 1 : 0), 0);
|
||||
|
||||
ResolveBestOfs("2 teams", () => {
|
||||
const matches = [{ matchId: 1, roundNumber: 1, groupNumber: 1 }];
|
||||
|
||||
const bestOfs = resolveBestOfs(matches);
|
||||
|
||||
assert.equal(count(bestOfs, 5), 0);
|
||||
assert.equal(count(bestOfs, 7), 1);
|
||||
});
|
||||
|
||||
ResolveBestOfs("4 teams", () => {
|
||||
const matches = [
|
||||
{ matchId: 1, roundNumber: 1, groupNumber: 1 },
|
||||
{ matchId: 2, roundNumber: 1, groupNumber: 1 },
|
||||
{ matchId: 3, roundNumber: 2, groupNumber: 1 },
|
||||
{ matchId: 4, roundNumber: 1, groupNumber: 2 },
|
||||
{ matchId: 5, roundNumber: 2, groupNumber: 2 },
|
||||
{ matchId: 6, roundNumber: 1, groupNumber: 3 },
|
||||
{ matchId: 7, roundNumber: 2, groupNumber: 3 },
|
||||
];
|
||||
|
||||
const bestOfs = resolveBestOfs(matches);
|
||||
|
||||
assert.equal(count(bestOfs, 5), 1);
|
||||
assert.equal(count(bestOfs, 7), 2);
|
||||
});
|
||||
|
||||
ResolveBestOfs("8 teams", () => {
|
||||
const matches = [
|
||||
{ matchId: 1, roundNumber: 1, groupNumber: 1 },
|
||||
{ matchId: 2, roundNumber: 1, groupNumber: 1 },
|
||||
{ matchId: 3, roundNumber: 1, groupNumber: 1 },
|
||||
{ matchId: 4, roundNumber: 1, groupNumber: 1 },
|
||||
{ matchId: 5, roundNumber: 2, groupNumber: 1 },
|
||||
{ matchId: 6, roundNumber: 2, groupNumber: 1 },
|
||||
{ matchId: 7, roundNumber: 3, groupNumber: 1 },
|
||||
{ matchId: 8, roundNumber: 1, groupNumber: 2 },
|
||||
{ matchId: 9, roundNumber: 1, groupNumber: 2 },
|
||||
{ matchId: 10, roundNumber: 2, groupNumber: 2 },
|
||||
{ matchId: 11, roundNumber: 2, groupNumber: 2 },
|
||||
{ matchId: 12, roundNumber: 3, groupNumber: 2 },
|
||||
{ matchId: 13, roundNumber: 4, groupNumber: 2 },
|
||||
{ matchId: 14, roundNumber: 1, groupNumber: 3 },
|
||||
{ matchId: 15, roundNumber: 2, groupNumber: 3 },
|
||||
];
|
||||
|
||||
const bestOfs = resolveBestOfs(matches);
|
||||
|
||||
assert.equal(count(bestOfs, 5), 2);
|
||||
assert.equal(count(bestOfs, 7), 2);
|
||||
});
|
||||
|
||||
ResolveBestOfs.run();
|
||||
Loading…
Reference in New Issue
Block a user