feat: add limited round-robin scheduling
This commit is contained in:
1 parent
24983aeb09
commit
658592973e
15 files changed
+403
-63
No files matched your search
@@ -19,10 +19,12 @@ function createService() {
|
||||
interface MatchOverrides {
|
||||
gameCount?: number;
|
||||
gameMode?: 'pair' | 'bracket' | 'round-robin';
|
||||
roundRobinMaxRounds?: number;
|
||||
participants?: Array<{ excluded?: boolean }>;
|
||||
teams?: Array<{ teamIndex: number }>;
|
||||
gameSchedule?: Array<{
|
||||
gameNumber: number;
|
||||
roundNumber?: number;
|
||||
teamAIndex: number;
|
||||
teamBIndex: number;
|
||||
}>;
|
||||
@@ -102,6 +104,23 @@ describe('TournamentCodeService round-robin scheduling', () => {
|
||||
).toBe(15);
|
||||
});
|
||||
|
||||
it('calculates limited round-robin slots from max rounds', () => {
|
||||
const service = createService();
|
||||
|
||||
expect(
|
||||
service.resolveRequiredSlots(
|
||||
createMatch({
|
||||
gameMode: 'round-robin',
|
||||
gameCount: 1,
|
||||
roundRobinMaxRounds: 3,
|
||||
teams: Array.from({ length: 8 }, (_, index) => ({
|
||||
teamIndex: index + 1,
|
||||
})),
|
||||
}),
|
||||
),
|
||||
).toBe(12);
|
||||
});
|
||||
|
||||
it('uses persisted round-robin game schedule for game refs', () => {
|
||||
const service = createService();
|
||||
const match = createMatch({
|
||||
@@ -124,7 +143,7 @@ describe('TournamentCodeService round-robin scheduling', () => {
|
||||
});
|
||||
});
|
||||
|
||||
it('falls back to lexicographic round-robin pairs before schedule is persisted', () => {
|
||||
it('falls back to round-based pairs before schedule is persisted', () => {
|
||||
const service = createService();
|
||||
const match = createMatch({
|
||||
gameMode: 'round-robin',
|
||||
@@ -137,10 +156,10 @@ describe('TournamentCodeService round-robin scheduling', () => {
|
||||
|
||||
expect(service.resolveSeriesRefForGameNumber(match, 1)).toEqual({
|
||||
teamAIndex: 1,
|
||||
teamBIndex: 2,
|
||||
teamBIndex: 4,
|
||||
});
|
||||
expect(service.resolveSeriesRefForGameNumber(match, 2)).toEqual({
|
||||
teamAIndex: 1,
|
||||
teamAIndex: 2,
|
||||
teamBIndex: 3,
|
||||
});
|
||||
});
|
||||
@@ -173,6 +192,31 @@ describe('TournamentCodeService round-robin scheduling', () => {
|
||||
expect(pair.gameSchedule).toEqual([]);
|
||||
});
|
||||
|
||||
it('creates a limited round-robin schedule grouped by playable rounds', () => {
|
||||
const service = createService();
|
||||
const roundRobin = createMatch({
|
||||
gameMode: 'round-robin',
|
||||
gameCount: 1,
|
||||
roundRobinMaxRounds: 3,
|
||||
teams: Array.from({ length: 8 }, (_, index) => ({
|
||||
teamIndex: index + 1,
|
||||
})),
|
||||
gameSchedule: [],
|
||||
});
|
||||
|
||||
service.ensureGameSchedule(roundRobin);
|
||||
|
||||
expect(roundRobin.gameSchedule).toHaveLength(12);
|
||||
for (const roundNumber of [1, 2, 3]) {
|
||||
const round = roundRobin.gameSchedule.filter(
|
||||
(game) => game.roundNumber === roundNumber,
|
||||
);
|
||||
expect(round).toHaveLength(4);
|
||||
expect(new Set(round.flatMap((game) => [game.teamAIndex, game.teamBIndex])).size)
|
||||
.toBe(8);
|
||||
}
|
||||
});
|
||||
|
||||
it('does not expose fallback round-robin slots before the schedule is persisted', async () => {
|
||||
const service = createService();
|
||||
const slots = await service.buildSlots(
|
||||
|
||||
Reference in new issue
Block a user