test: cover full double elimination projection
This commit is contained in:
1 parent
5049220e03
commit
0c2c7b59fc
1 file changed
+67
-8
@@ -124,15 +124,15 @@ describe('projectCompetition', () => {
|
|||||||
loserTeamId: 'team-3',
|
loserTeamId: 'team-3',
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
expect(projectedSeries(projection, 'WB_FINAL')).toMatchObject({
|
expect(projectedSeries(projection, 'WB_FINAL').entries).toContainEqual({
|
||||||
entries: expect.arrayContaining([
|
slot: 'B',
|
||||||
{ slot: 'B', teamId: 'team-8', gameWins: 0 },
|
teamId: 'team-8',
|
||||||
]),
|
gameWins: 0,
|
||||||
});
|
});
|
||||||
expect(projectedSeries(projection, 'LB_R2_M1')).toMatchObject({
|
expect(projectedSeries(projection, 'LB_R2_M1').entries).toContainEqual({
|
||||||
entries: expect.arrayContaining([
|
slot: 'B',
|
||||||
{ slot: 'B', teamId: 'team-3', gameWins: 0 },
|
teamId: 'team-3',
|
||||||
]),
|
gameWins: 0,
|
||||||
});
|
});
|
||||||
expect(projection.games).toHaveLength(7);
|
expect(projection.games).toHaveLength(7);
|
||||||
expect(
|
expect(
|
||||||
@@ -306,6 +306,65 @@ describe('projectCompetition', () => {
|
|||||||
expect(projection.gameSlots[0]).toMatchObject({ status: 'ready' });
|
expect(projection.gameSlots[0]).toMatchObject({ status: 'ready' });
|
||||||
expect(projection.games).toEqual([]);
|
expect(projection.games).toEqual([]);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('completes an eight-team double elimination with shared elimination-round placements', () => {
|
||||||
|
const competitionId = 'competition-eight-team-completion';
|
||||||
|
const teams = Array.from({ length: 8 }, (_, index) =>
|
||||||
|
seededTeam(`team-${index + 1}`, index + 1),
|
||||||
|
);
|
||||||
|
const format = doubleEliminationFormat({ upperWinsRequired: 1 });
|
||||||
|
const seriesGraph = generateSeriesGraph({ competitionId, teams, format });
|
||||||
|
const accept = acceptedGameFactory(competitionId);
|
||||||
|
const facts: ReturnType<typeof accept>[] = [];
|
||||||
|
let projection = projectCompetition({
|
||||||
|
competitionId,
|
||||||
|
revision: 0,
|
||||||
|
projectorVersion: 1,
|
||||||
|
teams,
|
||||||
|
format,
|
||||||
|
seriesGraph,
|
||||||
|
facts,
|
||||||
|
});
|
||||||
|
|
||||||
|
for (let guard = 0; projection.phase !== 'completed'; guard += 1) {
|
||||||
|
if (guard > seriesGraph.length) {
|
||||||
|
throw new Error('Double-elimination projection did not converge.');
|
||||||
|
}
|
||||||
|
const playable = projection.series.find(
|
||||||
|
(series) => series.status === 'ready',
|
||||||
|
);
|
||||||
|
if (!playable) throw new Error('Missing playable Series.');
|
||||||
|
const definition = seriesGraph.find(
|
||||||
|
(series) => series.id === playable.seriesId,
|
||||||
|
);
|
||||||
|
const [entryA, entryB] = playable.entries;
|
||||||
|
if (!definition || !entryA.teamId || !entryB.teamId) {
|
||||||
|
throw new Error('Playable Series has unresolved participants.');
|
||||||
|
}
|
||||||
|
facts.push(
|
||||||
|
accept(definition, 1, entryA.teamId, entryB.teamId, entryA.teamId),
|
||||||
|
);
|
||||||
|
projection = projectCompetition({
|
||||||
|
competitionId,
|
||||||
|
revision: facts.length,
|
||||||
|
projectorVersion: 1,
|
||||||
|
teams,
|
||||||
|
format,
|
||||||
|
seriesGraph,
|
||||||
|
facts,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
expect(projection.outcome?.type).toBe('double-elimination');
|
||||||
|
if (projection.outcome?.type !== 'double-elimination') {
|
||||||
|
throw new Error('Expected a double-elimination outcome.');
|
||||||
|
}
|
||||||
|
expect(typeof projection.outcome.championTeamId).toBe('string');
|
||||||
|
expect(projection.outcome.placements).toHaveLength(8);
|
||||||
|
expect(projection.placements?.map(({ rank }) => rank)).toEqual([
|
||||||
|
1, 2, 3, 4, 5, 5, 7, 7,
|
||||||
|
]);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
function fixedGames(gameCount: number) {
|
function fixedGames(gameCount: number) {
|
||||||
|
|||||||
Reference in new issue
Block a user