Skip to content

Commit 511219e

Browse files
committed
♻️ Refactoring tests and data (#1856)
1 parent e1a3739 commit 511219e

File tree

2 files changed

+18
-28
lines changed

2 files changed

+18
-28
lines changed

src/test/lib/utils/contest_table_provider.test.ts

Lines changed: 11 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@ vi.mock('$lib/utils/task', () => ({
3333

3434
describe('ContestTableProviderBase and implementations', () => {
3535
const mockTaskResults: TaskResults = taskResultsForContestTableProvider;
36+
const getContestRound = (contestId: string): number => {
37+
return parseInt(contestId.replace('abc', ''), 10);
38+
};
3639

3740
describe('ABC latest 20 rounds provider', () => {
3841
test('expects to filter tasks to include only ABC contests', () => {
@@ -50,7 +53,7 @@ describe('ContestTableProviderBase and implementations', () => {
5053
const filtered = provider.filter(largeDataset);
5154
const uniqueContests = new Set(filtered.map((task) => task.contest_id));
5255

53-
expect(uniqueContests.size).toBeLessThanOrEqual(20);
56+
expect(uniqueContests.size).toBe(20);
5457
});
5558

5659
test('expects to generate correct table structure', () => {
@@ -90,7 +93,7 @@ describe('ContestTableProviderBase and implementations', () => {
9093
expect(filtered.every((task) => task.contest_id.startsWith('abc'))).toBeTruthy();
9194
expect(
9295
filtered.every((task) => {
93-
const round = parseInt(task.contest_id.replace('abc', ''), 10);
96+
const round = getContestRound(task.contest_id);
9497
return round >= 319 && round <= 999;
9598
}),
9699
).toBeTruthy();
@@ -121,7 +124,7 @@ describe('ContestTableProviderBase and implementations', () => {
121124
expect(filtered.every((task) => task.contest_id.startsWith('abc'))).toBeTruthy();
122125
expect(
123126
filtered.every((task) => {
124-
const round = parseInt(task.contest_id.replace('abc', ''), 10);
127+
const round = getContestRound(task.contest_id);
125128
return round >= 212 && round <= 318;
126129
}),
127130
).toBeTruthy();
@@ -147,16 +150,10 @@ describe('ContestTableProviderBase and implementations', () => {
147150
describe('Common provider functionality', () => {
148151
test('expects to get contest round IDs correctly', () => {
149152
const provider = contestTableProviders.abcLatest20Rounds;
150-
const filtered = [
151-
{ contest_id: 'abc397', task_id: 'a', status_name: 'ac' },
152-
{ contest_id: 'abc319', task_id: 'a', status_name: 'ac' },
153-
{ contest_id: 'abc319', task_id: 'b', status_name: 'ac' },
154-
{ contest_id: 'abc319', task_id: 'c', status_name: 'ac' },
155-
{ contest_id: 'abc319', task_id: 'e', status_name: 'ac_with_editorial' },
156-
{ contest_id: 'abc319', task_id: 'f', status_name: 'wa' },
157-
{ contest_id: 'abc319', task_id: 'g', status_name: 'ns' },
158-
{ contest_id: 'abc318', task_id: 'a', status_name: 'ac' },
159-
] as TaskResults;
153+
// Use a subset of the mock data that covers the relevant contest IDs
154+
const filtered = mockTaskResults.filter((task) =>
155+
['abc397', 'abc319', 'abc318'].includes(task.contest_id),
156+
);
160157

161158
const roundIds = provider.getContestRoundIds(filtered);
162159

@@ -165,21 +162,7 @@ describe('ContestTableProviderBase and implementations', () => {
165162

166163
test('expects to get header IDs for tasks correctly', () => {
167164
const provider = contestTableProviders.abcLatest20Rounds;
168-
const filtered = [
169-
{ contest_id: 'abc319', task_id: 'abc319_a', task_table_index: 'A', status_name: 'ac' },
170-
{ contest_id: 'abc319', task_id: 'abc319_b', task_table_index: 'B', status_name: 'ac' },
171-
{ contest_id: 'abc319', task_id: 'abc319_c', task_table_index: 'C', status_name: 'ac' },
172-
{ contest_id: 'abc319', task_id: 'abc319_d', task_table_index: 'D', status_name: 'ac' },
173-
{
174-
contest_id: 'abc319',
175-
task_id: 'abc319_e',
176-
task_table_index: 'E',
177-
status_name: 'ac_with_editorial',
178-
},
179-
{ contest_id: 'abc319', task_id: 'abc319_f', task_table_index: 'F', status_name: 'wa' },
180-
{ contest_id: 'abc319', task_id: 'abc319_g', task_table_index: 'G', status_name: 'ns' },
181-
] as TaskResults;
182-
165+
const filtered = mockTaskResults.filter((task) => task.contest_id === 'abc319');
183166
const headerIds = provider.getHeaderIdsForTask(filtered);
184167

185168
expect(headerIds).toEqual(['A', 'B', 'C', 'D', 'E', 'F', 'G']);

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ function createTaskResultWithTaskTableIndex(
4949
}
5050

5151
// ABC212 - ABC232: 8 tasks (A, B, C, D, E, F, G and H)
52+
// // Mix of different submission statuses to test various filtering and display scenarios.
5253
const abc212_a = createTaskResultWithTaskTableIndex('abc212', 'abc212_a', 'A', AC);
5354
const abc212_b = createTaskResultWithTaskTableIndex('abc212', 'abc212_b', 'B', AC);
5455
const abc212_f = createTaskResultWithTaskTableIndex('abc212', 'abc212_f', 'F', AC_WITH_EDITORIAL);
@@ -68,6 +69,9 @@ const abc318_ex = createTaskResultWithTaskTableIndex('abc318', 'abc318_ex', 'Ex'
6869
// ABC319 - : 7 tasks (A, B, C, D, E, F and G)
6970
const abc319_a = createTaskResultWithTaskTableIndex('abc319', 'abc319_a', 'A', AC);
7071
const abc319_b = createTaskResultWithTaskTableIndex('abc319', 'abc319_b', 'B', AC);
72+
const abc319_c = createTaskResultWithTaskTableIndex('abc319', 'abc319_c', 'C', AC);
73+
const abc319_d = createTaskResultWithTaskTableIndex('abc319', 'abc319_d', 'D', AC);
74+
const abc319_e = createTaskResultWithTaskTableIndex('abc319', 'abc319_e', 'E', AC_WITH_EDITORIAL);
7175
const abc319_f = createTaskResultWithTaskTableIndex('abc319', 'abc319_f', 'F', TRYING);
7276
const abc319_g = createTaskResultWithTaskTableIndex('abc319', 'abc319_g', 'G', PENDING);
7377
const abc376_g = createTaskResultWithTaskTableIndex('abc376', 'abc376_g', 'G', AC);
@@ -109,6 +113,9 @@ export const taskResultsForContestTableProvider: TaskResults = [
109113
abc318_ex,
110114
abc319_a,
111115
abc319_b,
116+
abc319_c,
117+
abc319_d,
118+
abc319_e,
112119
abc319_f,
113120
abc319_g,
114121
abc376_g,

0 commit comments

Comments
 (0)