Skip to content

Commit 26676ff

Browse files
committed
📚 Add validation to helper method (#2627)
1 parent 930f11c commit 26676ff

File tree

1 file changed

+17
-0
lines changed
  • docs/dev-notes/2025-09-23/contest-task-pair-mapping

1 file changed

+17
-0
lines changed

docs/dev-notes/2025-09-23/contest-task-pair-mapping/plan.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -361,7 +361,22 @@ export class TaskMapAdapter<T> {
361361
// 他のメソッド (has, set, delete) も同様に実装
362362
}
363363

364+
/**
365+
* Creates a unique key for a ContestTaskPair using contestId and taskId.
366+
* Throws an error if either argument is an empty string.
367+
*
368+
* @param contestId - The ID of the contest.
369+
* @param taskId - The ID of the task.
370+
* @returns A string in the format "contestId:taskId".
371+
* @throws Will throw an error if contestId or taskId is empty.
372+
*/
364373
export function createContestTaskPairKey(contestId: string, taskId: string): ContestTaskPairKey {
374+
if (!contestId || contestId.trim() === '') {
375+
throw new Error('contestId must be a non-empty string');
376+
}
377+
if (!taskId || taskId.trim() === '') {
378+
throw new Error('taskId must be a non-empty string');
379+
365380
return `${contestId}:${taskId}`;
366381
}
367382
```
@@ -569,6 +584,8 @@ describe('createContestTaskPairKey', () => {
569584
test('expect to validate input parameters', () => {
570585
expect(() => createContestTaskPairKey('', 'task')).toThrow();
571586
expect(() => createContestTaskPairKey('contest', '')).toThrow();
587+
expect(() => createContestTaskPairKey(' ', 'task')).toThrow();
588+
expect(() => createContestTaskPairKey('contest', ' ')).toThrow();
572589
});
573590
});
574591
```

0 commit comments

Comments
 (0)