Skip to content

Commit 169d06a

Browse files
authored
Merge pull request #1214 from AtCoder-NoviSteps/#1165
✨ Add others to contest type (#1165)
2 parents 5927ad4 + f85dcd5 commit 169d06a

File tree

6 files changed

+58
-1
lines changed

6 files changed

+58
-1
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+
OTHERS OTHERS
2324
}
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 'OTHERS';

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+
OTHERS // その他
218219
}
219220

220221
// 11Q(最も簡単)〜6D(最難関)。

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+
OTHERS: 'OTHERS',
1617
} as const;
1718

1819
// Re-exporting the original type with the original name.

src/lib/utils/contest.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,16 @@ export const classifyContest = (contest_id: string) => {
4848
return ContestType.MATH_AND_ALGORITHM;
4949
}
5050

51+
// HACK: 2024年9月上旬時点では、「Chokudai SpeedRun 001」と「Chokudai SpeedRun 002」のみ該当。
52+
// 対象コンテストが増えた場合は、判定条件を見直す必要がある。
53+
if (contest_id.startsWith('chokudai_S')) {
54+
return ContestType.OTHERS;
55+
}
56+
5157
return null;
5258
};
5359

54-
// priority: 0 (High) - 10 (Low)
60+
// priority: 0 (High) - 11 (Low)
5561
// See:
5662
// https://jsprimer.net/basic/map-and-set/
5763
export const contestTypePriorities: Map<ContestType, number> = new Map([
@@ -66,6 +72,7 @@ export const contestTypePriorities: Map<ContestType, number> = new Map([
6672
[ContestType.JOI, 8],
6773
[ContestType.TESSOKU_BOOK, 9],
6874
[ContestType.MATH_AND_ALGORITHM, 10],
75+
[ContestType.OTHERS, 11],
6976
]);
7077

7178
export function getContestPriority(contestId: string): number {
@@ -112,5 +119,9 @@ export const getContestNameLabel = (contest_id: string) => {
112119
return 'アルゴリズムと数学';
113120
}
114121

122+
if (contest_id.startsWith('chokudai_S')) {
123+
return contest_id.replace('chokudai_S', 'Chokudai SpeedRun ');
124+
}
125+
115126
return contest_id.toUpperCase();
116127
};

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

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

116+
describe('when contest_id contains chokudai_S', () => {
117+
const testCases = [
118+
{ contestId: 'chokudai_S001', expected: ContestType.OTHERS },
119+
{ contestId: 'chokudai_S002', expected: ContestType.OTHERS },
120+
];
121+
122+
runTests('classifyContest', testCases, ({ contestId, expected }: TestCaseForContestType) => {
123+
expect(classifyContest(contestId)).toEqual(expected);
124+
});
125+
});
126+
116127
function runTests(
117128
testName: string,
118129
testCases: TestCasesForContestType,
@@ -230,6 +241,21 @@ describe('Contest', () => {
230241
);
231242
});
232243

244+
describe('when contest_id contains chokudai_S', () => {
245+
const testCases = [
246+
{ contestId: 'chokudai_S001', expected: ContestType.OTHERS },
247+
{ contestId: 'chokudai_S002', expected: ContestType.OTHERS },
248+
];
249+
250+
runTests(
251+
'getContestPriority',
252+
testCases,
253+
({ contestId, expected }: TestCaseForContestType) => {
254+
expect(getContestPriority(contestId)).toEqual(contestTypePriorities.get(expected));
255+
},
256+
);
257+
});
258+
233259
function runTests(
234260
testName: string,
235261
testCases: TestCasesForContestType,
@@ -357,6 +383,21 @@ describe('Contest', () => {
357383
expect(getContestNameLabel('math-and-algorithm')).toEqual('アルゴリズムと数学');
358384
});
359385

386+
describe('when contest_id contains chokudai_S', () => {
387+
const testCases = [
388+
{ contestId: 'chokudai_S001', expected: 'Chokudai SpeedRun 001' },
389+
{ contestId: 'chokudai_S002', expected: 'Chokudai SpeedRun 002' },
390+
];
391+
392+
runTests(
393+
'getContestNameLabel',
394+
testCases,
395+
({ contestId, expected }: TestCaseForContestNameLabel) => {
396+
expect(getContestNameLabel(contestId)).toEqual(expected);
397+
},
398+
);
399+
});
400+
360401
function runTests(
361402
testName: string,
362403
testCases: TestCasesForContestNameLabel,

0 commit comments

Comments
 (0)