From 768fc62b2cf771ff5a494211f19009c09e75c8b8 Mon Sep 17 00:00:00 2001 From: Kalle <38327916+Sendouc@users.noreply.github.com> Date: Sat, 26 Aug 2023 13:19:18 +0300 Subject: [PATCH] Throw an error in map list generation if duplicate maps --- .../generation.test.ts | 27 +++++++++++++++++++ .../tournament-map-list.ts | 11 ++++++++ 2 files changed, 38 insertions(+) diff --git a/app/modules/tournament-map-list-generator/generation.test.ts b/app/modules/tournament-map-list-generator/generation.test.ts index a65287dfd..235fe6f7d 100644 --- a/app/modules/tournament-map-list-generator/generation.test.ts +++ b/app/modules/tournament-map-list-generator/generation.test.ts @@ -763,5 +763,32 @@ TournamentMapListGeneratorOneMode( } ); +TournamentMapListGeneratorOneMode( + "Throws if duplicate maps in the pool", + () => { + assert.throws( + () => + generateMaps({ + teams: [ + { + id: 1, + maps: new MapPool([ + { mode: "SZ", stageId: 1 }, + { mode: "SZ", stageId: 1 }, + ]), + }, + { + id: 2, + maps: new MapPool([]), + }, + ], + modesIncluded: ["SZ"], + }), + (err: Error) => err.message.includes("Duplicate map"), + "Expected error to be thrown about duplicate maps" + ); + } +); + TournamentMapListGenerator.run(); TournamentMapListGeneratorOneMode.run(); diff --git a/app/modules/tournament-map-list-generator/tournament-map-list.ts b/app/modules/tournament-map-list-generator/tournament-map-list.ts index f530a63fe..d7db5bd78 100644 --- a/app/modules/tournament-map-list-generator/tournament-map-list.ts +++ b/app/modules/tournament-map-list-generator/tournament-map-list.ts @@ -163,6 +163,17 @@ export function createTournamentMapList( ), "Maps submitted for modes not included in the tournament" ); + + for (const team of input.teams) { + const stringified = team.maps.stageModePairs.map( + (p) => `${p.stageId}-${p.mode}` + ); + const unique = new Set(stringified); + invariant( + unique.size === stringified.length, + `Duplicate maps in map pool (team ${team.id})` + ); + } } function utilizeOtherStageIdsWhenNoTiebreaker() {