Skip to content

Commit 1b6dbde

Browse files
committed
test: add more test cases
1 parent 9badf3d commit 1b6dbde

File tree

31 files changed

+370
-30
lines changed

31 files changed

+370
-30
lines changed

.amazonq/rules/development-rules.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,5 +24,7 @@ Each problem has:
2424

2525
- `README.md` - Problem description
2626
- `solution.py` - Implementation with TODO placeholder
27-
- `tests.py` - Parametrized pytest tests
27+
- `test_solution.py` - Parametrized pytest tests
28+
- `helpers.py` - Test helper functions
29+
- `playground.ipynb` - Interactive Jupyter notebook
2830
- `__init__.py` - Empty package file

.templates/leetcode/json/combination_sum.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@
5353
"name": "test_combination_sum",
5454
"signature": "(self, candidates: list[int], target: int, expected: list[list[int]])",
5555
"parametrize": "candidates, target, expected",
56-
"test_cases": "[([2, 3, 6, 7], 7, [[2, 2, 3], [7]]), ([2, 3, 5], 8, [[2, 2, 2, 2], [2, 3, 3], [3, 5]]), ([2], 1, [])]",
56+
"test_cases": "[([2, 3, 6, 7], 7, [[2, 2, 3], [7]]), ([2, 3, 5], 8, [[2, 2, 2, 2], [2, 3, 3], [3, 5]]), ([2], 1, []), ([2, 3], 1, []), ([3, 5], 3, [[3]]), ([2, 4], 6, [[2, 2, 2], [2, 4]]), ([5], 5, [[5]]), ([2, 3, 4], 6, [[2, 2, 2], [2, 4], [3, 3]]), ([4, 2, 8], 8, [[2, 2, 2, 2], [2, 2, 4], [4, 4], [8]]), ([3, 4, 5], 9, [[3, 3, 3], [4, 5]]), ([6, 3, 2], 6, [[2, 2, 2], [3, 3], [6]]), ([2, 7], 9, [[2, 7]])]",
5757
"body": " result = run_combination_sum(Solution, candidates, target)\n assert_combination_sum(result, expected)"
5858
}
5959
]

.templates/leetcode/json/container_with_most_water.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050
"name": "test_max_area",
5151
"signature": "(self, height: list[int], expected: int)",
5252
"parametrize": "height, expected",
53-
"test_cases": "[([1,8,6,2,5,4,8,3,7], 49), ([1,1], 1), ([1,2,1], 2)]",
53+
"test_cases": "[([1,8,6,2,5,4,8,3,7], 49), ([1,1], 1), ([1,2,1], 2), ([2,1], 1), ([1,2,4,3], 4), ([1,3,2,5,25,24,5], 24), ([2,3,4,5,18,17,6], 17), ([1,2,3,4,5], 6), ([5,4,3,2,1], 6), ([0,2], 0), ([3,9,3,4,7,2,12,6], 45), ([1,0,0,0,0,0,0,2,2], 8)]",
5454
"body": " result = run_max_area(Solution, height)\n assert_max_area(result, expected)"
5555
}
5656
]

.templates/leetcode/json/contains_duplicate.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@
5353
"name": "test_contains_duplicate",
5454
"signature": "(self, nums: list[int], expected: bool)",
5555
"parametrize": "nums, expected",
56-
"test_cases": "[([1, 2, 3, 1], True), ([1, 2, 3, 4], False), ([1, 1, 1, 3, 3, 4, 3, 2, 4, 2], True)]",
56+
"test_cases": "[([1, 2, 3, 1], True), ([1, 2, 3, 4], False), ([1, 1, 1, 3, 3, 4, 3, 2, 4, 2], True), ([1], False), ([1, 1], True), ([0, 0], True), ([-1, -1], True), ([1, 2, 3, 4, 5, 6, 7, 8, 9, 10], False), ([10, 9, 8, 7, 6, 5, 4, 3, 2, 1], False), ([1, 2, 3, 4, 5, 1], True), ([-1000000000, 1000000000, -1000000000], True), ([0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0], True)]",
5757
"body": " result = run_contains_duplicate(Solution, nums)\n assert_contains_duplicate(result, expected)"
5858
}
5959
]

