Skip to content

Commit a4932e2

Browse files
authored
Merge pull request #1231 from AtCoder-NoviSteps/#747
✨ Add arc to contest type (#747)
2 parents 9237b4d + ece0dd0 commit a4932e2

File tree

6 files changed

+92
-2
lines changed

6 files changed

+92
-2
lines changed

prisma/ERD.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ JOI JOI
2020
TYPICAL90 TYPICAL90
2121
TESSOKU_BOOK TESSOKU_BOOK
2222
MATH_AND_ALGORITHM MATH_AND_ALGORITHM
23+
ARC ARC
2324
OTHERS OTHERS
2425
}
2526
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
-- AlterEnum
2+
ALTER TYPE "ContestType" ADD VALUE 'ARC';

prisma/schema.prisma

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,7 @@ enum ContestType {
215215
TYPICAL90 // 競プロ典型 90 問
216216
TESSOKU_BOOK // 競技プログラミングの鉄則
217217
MATH_AND_ALGORITHM // アルゴリズムと数学
218+
ARC // AtCoder Regular Contest
218219
OTHERS // その他
219220
}
220221

src/lib/types/contest.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ export const ContestType: { [key in ContestTypeOrigin]: key } = {
1313
TYPICAL90: 'TYPICAL90', // 競プロ典型 90 問
1414
TESSOKU_BOOK: 'TESSOKU_BOOK', // 競技プログラミングの鉄則
1515
MATH_AND_ALGORITHM: 'MATH_AND_ALGORITHM', // アルゴリズムと数学
16+
ARC: 'ARC', // AtCoder Regular Contest
1617
OTHERS: 'OTHERS',
1718
} as const;
1819

src/lib/utils/contest.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ export const classifyContest = (contest_id: string) => {
88
return ContestType.ABC;
99
}
1010

11+
if (/^arc\d{3}$/.exec(contest_id)) {
12+
return ContestType.ARC;
13+
}
14+
1115
if (contest_id.startsWith('APG4b')) {
1216
return ContestType.APG4B;
1317
}
@@ -57,7 +61,9 @@ export const classifyContest = (contest_id: string) => {
5761
return null;
5862
};
5963

