|
6 | 6 | countAllTasks, |
7 | 7 | areAllTasksAccepted, |
8 | 8 | compareByContestIdAndTaskId, |
| 9 | + removeTaskIndexFromTitle, |
9 | 10 | } from '$lib/utils/task'; |
10 | 11 | import type { WorkBookTaskBase } from '$lib/types/workbook'; |
11 | 12 | import { type TaskResult, type TaskResults } from '$lib/types/task'; |
@@ -50,6 +51,14 @@ type TestCaseForSortingTaskResults = { |
50 | 51 |
|
51 | 52 | type TestCasesForSortingTaskResults = TestCaseForSortingTaskResults[]; |
52 | 53 |
|
| 54 | +type TestCaseForNewTitle = { |
| 55 | + title: string; |
| 56 | + taskTableIndex: string; |
| 57 | + expected: string; |
| 58 | +}; |
| 59 | + |
| 60 | +type TestCasesForNewTitle = TestCaseForNewTitle[]; |
| 61 | + |
53 | 62 | describe('Task', () => { |
54 | 63 | describe('task url', () => { |
55 | 64 | describe('when contest ids and task ids in AtCoder are given', () => { |
@@ -567,4 +576,112 @@ describe('Task', () => { |
567 | 576 | ); |
568 | 577 | } |
569 | 578 | }); |
| 579 | + |
| 580 | + describe('remove task index from title', () => { |
| 581 | + describe('when ABC371 is given', () => { |
| 582 | + const testCases: TestCasesForNewTitle = [ |
| 583 | + { |
| 584 | + title: 'A. Jiro', |
| 585 | + taskTableIndex: 'A', |
| 586 | + expected: 'Jiro', |
| 587 | + }, |
| 588 | + { |
| 589 | + title: 'B. Taro', |
| 590 | + taskTableIndex: 'B', |
| 591 | + expected: 'Taro', |
| 592 | + }, |
| 593 | + { |
| 594 | + title: 'C. Make Isomorphic', |
| 595 | + taskTableIndex: 'C', |
| 596 | + expected: 'Make Isomorphic', |
| 597 | + }, |
| 598 | + { |
| 599 | + title: 'D. 1D Country', |
| 600 | + taskTableIndex: 'D', |
| 601 | + expected: '1D Country', |
| 602 | + }, |
| 603 | + { |
| 604 | + title: 'E. I Hate Sigma Problems', |
| 605 | + taskTableIndex: 'E', |
| 606 | + expected: 'I Hate Sigma Problems', |
| 607 | + }, |
| 608 | + { |
| 609 | + title: 'F. Takahashi in Narrow Road', |
| 610 | + taskTableIndex: 'F', |
| 611 | + expected: 'Takahashi in Narrow Road', |
| 612 | + }, |
| 613 | + { |
| 614 | + title: 'G. Lexicographically Smallest Permutation', |
| 615 | + taskTableIndex: 'G', |
| 616 | + expected: 'Lexicographically Smallest Permutation', |
| 617 | + }, |
| 618 | + ]; |
| 619 | + |
| 620 | + runTests( |
| 621 | + 'removeTaskIndexFromTitle', |
| 622 | + testCases, |
| 623 | + ({ title, taskTableIndex, expected }: TestCaseForNewTitle) => { |
| 624 | + expect(removeTaskIndexFromTitle(title, taskTableIndex)).toBe(expected); |
| 625 | + }, |
| 626 | + ); |
| 627 | + }); |
| 628 | + |
| 629 | + describe('when APG4b is given', () => { |
| 630 | + const testCases: TestCasesForNewTitle = [ |
| 631 | + { |
| 632 | + title: 'EX1. 1.01', |
| 633 | + taskTableIndex: 'EX1', |
| 634 | + expected: '1.01', |
| 635 | + }, |
| 636 | + { |
| 637 | + title: 'EX2. 1.02', |
| 638 | + taskTableIndex: 'EX2', |
| 639 | + expected: '1.02', |
| 640 | + }, |
| 641 | + { |
| 642 | + title: 'EX9. 1.09', |
| 643 | + taskTableIndex: 'EX9', |
| 644 | + expected: '1.09', |
| 645 | + }, |
| 646 | + { |
| 647 | + title: 'EX10. 1.10', |
| 648 | + taskTableIndex: 'EX10', |
| 649 | + expected: '1.10', |
| 650 | + }, |
| 651 | + { |
| 652 | + title: 'EX16. 2.01', |
| 653 | + taskTableIndex: 'EX16', |
| 654 | + expected: '2.01', |
| 655 | + }, |
| 656 | + { |
| 657 | + title: 'EX21. 2.06', |
| 658 | + taskTableIndex: 'EX21', |
| 659 | + expected: '2.06', |
| 660 | + }, |
| 661 | + { |
| 662 | + title: 'EX26. 3.06', |
| 663 | + taskTableIndex: 'EX26', |
| 664 | + expected: '3.06', |
| 665 | + }, |
| 666 | + ]; |
| 667 | + runTests( |
| 668 | + 'removeTaskIndexFromTitle', |
| 669 | + testCases, |
| 670 | + ({ title, taskTableIndex, expected }: TestCaseForNewTitle) => { |
| 671 | + expect(removeTaskIndexFromTitle(title, taskTableIndex)).toBe(expected); |
| 672 | + }, |
| 673 | + ); |
| 674 | + }); |
| 675 | + |
| 676 | + function runTests( |
| 677 | + testName: string, |
| 678 | + testCases: TestCasesForNewTitle, |
| 679 | + testFunction: (testCase: TestCaseForNewTitle) => void, |
| 680 | + ) { |
| 681 | + test.each(testCases)( |
| 682 | + `${testName}(title: $title, taskTableIndex: $taskTableIndex)`, |
| 683 | + testFunction, |
| 684 | + ); |
| 685 | + } |
| 686 | + }); |
570 | 687 | }); |
0 commit comments