.templates/leetcode/json/course_schedule.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@
5252
"name": "test_can_finish",
5353
"signature": "(self, num_courses: int, prerequisites: list[list[int]], expected: bool)",
5454
"parametrize": "num_courses, prerequisites, expected",
55-
"test_cases": "[(2, [[1, 0]], True), (2, [[1, 0], [0, 1]], False), (1, [], True), (3, [[1, 0], [2, 1]], True), (4, [[1, 0], [2, 1], [3, 2], [1, 3]], False)]",
55+
"test_cases": "[(2, [[1, 0]], True), (2, [[1, 0], [0, 1]], False), (1, [], True), (3, [[1, 0], [2, 1]], True), (4, [[1, 0], [2, 1], [3, 2], [1, 3]], False), (3, [[0, 1], [0, 2], [1, 2]], True), (4, [[0, 1], [1, 2], [2, 3], [3, 1]], False), (6, [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5]], True), (3, [[1, 0], [2, 0]], True), (5, [[0, 1], [1, 2], [2, 3], [3, 4], [4, 0]], False), (4, [[1, 0], [2, 0], [3, 1], [3, 2]], True), (5, [[1, 0], [2, 1], [3, 2], [4, 3], [0, 4]], False)]",
5656
"body": " result = run_can_finish(Solution, num_courses, prerequisites)\n assert_can_finish(result, expected)"
5757
}
5858
]

.templates/leetcode/json/evaluate_reverse_polish_notation.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@
5555
"name": "test_eval_rpn",
5656
"signature": "(self, tokens: list[str], expected: int)",
5757
"parametrize": "tokens, expected",
58-
"test_cases": "[(['2', '1', '+', '3', '*'], 9), (['4', '13', '5', '/', '+'], 6), (['10', '6', '9', '3', '+', '-11', '*', '/', '*', '17', '+', '5', '+'], 22)]",
58+
"test_cases": "[(['2', '1', '+', '3', '*'], 9), (['4', '13', '5', '/', '+'], 6), (['10', '6', '9', '3', '+', '-11', '*', '/', '*', '17', '+', '5', '+'], 22), (['3'], 3), (['15', '7', '1', '1', '+', '-', '/', '3', '*', '2', '1', '1', '+', '+', '-'], 5), (['2', '1', '+'], 3), (['2', '1', '-'], 1), (['3', '4', '*'], 12), (['8', '2', '/'], 4), (['5', '1', '2', '+', '4', '*', '+', '3', '-'], 14), (['-1', '2', '+'], 1), (['0', '3', '/'], 0), (['18', '6', '/', '3', '/'], 1)]",
5959
"body": " result = run_eval_rpn(Solution, tokens)\n assert_eval_rpn(result, expected)"
6060
}
6161
]