60-
// priority: 0 (High) - 11 (Low)
64+
// priority: 0 (High) - 12 (Low)
65+
// HACK: ARCの優先順位は暫定版
66+
//
6167
// See:
6268
// https://jsprimer.net/basic/map-and-set/
6369
export const contestTypePriorities: Map<ContestType, number> = new Map([
@@ -72,7 +78,8 @@ export const contestTypePriorities: Map<ContestType, number> = new Map([
7278
[ContestType.JOI, 8],
7379
[ContestType.TESSOKU_BOOK, 9],
7480
[ContestType.MATH_AND_ALGORITHM, 10],
75-
[ContestType.OTHERS, 11],
81+
[ContestType.ARC, 11],
82+
[ContestType.OTHERS, 12],
7683
]);
7784

7885
export function getContestPriority(contestId: string): number {

src/test/lib/utils/contest.test.ts

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,27 @@ describe('Contest', () => {
113113
expect(classifyContest('math-and-algorithm')).toEqual(ContestType.MATH_AND_ALGORITHM);
114114
});
115115

116+
describe('when contest_id contains arc', () => {
117+
const testCases = [
118+
{ contestId: 'arc001', expected: ContestType.ARC },
119+
{ contestId: 'arc002', expected: ContestType.ARC },
120+
{ contestId: 'arc057', expected: ContestType.ARC },
121+
{ contestId: 'arc058', expected: ContestType.ARC },
122+
{ contestId: 'arc099', expected: ContestType.ARC },
123+
{ contestId: 'arc100', expected: ContestType.ARC },
124+
{ contestId: 'arc101', expected: ContestType.ARC },
125+
{ contestId: 'arc103', expected: ContestType.ARC },
126+
{ contestId: 'arc104', expected: ContestType.ARC },
127+
{ contestId: 'arc105', expected: ContestType.ARC },
128+
{ contestId: 'arc182', expected: ContestType.ARC },
129+
{ contestId: 'arc183', expected: ContestType.ARC },
130+
];
131+
132+
runTests('classifyContest', testCases, ({ contestId, expected }: TestCaseForContestType) => {
133+
expect(classifyContest(contestId)).toEqual(expected);
134+
});
135+
});
136+
116137
describe('when contest_id contains chokudai_S', () => {
117138
const testCases = [
118139
{ contestId: 'chokudai_S001', expected: ContestType.OTHERS },
@@ -241,6 +262,31 @@ describe('Contest', () => {
241262
);
242263
});
243264

265+
describe('when contest_id contains arc', () => {
266+
const testCases = [
267+
{ contestId: 'arc001', expected: ContestType.ARC },
268+
{ contestId: 'arc002', expected: ContestType.ARC },
269+
{ contestId: 'arc057', expected: ContestType.ARC },
270+
{ contestId: 'arc058', expected: ContestType.ARC },
271+
{ contestId: 'arc099', expected: ContestType.ARC },
272+
{ contestId: 'arc100', expected: ContestType.ARC },
273+
{ contestId: 'arc101', expected: ContestType.ARC },
274+
{ contestId: 'arc103', expected: ContestType.ARC },
275+
{ contestId: 'arc104', expected: ContestType.ARC },
276+
{ contestId: 'arc105', expected: ContestType.ARC },
277+
{ contestId: 'arc182', expected: ContestType.ARC },
278+
{ contestId: 'arc183', expected: ContestType.ARC },
279+
];
280+
281+
runTests(
282+
'getContestPriority',
283+
testCases,
284+
({ contestId, expected }: TestCaseForContestType) => {
285+
expect(getContestPriority(contestId)).toEqual(contestTypePriorities.get(expected));
286+
},
287+
);
288+
});
289+
244290
describe('when contest_id contains chokudai_S', () => {
245291
const testCases = [
246292
{ contestId: 'chokudai_S001', expected: ContestType.OTHERS },
@@ -272,6 +318,13 @@ describe('Contest', () => {
272318

273319
expect(getContestUrl(contestId)).toEqual(expected);
274320
});
321+
322+
test('when contest_id is ARC183', () => {
323+
const contestId = 'arc183';
324+
const expected = 'https://atcoder.jp/contests/arc183';
325+
326+
expect(getContestUrl(contestId)).toEqual(expected);
327+
});
275328
});
276329

277330
describe('get contest name label', () => {
@@ -383,6 +436,31 @@ describe('Contest', () => {
383436
expect(getContestNameLabel('math-and-algorithm')).toEqual('アルゴリズムと数学');
384437
});
385438

439+
describe('when contest_id contains arc', () => {
440+
const testCases = [
441+
{ contestId: 'arc001', expected: 'ARC001' },
442+
{ contestId: 'arc002', expected: 'ARC002' },
443+
{ contestId: 'arc057', expected: 'ARC057' },
444+
{ contestId: 'arc058', expected: 'ARC058' },
445+
{ contestId: 'arc099', expected: 'ARC099' },
446+
{ contestId: 'arc100', expected: 'ARC100' },
447+
{ contestId: 'arc101', expected: 'ARC101' },
448+
{ contestId: 'arc103', expected: 'ARC103' },
449+
{ contestId: 'arc104', expected: 'ARC104' },
450+
{ contestId: 'arc105', expected: 'ARC105' },
451+
{ contestId: 'arc182', expected: 'ARC182' },
452+
{ contestId: 'arc183', expected: 'ARC183' },
453+
];
454+
455+
runTests(
456+
'getContestNameLabel',
457+
testCases,
458+
({ contestId, expected }: TestCaseForContestNameLabel) => {
459+
expect(getContestNameLabel(contestId)).toEqual(expected);
460+
},
461+
);
462+
});
463+
386464
describe('when contest_id contains chokudai_S', () => {
387465
const testCases = [
388466
{ contestId: 'chokudai_S001', expected: 'Chokudai SpeedRun 001' },

0 commit comments

Comments
 (0)