Skip to content

Commit 8e33c51

Browse files
committed
:docs: Improve AOJ course contest labels (#1526)
1 parent d1c151d commit 8e33c51

File tree

2 files changed

+17
-7
lines changed

2 files changed

+17
-7
lines changed

src/lib/utils/contest.ts

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -324,15 +324,15 @@ export const getContestNameLabel = (contestId: string) => {
324324

325325
// AIZU ONLINE JUDGE
326326
if (aojCoursePrefixes.has(contestId)) {
327-
return 'AOJ Courses';
327+
return getAojContestLabel(AOJ_COURSES, contestId);
328328
}
329329

330330
if (contestId.startsWith('PCK')) {
331-
return getAojChallengeLabel(PCK_TRANSLATIONS, contestId);
331+
return getAojContestLabel(PCK_TRANSLATIONS, contestId);
332332
}
333333

334334
if (contestId.startsWith('JAG')) {
335-
return getAojChallengeLabel(JAG_TRANSLATIONS, contestId);
335+
return getAojContestLabel(JAG_TRANSLATIONS, contestId);
336336
}
337337

338338
return contestId.toUpperCase();
@@ -349,6 +349,10 @@ export const getContestNameLabel = (contestId: string) => {
349349
* @returns The formatted contest label (ex: UTPC 2023).
350350
*/
351351
export function getAtCoderUniversityContestLabel(contestId: string): string {
352+
if (!regexForAtCoderUniversity.test(contestId)) {
353+
throw new Error(`Invalid university contest ID format: ${contestId}`);
354+
}
355+
352356
return contestId.replace(
353357
regexForAtCoderUniversity,
354358
(_, contestType, common, contestYear) =>
@@ -386,7 +390,7 @@ const JAG_TRANSLATIONS = {
386390
Regional: ' 模擬地区 ',
387391
};
388392

389-
function getAojChallengeLabel(
393+
export function getAojContestLabel(
390394
translations: Readonly<ContestLabelTranslations>,
391395
contestId: string,
392396
): string {
@@ -410,5 +414,7 @@ export const addContestNameToTaskIndex = (contestId: string, taskTableIndex: str
410414
};
411415

412416
function isAojContest(contestId: string): boolean {
413-
return contestId.startsWith('PCK') || contestId.startsWith('JAG');
417+
return (
418+
aojCoursePrefixes.has(contestId) || contestId.startsWith('PCK') || contestId.startsWith('JAG')
419+
);
414420
}

src/test/lib/utils/test_cases/contest_name_and_task_index.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
import { createTestCase, zip } from '../../common/test_helpers';
2-
import { getAtCoderUniversityContestLabel } from '$lib/utils/contest';
2+
import {
3+
getAtCoderUniversityContestLabel,
4+
getAojContestLabel,
5+
AOJ_COURSES,
6+
} from '$lib/utils/contest';
37

48
export type TestCaseForContestNameAndTaskIndex = {
59
contestId: string;
@@ -373,7 +377,7 @@ const generateAojCoursesTestCases = (
373377
)({
374378
contestId: `${contestId}`,
375379
taskTableIndex: `${contestId}_${taskIndex}`,
376-
expected: `AOJ Courses - ${contestId}_${taskIndex}`,
380+
expected: `AOJ ${contestId}_${taskIndex}${getAojContestLabel(AOJ_COURSES, contestId)}`,
377381
});
378382

379383
return testCase;

0 commit comments

Comments
 (0)