.templates/leetcode/json/flood_fill.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@
5252
"name": "test_flood_fill",
5353
"signature": "(self, image: list[list[int]], sr: int, sc: int, color: int, expected: list[list[int]])",
5454
"parametrize": "image, sr, sc, color, expected",
55-
"test_cases": "[([[1, 1, 1], [1, 1, 0], [1, 0, 1]], 1, 1, 2, [[2, 2, 2], [2, 2, 0], [2, 0, 1]]), ([[0, 0, 0], [0, 0, 0]], 0, 0, 0, [[0, 0, 0], [0, 0, 0]]), ([[0, 0, 0], [0, 1, 1]], 1, 1, 1, [[0, 0, 0], [0, 1, 1]]), ([[1, 1, 1], [1, 1, 0], [1, 0, 1]], 1, 1, 1, [[1, 1, 1], [1, 1, 0], [1, 0, 1]])]",
55+
"test_cases": "[([[1, 1, 1], [1, 1, 0], [1, 0, 1]], 1, 1, 2, [[2, 2, 2], [2, 2, 0], [2, 0, 1]]), ([[0, 0, 0], [0, 0, 0]], 0, 0, 0, [[0, 0, 0], [0, 0, 0]]), ([[0, 0, 0], [0, 1, 1]], 1, 1, 1, [[0, 0, 0], [0, 1, 1]]), ([[1, 1, 1], [1, 1, 0], [1, 0, 1]], 1, 1, 1, [[1, 1, 1], [1, 1, 0], [1, 0, 1]]), ([[1]], 0, 0, 2, [[2]]), ([[0, 1], [1, 0]], 0, 0, 3, [[3, 1], [1, 0]]), ([[1, 1], [1, 1]], 0, 0, 2, [[2, 2], [2, 2]]), ([[0, 1, 0], [1, 0, 1], [0, 1, 0]], 1, 1, 2, [[0, 1, 0], [1, 2, 1], [0, 1, 0]]), ([[2, 2, 2], [2, 2, 0], [2, 0, 1]], 0, 0, 3, [[3, 3, 3], [3, 3, 0], [3, 0, 1]]), ([[1, 0, 1], [0, 1, 0], [1, 0, 1]], 1, 1, 5, [[1, 0, 1], [0, 5, 0], [1, 0, 1]]), ([[0, 0, 0, 0], [0, 1, 1, 0], [0, 1, 1, 0], [0, 0, 0, 0]], 1, 1, 2, [[0, 0, 0, 0], [0, 2, 2, 0], [0, 2, 2, 0], [0, 0, 0, 0]]), ([[1, 2, 3], [4, 5, 6], [7, 8, 9]], 1, 1, 0, [[1, 2, 3], [4, 0, 6], [7, 8, 9]])]",
5656
"body": " result = run_flood_fill(Solution, image, sr, sc, color)\n assert_flood_fill(result, expected)"
5757
}
5858
]

.templates/leetcode/json/implement_queue_using_stacks.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@
6767
"name": "test_queue_operations",
6868
"signature": "(self, operations: list[str], inputs: list[list[int]], expected: list[int | None | bool])",
6969
"parametrize": "operations, inputs, expected",
70-
"test_cases": "[(['MyQueue', 'push', 'push', 'peek', 'pop', 'empty'], [[], [1], [2], [], [], []], [None, None, None, 1, 1, False]), (['MyQueue', 'empty', 'push', 'peek', 'pop', 'empty'], [[], [], [1], [], [], []], [None, True, None, 1, 1, True]), (['MyQueue', 'push', 'push', 'push', 'pop', 'pop', 'peek', 'pop', 'empty'], [[], [1], [2], [3], [], [], [], [], []], [None, None, None, None, 1, 2, 3, 3, True])]",
70+
"test_cases": "[(['MyQueue', 'push', 'push', 'peek', 'pop', 'empty'], [[], [1], [2], [], [], []], [None, None, None, 1, 1, False]), (['MyQueue', 'empty', 'push', 'peek', 'pop', 'empty'], [[], [], [1], [], [], []], [None, True, None, 1, 1, True]), (['MyQueue', 'push', 'push', 'push', 'pop', 'pop', 'peek', 'pop', 'empty'], [[], [1], [2], [3], [], [], [], [], []], [None, None, None, None, 1, 2, 3, 3, True]), (['MyQueue', 'push', 'peek', 'pop'], [[], [5], [], []], [None, None, 5, 5]), (['MyQueue', 'push', 'push', 'pop', 'push', 'peek'], [[], [1], [2], [], [3], []], [None, None, None, 1, None, 2]), (['MyQueue', 'empty'], [[], []], [None, True]), (['MyQueue', 'push', 'push', 'push', 'push', 'pop', 'pop', 'pop', 'pop', 'empty'], [[], [1], [2], [3], [4], [], [], [], [], []], [None, None, None, None, None, 1, 2, 3, 4, True]), (['MyQueue', 'push', 'pop', 'push', 'pop', 'empty'], [[], [7], [], [8], [], []], [None, None, 7, None, 8, True]), (['MyQueue', 'push', 'push', 'peek', 'peek', 'pop', 'peek'], [[], [9], [8], [], [], [], []], [None, None, None, 9, 9, 9, 8]), (['MyQueue', 'push', 'push', 'push', 'push', 'push', 'pop', 'pop', 'pop', 'push', 'peek'], [[], [1], [2], [3], [4], [5], [], [], [], [6], []], [None, None, None, None, None, None, 1, 2, 3, None, 4]), (['MyQueue', 'push', 'empty', 'pop', 'empty', 'push', 'empty'], [[], [1], [], [], [], [2], []], [None, None, False, 1, True, None, False]), (['MyQueue', 'push', 'push', 'push', 'pop', 'push', 'pop', 'pop', 'push', 'pop'], [[], [1], [2], [3], [], [4], [], [], [5], []], [None, None, None, None, 1, None, 2, 3, None, 4])]",
7171
"body": " result, _ = run_my_queue(MyQueue, operations, inputs)\n assert_my_queue(result, expected)"
7272
}
7373
]

