Skip to content

Commit 8a0e75f

Browse files
committed
🚨 Add tests for adding task index to contest name (#1145)
1 parent 6f06bf7 commit 8a0e75f

File tree

1 file changed

+207
-0
lines changed

1 file changed

+207
-0
lines changed

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

Lines changed: 207 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import {
66
contestTypePriorities,
77
getContestUrl,
88
getContestNameLabel,
9+
addContestNameToTaskIndex,
910
} from '$lib/utils/contest';
1011
import { ContestType } from '$lib/types/contest';
1112

@@ -23,6 +24,14 @@ type TestCaseForContestNameLabel = {
2324

2425
type TestCasesForContestNameLabel = TestCaseForContestNameLabel[];
2526

27+
type TestCaseForContestNameAndTaskIndex = {
28+
contestId: string;
29+
taskTableIndex: string;
30+
expected: string;
31+
};
32+
33+
type TestCasesForContestNameAndTaskIndex = TestCaseForContestNameAndTaskIndex[];
34+
2635
describe('Contest', () => {
2736
// TODO: Add ARC and AOI.
2837
describe('classify contest', () => {
@@ -484,4 +493,202 @@ describe('Contest', () => {
484493
test.each(testCases)(`${testName}(contestId: $contestId)`, testFunction);
485494
}
486495
});
496+
497+
describe('add contest name to task index', () => {
498+
describe('when contest_id contains ABC', () => {
499+
const testCases: TestCasesForContestNameAndTaskIndex = [
500+
{ contestId: 'abc001', taskTableIndex: 'A', expected: 'ABC001 - A' },
501+
{ contestId: 'abc001', taskTableIndex: 'B', expected: 'ABC001 - B' },
502+
{ contestId: 'abc001', taskTableIndex: 'C', expected: 'ABC001 - C' },
503+
{ contestId: 'abc001', taskTableIndex: 'D', expected: 'ABC001 - D' },
504+
{ contestId: 'abc002', taskTableIndex: 'A', expected: 'ABC002 - A' },
505+
{ contestId: 'abc099', taskTableIndex: 'B', expected: 'ABC099 - B' },
506+
{ contestId: 'abc100', taskTableIndex: 'C', expected: 'ABC100 - C' },
507+
{ contestId: 'abc101', taskTableIndex: 'D', expected: 'ABC101 - D' },
508+
{ contestId: 'abc200', taskTableIndex: 'E', expected: 'ABC200 - E' },
509+
{ contestId: 'abc201', taskTableIndex: 'F', expected: 'ABC201 - F' },
510+
{ contestId: 'abc365', taskTableIndex: 'G', expected: 'ABC365 - G' },
511+
{ contestId: 'abc999', taskTableIndex: 'A', expected: 'ABC999 - A' },
512+
];
513+
514+
runTests(
515+
'addContestNameToTaskIndex',
516+
testCases,
517+
({ contestId, taskTableIndex, expected }: TestCaseForContestNameAndTaskIndex) => {
518+
expect(addContestNameToTaskIndex(contestId, taskTableIndex)).toEqual(expected);
519+
},
520+
);
521+
});
522+
523+
describe('when contest_id starts with APG4b', () => {
524+
const testCases = [
525+
{ contestId: 'APG4b', taskTableIndex: 'EX1', expected: 'APG4b - EX1' },
526+
{ contestId: 'APG4b', taskTableIndex: 'EX2', expected: 'APG4b - EX2' },
527+
{ contestId: 'APG4b', taskTableIndex: 'EX10', expected: 'APG4b - EX10' },
528+
{ contestId: 'APG4bPython', taskTableIndex: 'EX1', expected: 'APG4bPython - EX1' },
529+
];
530+
531+
runTests(
532+
'addContestNameToTaskIndex',
533+
testCases,
534+
({ contestId, taskTableIndex, expected }: TestCaseForContestNameAndTaskIndex) => {
535+
expect(addContestNameToTaskIndex(contestId, taskTableIndex)).toEqual(expected);
536+
},
537+
);
538+
});
539+
540+
describe('when contest_id is typical90', () => {
541+
const testCases = [
542+
{ contestId: 'typical90', taskTableIndex: '001', expected: '競プロ典型 90 問 - 001' },
543+
{ contestId: 'typical90', taskTableIndex: '002', expected: '競プロ典型 90 問 - 002' },
544+
{ contestId: 'typical90', taskTableIndex: '010', expected: '競プロ典型 90 問 - 010' },
545+
{ contestId: 'typical90', taskTableIndex: '090', expected: '競プロ典型 90 問 - 090' },
546+
];
547+
548+
runTests(
549+
'addContestNameToTaskIndex',
550+
testCases,
551+
({ contestId, taskTableIndex, expected }: TestCaseForContestNameAndTaskIndex) => {
552+
expect(addContestNameToTaskIndex(contestId, taskTableIndex)).toEqual(expected);
553+
},
554+
);
555+
});
556+
557+
describe('when contest_id is tessoku-book', () => {
558+
const testCases = [
559+
{
560+
contestId: 'tessoku-book',
561+
taskTableIndex: 'A01',
562+
expected: '競技プログラミングの鉄則 - A01',
563+
},
564+
{
565+
contestId: 'tessoku-book',
566+
taskTableIndex: 'A10',
567+
expected: '競技プログラミングの鉄則 - A10',
568+
},
569+
{
570+
contestId: 'tessoku-book',
571+
taskTableIndex: 'A77',
572+
expected: '競技プログラミングの鉄則 - A77',
573+
},
574+
{
575+
contestId: 'tessoku-book',
576+
taskTableIndex: 'B01',
577+
expected: '競技プログラミングの鉄則 - B01',
578+
},
579+
{
580+
contestId: 'tessoku-book',
581+
taskTableIndex: 'B10',
582+
expected: '競技プログラミングの鉄則 - B10',
583+
},
584+
{
585+
contestId: 'tessoku-book',
586+
taskTableIndex: 'B69',
587+
expected: '競技プログラミングの鉄則 - B69',
588+
},
589+
{
590+
contestId: 'tessoku-book',
591+
taskTableIndex: 'C01',
592+
expected: '競技プログラミングの鉄則 - C01',
593+
},
594+
{
595+
contestId: 'tessoku-book',
596+
taskTableIndex: 'C10',
597+
expected: '競技プログラミングの鉄則 - C10',
598+
},
599+
{
600+
contestId: 'tessoku-book',
601+
taskTableIndex: 'C20',
602+
expected: '競技プログラミングの鉄則 - C20',
603+
},
604+
];
605+
606+
runTests(
607+
'addContestNameToTaskIndex',
608+
testCases,
609+
({ contestId, taskTableIndex, expected }: TestCaseForContestNameAndTaskIndex) => {
610+
expect(addContestNameToTaskIndex(contestId, taskTableIndex)).toEqual(expected);
611+
},
612+
);
613+
});
614+
615+
describe('when contest_id is math-and-algorithm', () => {
616+
const testCases = [
617+
{
618+
contestId: 'math-and-algorithm',
619+
taskTableIndex: '001',
620+
expected: 'アルゴリズムと数学 - 001',
621+
},
622+
{
623+
contestId: 'math-and-algorithm',
624+
taskTableIndex: '002',
625+
expected: 'アルゴリズムと数学 - 002',
626+
},
627+
{
628+
contestId: 'math-and-algorithm',
629+
taskTableIndex: '010',
630+
expected: 'アルゴリズムと数学 - 010',
631+
},
632+
{
633+
contestId: 'math-and-algorithm',
634+
taskTableIndex: '099',
635+
expected: 'アルゴリズムと数学 - 099',
636+
},
637+
{
638+
contestId: 'math-and-algorithm',
639+
taskTableIndex: '100',
640+
expected: 'アルゴリズムと数学 - 100',
641+
},
642+
{
643+
contestId: 'math-and-algorithm',
644+
taskTableIndex: '104',
645+
expected: 'アルゴリズムと数学 - 104',
646+
},
647+
];
648+
649+
runTests(
650+
'addContestNameToTaskIndex',
651+
testCases,
652+
({ contestId, taskTableIndex, expected }: TestCaseForContestNameAndTaskIndex) => {
653+
expect(addContestNameToTaskIndex(contestId, taskTableIndex)).toEqual(expected);
654+
},
655+
);
656+
});
657+
658+
describe('when contest_id contains arc', () => {
659+
const testCases = [
660+
{ contestId: 'arc001', taskTableIndex: 'A', expected: 'ARC001 - A' },
661+
{ contestId: 'arc002', taskTableIndex: 'B', expected: 'ARC002 - B' },
662+
{ contestId: 'arc057', taskTableIndex: 'C', expected: 'ARC057 - C' },
663+
{ contestId: 'arc058', taskTableIndex: 'D', expected: 'ARC058 - D' },
664+
{ contestId: 'arc099', taskTableIndex: 'E', expected: 'ARC099 - E' },
665+
{ contestId: 'arc100', taskTableIndex: 'F', expected: 'ARC100 - F' },
666+
{ contestId: 'arc101', taskTableIndex: 'C', expected: 'ARC101 - C' },
667+
{ contestId: 'arc103', taskTableIndex: 'D', expected: 'ARC103 - D' },
668+
{ contestId: 'arc104', taskTableIndex: 'A', expected: 'ARC104 - A' },
669+
{ contestId: 'arc105', taskTableIndex: 'B', expected: 'ARC105 - B' },
670+
{ contestId: 'arc182', taskTableIndex: 'C', expected: 'ARC182 - C' },
671+
{ contestId: 'arc183', taskTableIndex: 'D', expected: 'ARC183 - D' },
672+
];
673+
674+
runTests(
675+
'addContestNameToTaskIndex',
676+
testCases,
677+
({ contestId, taskTableIndex, expected }: TestCaseForContestNameAndTaskIndex) => {
678+
expect(addContestNameToTaskIndex(contestId, taskTableIndex)).toEqual(expected);
679+
},
680+
);
681+
});
682+
683+
function runTests(
684+
testName: string,
685+
testCases: TestCasesForContestNameAndTaskIndex,
686+
testFunction: (testCase: TestCaseForContestNameAndTaskIndex) => void,
687+
) {
688+
test.each(testCases)(
689+
`${testName}(contestId: $contestId, taskTableIndex: $taskTableIndex)`,
690+
testFunction,
691+
);
692+
}
693+
});
487694
});

0 commit comments

Comments
 (0)