Skip to content

Commit

Permalink
:docs: Improve ABC, ARC and AGC contest labels (#1526)
Browse files Browse the repository at this point in the history
  • Loading branch information
KATO-Hiro committed Nov 24, 2024
1 parent 22b9310 commit 5352890
Show file tree
Hide file tree
Showing 3 changed files with 110 additions and 81 deletions.
63 changes: 46 additions & 17 deletions src/lib/utils/contest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -240,52 +240,81 @@ export function getContestPriority(contestId: string): number {
}
}

export const getContestNameLabel = (contest_id: string) => {
if (contest_id === 'APG4b' || contest_id === 'APG4bPython') {
return contest_id;
/**
* Regular expression to match contest codes.
*
* This regex matches strings that start with one of the following prefixes:
* - "abc"
* - "arc"
* - "agc"
*
* followed by exactly three digits. The matching is case-insensitive.
*
* Example matches:
* - "abc376"
* - "ARC128"
* - "agc045"
*
* Example non-matches:
* - "xyz123"
* - "abc12"
* - "abc1234"
*/
const regexForAxc = /^(abc|arc|agc)(\d{3})/i;

export const getContestNameLabel = (contestId: string) => {
if (regexForAxc.exec(contestId)) {
return contestId.replace(
regexForAxc,
(_, contestType, contestNumber) => `${contestType.toUpperCase()} ${contestNumber}`,
);
}

if (contest_id === 'typical90') {
if (contestId === 'APG4b' || contestId === 'APG4bPython') {
return contestId;
}

if (contestId === 'typical90') {
return '競プロ典型 90 問';
}

if (contest_id === 'dp') {
if (contestId === 'dp') {
return 'EDPC';
}

if (contest_id === 'tdpc') {
if (contestId === 'tdpc') {
return 'TDPC';
}

if (contest_id === 'practice2') {
if (contestId === 'practice2') {
return 'ACL Practice';
}

if (contest_id === 'tessoku-book') {
if (contestId === 'tessoku-book') {
return '競技プログラミングの鉄則';
}

if (contest_id === 'math-and-algorithm') {
if (contestId === 'math-and-algorithm') {
return 'アルゴリズムと数学';
}

if (contest_id.startsWith('chokudai_S')) {
return contest_id.replace('chokudai_S', 'Chokudai SpeedRun ');
if (contestId.startsWith('chokudai_S')) {
return contestId.replace('chokudai_S', 'Chokudai SpeedRun ');
}

if (aojCoursePrefixes.has(contest_id)) {
if (aojCoursePrefixes.has(contestId)) {
return 'AOJ Courses';
}

if (contest_id.startsWith('PCK')) {
return getAojChallengeLabel(PCK_TRANSLATIONS, contest_id);
if (contestId.startsWith('PCK')) {
return getAojChallengeLabel(PCK_TRANSLATIONS, contestId);
}

if (contest_id.startsWith('JAG')) {
return getAojChallengeLabel(JAG_TRANSLATIONS, contest_id);
if (contestId.startsWith('JAG')) {
return getAojChallengeLabel(JAG_TRANSLATIONS, contestId);
}

return contest_id.toUpperCase();
return contestId.toUpperCase();
};

/**
Expand Down
42 changes: 21 additions & 21 deletions src/test/lib/utils/test_cases/contest_name_and_task_index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@ const generateAbcTestCases = (
taskIndices: string[],
): { name: string; value: TestCaseForContestNameAndTaskIndex }[] => {
return zip(contestIds, taskIndices).map(([contestId, taskIndex]) => {
const testCase = createTestCaseForContestNameAndTaskIndex(`ABC${contestId}, task ${taskIndex}`)(
{
contestId: `abc${contestId}`,
taskTableIndex: taskIndex,
expected: `ABC${contestId} - ${taskIndex}`,
},
);
const testCase = createTestCaseForContestNameAndTaskIndex(
`ABC ${contestId}, task ${taskIndex}`,
)({
contestId: `abc${contestId}`,
taskTableIndex: taskIndex,
expected: `ABC ${contestId} - ${taskIndex}`,
});

return testCase;
});
Expand Down Expand Up @@ -162,13 +162,13 @@ const generateArcTestCases = (
taskIndices: string[],
): { name: string; value: TestCaseForContestNameAndTaskIndex }[] => {
return zip(contestIds, taskIndices).map(([contestId, taskIndex]) => {
const testCase = createTestCaseForContestNameAndTaskIndex(`ARC${contestId}, task ${taskIndex}`)(
{
contestId: `arc${contestId}`,
taskTableIndex: taskIndex,
expected: `ARC${contestId} - ${taskIndex}`,
},
);
const testCase = createTestCaseForContestNameAndTaskIndex(
`ARC ${contestId}, task ${taskIndex}`,
)({
contestId: `arc${contestId}`,
taskTableIndex: taskIndex,
expected: `ARC ${contestId} - ${taskIndex}`,
});

return testCase;
});
Expand All @@ -184,13 +184,13 @@ const generateAgcTestCases = (
taskIndices: string[],
): { name: string; value: TestCaseForContestNameAndTaskIndex }[] => {
return zip(contestIds, taskIndices).map(([contestId, taskIndex]) => {
const testCase = createTestCaseForContestNameAndTaskIndex(`AGC${contestId}, task ${taskIndex}`)(
{
contestId: `agc${contestId}`,
taskTableIndex: taskIndex,
expected: `AGC${contestId} - ${taskIndex}`,
},
);
const testCase = createTestCaseForContestNameAndTaskIndex(
`AGC ${contestId}, task ${taskIndex}`,
)({
contestId: `agc${contestId}`,
taskTableIndex: taskIndex,
expected: `AGC ${contestId} - ${taskIndex}`,
});

return testCase;
});
Expand Down
86 changes: 43 additions & 43 deletions src/test/lib/utils/test_cases/contest_name_labels.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ const generateAbcTestCases = (
contestIds: string[],
): { name: string; value: TestCaseForContestNameLabel }[] => {
return contestIds.map((contestId) => {
const testCase = createTestCaseForContestNameLabel(`ABC${contestId}`)({
const testCase = createTestCaseForContestNameLabel(`ABC ${contestId}`)({
contestId: `abc${contestId}`,
expected: `ABC${contestId}`,
expected: `ABC ${contestId}`,
});

return testCase;
Expand All @@ -28,7 +28,7 @@ export const abc = generateAbcTestCases([
'101',
'200',
'201',
'365',
'380',
'999',
]);

Expand Down Expand Up @@ -170,84 +170,84 @@ export const mathAndAlgorithm = [
];

export const arc = [
createTestCaseForContestNameLabel('ARC001')({
createTestCaseForContestNameLabel('ARC 001')({
contestId: 'arc001',
expected: 'ARC001',
expected: 'ARC 001',
}),
createTestCaseForContestNameLabel('ARC002')({
createTestCaseForContestNameLabel('ARC 002')({
contestId: 'arc002',
expected: 'ARC002',
expected: 'ARC 002',
}),
createTestCaseForContestNameLabel('ARC057')({
createTestCaseForContestNameLabel('ARC 057')({
contestId: 'arc057',
expected: 'ARC057',
expected: 'ARC 057',
}),
createTestCaseForContestNameLabel('ARC058')({
createTestCaseForContestNameLabel('ARC 058')({
contestId: 'arc058',
expected: 'ARC058',
expected: 'ARC 058',
}),
createTestCaseForContestNameLabel('ARC099')({
createTestCaseForContestNameLabel('ARC 099')({
contestId: 'arc099',
expected: 'ARC099',
expected: 'ARC 099',
}),
createTestCaseForContestNameLabel('ARC100')({
createTestCaseForContestNameLabel('ARC 100')({
contestId: 'arc100',
expected: 'ARC100',
expected: 'ARC 100',
}),
createTestCaseForContestNameLabel('ARC101')({
createTestCaseForContestNameLabel('ARC 101')({
contestId: 'arc101',
expected: 'ARC101',
expected: 'ARC 101',
}),
createTestCaseForContestNameLabel('ARC103')({
createTestCaseForContestNameLabel('ARC 103')({
contestId: 'arc103',
expected: 'ARC103',
expected: 'ARC 103',
}),
createTestCaseForContestNameLabel('ARC104')({
createTestCaseForContestNameLabel('ARC 104')({
contestId: 'arc104',
expected: 'ARC104',
expected: 'ARC 104',
}),
createTestCaseForContestNameLabel('ARC105')({
createTestCaseForContestNameLabel('ARC 105')({
contestId: 'arc105',
expected: 'ARC105',
expected: 'ARC 105',
}),
createTestCaseForContestNameLabel('ARC182')({
contestId: 'arc182',
expected: 'ARC182',
createTestCaseForContestNameLabel('ARC 187')({
contestId: 'arc187',
expected: 'ARC 187',
}),
createTestCaseForContestNameLabel('ARC183')({
contestId: 'arc183',
expected: 'ARC183',
createTestCaseForContestNameLabel('ARC 188')({
contestId: 'arc188',
expected: 'ARC 188',
}),
];

export const agc = [
createTestCaseForContestNameLabel('AGC001')({
createTestCaseForContestNameLabel('AGC 001')({
contestId: 'agc001',
expected: 'AGC001',
expected: 'AGC 001',
}),
createTestCaseForContestNameLabel('AGC002')({
createTestCaseForContestNameLabel('AGC 002')({
contestId: 'agc002',
expected: 'AGC002',
expected: 'AGC 002',
}),
createTestCaseForContestNameLabel('AGC009')({
createTestCaseForContestNameLabel('AGC 009')({
contestId: 'agc009',
expected: 'AGC009',
expected: 'AGC 009',
}),
createTestCaseForContestNameLabel('AGC010')({
createTestCaseForContestNameLabel('AGC 010')({
contestId: 'agc010',
expected: 'AGC010',
expected: 'AGC 010',
}),
createTestCaseForContestNameLabel('AGC011')({
createTestCaseForContestNameLabel('AGC 011')({
contestId: 'agc011',
expected: 'AGC011',
expected: 'AGC 011',
}),
createTestCaseForContestNameLabel('AGC066')({
createTestCaseForContestNameLabel('AGC 066')({
contestId: 'agc066',
expected: 'AGC066',
expected: 'AGC 066',
}),
createTestCaseForContestNameLabel('AGC067')({
createTestCaseForContestNameLabel('AGC 067')({
contestId: 'agc067',
expected: 'AGC067',
expected: 'AGC 067',
}),
];

Expand Down

0 comments on commit 5352890

Please sign in to comment.