.templates/leetcode/json/implement_trie_prefix_tree.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
"helpers_content": "",
2121
"helpers_run_name": "trie_operations",
2222
"helpers_run_signature": "(solution_class: type, operations: list[str], inputs: list[list[str]])",
23-
"helpers_run_body": " trie = None\n results: list[bool | None] = []\n for i, op in enumerate(operations):\n if op == 'Trie':\n trie = solution_class()\n results.append(None)\n elif op == 'insert' and trie is not None:\n trie.insert(inputs[i][0])\n results.append(None)\n elif op == 'search' and trie is not None:\n results.append(trie.search(inputs[i][0]))\n elif op == 'starts_with' and trie is not None:\n results.append(trie.starts_with(inputs[i][0]))\n return results, trie",
23+
"helpers_run_body": " trie = None\n results: list[bool | None] = []\n for i, op in enumerate(operations):\n if op == 'Trie':\n trie = solution_class()\n results.append(None)\n elif op == 'insert' and trie is not None:\n trie.insert(inputs[i][0])\n results.append(None)\n elif op == 'search' and trie is not None:\n results.append(trie.search(inputs[i][0]))\n elif op == 'starts_with' and trie is not None:\n results.append(trie.starts_with(inputs[i][0]))\n elif op == 'startsWith' and trie is not None:\n results.append(trie.starts_with(inputs[i][0]))\n return results, trie",
2424
"helpers_assert_name": "trie_operations",
2525
"helpers_assert_signature": "(result: list[bool | None], expected: list[bool | None]) -> bool",
2626
"helpers_assert_body": " assert result == expected\n return True",
@@ -62,7 +62,7 @@
6262
"name": "test_trie_operations",
6363
"signature": "(self, operations: list[str], inputs: list[list[str]], expected: list[bool | None])",
6464
"parametrize": "operations, inputs, expected",
65-
"test_cases": "[(['Trie', 'insert', 'search', 'search', 'starts_with', 'insert', 'search'], [[], ['apple'], ['apple'], ['app'], ['app'], ['app'], ['app']], [None, None, True, False, True, None, True]), (['Trie', 'insert', 'insert', 'search', 'search', 'starts_with', 'starts_with'], [[], ['hello'], ['world'], ['hello'], ['hi'], ['hel'], ['wor']], [None, None, None, True, False, True, True]), (['Trie', 'insert', 'insert', 'search', 'search', 'starts_with', 'starts_with'], [[], ['a'], ['aa'], ['a'], ['aa'], ['a'], ['aa']], [None, None, None, True, True, True, True]), (['Trie', 'insert', 'search', 'starts_with', 'insert', 'search', 'starts_with'], [[], ['test'], ['testing'], ['test'], ['testing'], ['testing'], ['test']], [None, None, False, True, None, True, True]), (['Trie', 'search', 'starts_with'], [[], ['empty'], ['empty']], [None, False, False])]",
65+
"test_cases": "[([\"Trie\", \"insert\", \"insert\", \"search\", \"search\", \"search\"], [[], [\"app\"], [\"apple\"], [\"app\"], [\"apple\"], [\"appl\"]], [None, None, None, True, True, False]), ([\"Trie\", \"insert\", \"insert\", \"insert\", \"search\", \"search\", \"search\"], [[], [\"cat\"], [\"car\"], [\"card\"], [\"cat\"], [\"car\"], [\"care\"]], [None, None, None, None, True, True, False]), ([\"Trie\", \"insert\", \"insert\", \"starts_with\", \"starts_with\", \"starts_with\"], [[], [\"test\"], [\"testing\"], [\"test\"], [\"testing\"], [\"te\"]], [None, None, None, True, True, True]), ([\"Trie\", \"insert\", \"search\", \"search\", \"insert\", \"search\", \"search\"], [[], [\"abc\"], [\"abc\"], [\"ab\"], [\"ab\"], [\"ab\"], [\"abc\"]], [None, None, True, False, None, True, True]), ([\"Trie\", \"insert\", \"search\", \"starts_with\"], [[], [\"a\"], [\"a\"], [\"a\"]], [None, None, True, True]), ([\"Trie\", \"search\", \"starts_with\"], [[], [\"empty\"], [\"empty\"]], [None, False, False]), ([\"Trie\", \"insert\", \"insert\", \"search\", \"search\", \"starts_with\", \"starts_with\"], [[], [\"word\"], [\"world\"], [\"word\"], [\"world\"], [\"wor\"], [\"wo\"]], [None, None, None, True, True, True, True]), ([\"Trie\", \"insert\", \"insert\", \"insert\", \"search\", \"search\", \"search\", \"starts_with\"], [[], [\"aa\"], [\"aaa\"], [\"aaaa\"], [\"aa\"], [\"aaa\"], [\"aaaa\"], [\"a\"]], [None, None, None, None, True, True, True, True]), ([\"Trie\", \"insert\", \"search\", \"search\", \"starts_with\", \"starts_with\"], [[], [\"hello\"], [\"hello\"], [\"hell\"], [\"hello\"], [\"hel\"]], [None, None, True, False, True, True]), ([\"Trie\", \"insert\", \"insert\", \"insert\", \"search\", \"search\", \"search\", \"starts_with\", \"starts_with\"], [[], [\"she\"], [\"sells\"], [\"sea\"], [\"she\"], [\"shells\"], [\"sea\"], [\"se\"], [\"s\"]], [None, None, None, None, True, False, True, True, True]), ([\"Trie\", \"insert\", \"insert\", \"search\", \"search\", \"starts_with\", \"starts_with\", \"starts_with\"], [[], [\"programming\"], [\"program\"], [\"programming\"], [\"program\"], [\"prog\"], [\"programming\"], [\"programm\"]], [None, None, None, True, True, True, True, True]), ([\"Trie\", \"insert\", \"search\", \"starts_with\", \"insert\", \"search\", \"starts_with\"], [[], [\"z\"], [\"z\"], [\"z\"], [\"zzz\"], [\"zzz\"], [\"zz\"]], [None, None, True, True, None, True, True])]",
6666
"body": " result, _ = run_trie_operations(Trie, operations, inputs)\n assert_trie_operations(result, expected)"
6767
}
6868
]

