Skip to content

Commit bde5d32

Browse files
committed
refactor: Remove duplicated codes (#3169)
1 parent 5344234 commit bde5d32

File tree

3 files changed

+13
-43
lines changed

3 files changed

+13
-43
lines changed

src/features/tasks/utils/contest-table/abc_providers.test.ts

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -10,19 +10,9 @@ import {
1010
ABC042ToABC125Provider,
1111
ABC001ToABC041Provider,
1212
} from './abc_providers';
13+
import { parseContestRound } from './contest_table_provider_base';
1314
import { taskResultsForContestTableProvider } from '$features/tasks/fixtures/contest-table/contest_table_provider';
1415

15-
const getContestRound = (contestId: string): number => {
16-
const roundString = contestId.replace(/^\D+/, '');
17-
const round = parseInt(roundString, 10);
18-
19-
if (isNaN(round)) {
20-
throw new Error(`Invalid contest ID format: ${contestId}`);
21-
}
22-
23-
return round;
24-
};
25-
2616
describe('ABC providers', () => {
2717
const mockTaskResults: TaskResults = taskResultsForContestTableProvider;
2818

@@ -116,7 +106,7 @@ describe('ABC providers', () => {
116106
expect(filtered.every((task) => task.contest_id.startsWith('abc'))).toBe(true);
117107
expect(
118108
filtered.every((task) => {
119-
const round = getContestRound(task.contest_id);
109+
const round = parseContestRound(task.contest_id, 'abc');
120110
return round >= 319 && round <= 999;
121111
}),
122112
).toBe(true);
@@ -143,7 +133,7 @@ describe('ABC providers', () => {
143133
expect(filtered.every((task) => task.contest_id.startsWith('abc'))).toBe(true);
144134
expect(
145135
filtered.every((task) => {
146-
const round = getContestRound(task.contest_id);
136+
const round = parseContestRound(task.contest_id, 'abc');
147137
return round >= 319;
148138
}),
149139
).toBe(true);
@@ -159,7 +149,7 @@ describe('ABC providers', () => {
159149
expect(filtered.every((task) => task.contest_id.startsWith('abc'))).toBe(true);
160150
expect(
161151
filtered.every((task) => {
162-
const round = getContestRound(task.contest_id);
152+
const round = parseContestRound(task.contest_id, 'abc');
163153
return round >= 212 && round <= 318;
164154
}),
165155
).toBe(true);
@@ -187,7 +177,7 @@ describe('ABC providers', () => {
187177
expect(filtered.every((task) => task.contest_id.startsWith('abc'))).toBe(true);
188178
expect(
189179
filtered.every((task) => {
190-
const round = getContestRound(task.contest_id);
180+
const round = parseContestRound(task.contest_id, 'abc');
191181
return round >= 212 && round <= 318;
192182
}),
193183
).toBe(true);
@@ -203,7 +193,7 @@ describe('ABC providers', () => {
203193
expect(filtered.every((task) => task.contest_id.startsWith('abc'))).toBe(true);
204194
expect(
205195
filtered.every((task) => {
206-
const round = getContestRound(task.contest_id);
196+
const round = parseContestRound(task.contest_id, 'abc');
207197
return round >= 126 && round <= 211;
208198
}),
209199
).toBe(true);
@@ -241,7 +231,7 @@ describe('ABC providers', () => {
241231
expect(filtered.every((task) => task.contest_id.startsWith('abc'))).toBe(true);
242232
expect(
243233
filtered.every((task) => {
244-
const round = getContestRound(task.contest_id);
234+
const round = parseContestRound(task.contest_id, 'abc');
245235
return round >= 126 && round <= 211;
246236
}),
247237
).toBe(true);

src/features/tasks/utils/contest-table/agc_provider.test.ts

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,9 @@ import { ContestType } from '$lib/types/contest';
44
import type { TaskResults } from '$lib/types/task';
55

66
import { AGC001OnwardsProvider } from './agc_provider';
7+
import { parseContestRound } from './contest_table_provider_base';
78
import { taskResultsForAGC001OnwardsProvider } from '$features/tasks/fixtures/contest-table/contest_table_provider';
89

9-
const getContestRound = (contestId: string): number => {
10-
const roundString = contestId.replace(/^\D+/, '');
11-
const round = parseInt(roundString, 10);
12-
13-
if (isNaN(round)) {
14-
throw new Error(`Invalid contest ID format: ${contestId}`);
15-
}
16-
17-
return round;
18-
};
19-
2010
describe('AGC001OnwardsProvider', () => {
2111
test('expects to filter tasks to include only AGC001 and later', () => {
2212
const provider = new AGC001OnwardsProvider(ContestType.AGC);
@@ -25,7 +15,7 @@ describe('AGC001OnwardsProvider', () => {
2515
expect(filtered.every((task) => task.contest_id.startsWith('agc'))).toBe(true);
2616
expect(
2717
filtered.every((task) => {
28-
const round = getContestRound(task.contest_id);
18+
const round = parseContestRound(task.contest_id, 'agc');
2919
return round >= 1 && round <= 999;
3020
}),
3121
).toBe(true);
@@ -186,7 +176,7 @@ describe('AGC001OnwardsProvider', () => {
186176
expect(filtered).toHaveLength(3);
187177
expect(
188178
filtered.every((task) => {
189-
const round = getContestRound(task.contest_id);
179+
const round = parseContestRound(task.contest_id, 'agc');
190180
return round >= 1 && round <= 999;
191181
}),
192182
).toBe(true);

src/features/tasks/utils/contest-table/arc_providers.test.ts

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,9 @@ import {
88
ARC058ToARC103Provider,
99
ARC001ToARC057Provider,
1010
} from './arc_providers';
11+
import { parseContestRound } from './contest_table_provider_base';
1112
import { taskResultsForARC104OnwardsProvider } from '$features/tasks/fixtures/contest-table/contest_table_provider';
1213

13-
const getContestRound = (contestId: string): number => {
14-
const roundString = contestId.replace(/^\D+/, '');
15-
const round = parseInt(roundString, 10);
16-
17-
if (isNaN(round)) {
18-
throw new Error(`Invalid contest ID format: ${contestId}`);
19-
}
20-
21-
return round;
22-
};
23-
2414
describe('ARC providers', () => {
2515
// ARC 104 Onwards only
2616
describe('ARC 104 Onwards', () => {
@@ -31,7 +21,7 @@ describe('ARC providers', () => {
3121
expect(filtered.every((task) => task.contest_id.startsWith('arc'))).toBe(true);
3222
expect(
3323
filtered.every((task) => {
34-
const round = getContestRound(task.contest_id);
24+
const round = parseContestRound(task.contest_id, 'arc');
3525
return round >= 104 && round <= 999;
3626
}),
3727
).toBe(true);
@@ -162,7 +152,7 @@ describe('ARC providers', () => {
162152
expect(filtered).toHaveLength(2);
163153
expect(
164154
filtered.every((task) => {
165-
const round = getContestRound(task.contest_id);
155+
const round = parseContestRound(task.contest_id, 'arc');
166156
return round >= 104;
167157
}),
168158
).toBe(true);

0 commit comments

Comments
 (0)