Skip to content

Commit 6fccadb

Browse files
committed
♻️ Refactoring tests and add docs (#1856)
1 parent 095b393 commit 6fccadb

File tree

1 file changed

+45
-23
lines changed

1 file changed

+45
-23
lines changed

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

+45-23
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,16 @@ import type { TaskResult, TaskResults } from '$lib/types/task';
66
// and task_id for header name testing.
77

88
/**
9-
* Default task result object used as a template for test data.
10-
* Most fields are initialized as empty strings as they're not relevant for these tests.
11-
* @type {TaskResult}
9+
* Default initial values for a TaskResult object.
10+
*
11+
* This constant provides empty or falsy default values for all properties
12+
* of a TaskResult. It's marked as readonly to prevent modifications.
13+
* The `updated_at` date is set to Unix epoch (January 1, 1970) as a
14+
* clearly identifiable default timestamp.
15+
*
16+
* @type {Readonly<TaskResult>} An immutable default TaskResult object
1217
*/
13-
const defaultTaskResult: TaskResult = {
18+
const defaultTaskResult: Readonly<TaskResult> = {
1419
is_ac: false,
1520
user_id: '',
1621
status_name: '',
@@ -120,6 +125,41 @@ const [abc319_a, abc319_b, abc319_c, abc319_d, abc319_e, abc319_f, abc319_g] = c
120125
],
121126
);
122127

128+
/**
129+
* Creates an array of contest task results with sequential contest numbers.
130+
*
131+
* @param startContestNumber - The first contest number in the sequence
132+
* @param contestCount - The number of contests to generate
133+
* @param taskIndex - The task index (e.g., 'A', 'B', 'C') to use for all contests
134+
* @returns An array of task results with alternating statuses (AC, AC_WITH_EDITORIAL, TRYING, PENDING)
135+
* in a repeating pattern. Each task has the format `abc{contestNumber}_{taskIndex.toLowerCase()}`.
136+
*
137+
* @example
138+
* Creates 3 contest results starting from ABC123 with task index D
139+
* const contests = createContestsRange(123, 3, 'D');
140+
*/
141+
function createContestsRange(startContestNumber: number, contestCount: number, taskIndex: string) {
142+
return Array.from({ length: contestCount }, (_, i) => {
143+
const contestNumber = startContestNumber + i;
144+
const contestId = `abc${contestNumber}`;
145+
const taskId = `${contestId}_${taskIndex.toLowerCase()}`;
146+
// Alternating statuses for variety
147+
let statusName;
148+
149+
if (i % 4 === 0) {
150+
statusName = AC;
151+
} else if (i % 4 === 1) {
152+
statusName = AC_WITH_EDITORIAL;
153+
} else if (i % 4 === 2) {
154+
statusName = TRYING;
155+
} else {
156+
statusName = PENDING;
157+
}
158+
159+
return createTaskResultWithTaskTableIndex(contestId, taskId, 'G', statusName);
160+
});
161+
}
162+
123163
const [
124164
abc376_g,
125165
abc377_g,
@@ -143,25 +183,7 @@ const [
143183
abc395_g,
144184
abc396_g,
145185
abc397_g,
146-
] = Array.from({ length: 22 }, (_, i) => {
147-
const contestNum = 376 + i;
148-
const contestId = `abc${contestNum}`;
149-
const taskId = `${contestId}_g`;
150-
// Alternating statuses for variety
151-
let statusName;
152-
153-
if (i % 4 === 0) {
154-
statusName = AC;
155-
} else if (i % 4 === 1) {
156-
statusName = AC_WITH_EDITORIAL;
157-
} else if (i % 4 === 2) {
158-
statusName = TRYING;
159-
} else {
160-
statusName = PENDING;
161-
}
162-
163-
return createTaskResultWithTaskTableIndex(contestId, taskId, 'G', statusName);
164-
});
186+
] = createContestsRange(376, 22, 'G');
165187

166188
export const taskResultsForContestTableProvider: TaskResults = [
167189
abc212_a,

0 commit comments

Comments
 (0)