.templates/leetcode/json/maximum_profit_in_job_scheduling.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@
5555
"name": "test_job_scheduling",
5656
"signature": "(self, start_time: list[int], end_time: list[int], profit: list[int], expected: int)",
5757
"parametrize": "start_time, end_time, profit, expected",
58-
"test_cases": "[([1, 2, 3, 3], [3, 4, 5, 6], [50, 10, 40, 70], 120), ([1, 2, 3, 4, 6], [3, 5, 10, 6, 9], [20, 20, 100, 70, 60], 150), ([1, 1, 1], [2, 3, 4], [5, 6, 4], 6), ([1], [2], [100], 100)]",
58+
"test_cases": "[([1, 2, 3, 3], [3, 4, 5, 6], [50, 10, 40, 70], 120), ([1, 2, 3, 4, 6], [3, 5, 10, 6, 9], [20, 20, 100, 70, 60], 150), ([1, 1, 1], [2, 3, 4], [5, 6, 4], 6), ([1, 2], [2, 3], [100, 200], 300), ([6, 15, 7, 11, 1, 3, 16, 2], [19, 18, 19, 16, 10, 8, 19, 8], [2, 9, 1, 19, 5, 7, 3, 19], 41)]",
5959
"body": " result = run_job_scheduling(Solution, start_time, end_time, profit)\n assert_job_scheduling(result, expected)"
6060
}
6161
]

0 commit comments

Comments
 (0)