Skip to content

Commit f9ad24a

Browse files
committed
feat: add more test cases for clone graph
1 parent 7a87496 commit f9ad24a

File tree

5 files changed

+92
-4
lines changed

5 files changed

+92
-4
lines changed

.amazonq/rules/test-case-enhancement.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ When user requests to enhance test cases for a problem, the assistant will:
5252
- **CRITICAL**: Remove entire newly generated `leetcode/{problem_name}/` directory
5353
- **CRITICAL**: Restore original structure from `.cache/leetcode/{problem_name}/` backup
5454
- **CRITICAL**: Only THEN copy enhanced `test_solution.py` from generated files to restored structure
55+
- **CRITICAL**: Preserve existing solution class parametrization - if original test had multiple solution classes, restore them
5556
- Verify final state with `make p-test PROBLEM={problem_name}`
5657
- Clean up backup directory after successful verification
5758

@@ -94,6 +95,7 @@ When user requests to enhance test cases for a problem, the assistant will:
9495
- Maintain type hints in parametrize_typed
9596
- Ensure test_cases string is valid Python list syntax
9697
- **NEVER include custom solution classes** in test_imports - only import the main solution class specified in solution_class_name
98+
- **PRESERVE existing solution class parametrization** - if original test had multiple solution classes, restore them after JSON regeneration
9799

98100
## Commands Reference
99101

.templates/leetcode/json/clone_graph.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@
5555
"name": "test_clone_graph",
5656
"signature": "(self, adj_list: list[list[int]])",
5757
"parametrize": "adj_list",
58-
"test_cases": "[[[2, 4], [1, 3], [2, 4], [1, 3]], [[]], []]",
58+
"test_cases": "[[[2, 4], [1, 3], [2, 4], [1, 3]], [[]], [], [[2], [1]], [[2, 3], [1], [1]], [[2], [3], [4], []], [[2, 3, 4], [1], [1], [1]], [[2, 3], [1, 3], [1, 2]], [[2, 5], [1, 3], [2, 4], [3, 5], [1, 4]], [[2, 3], [1, 4], [1, 4], [2, 3]], [[2, 3, 4, 5], [1], [1], [1], [1]], [[2], [3], [4], [5], []]]",
5959
"body": " result = run_clone_graph(Solution, adj_list)\n assert_clone_graph(result, adj_list)"
6060
}
6161
]

.templates/leetcode/json/time_based_key_value_store.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@
5757
"name": "test_time_map_operations",
5858
"signature": "(self, operations: list[str], inputs: list[list], expected: list)",
5959
"parametrize": "operations, inputs, expected",
60-
"test_cases": "[(['TimeMap', 'set', 'get', 'get', 'set', 'get', 'get'], [[], ['foo', 'bar', 1], ['foo', 1], ['foo', 3], ['foo', 'bar2', 4], ['foo', 4], ['foo', 5]], [None, None, 'bar', 'bar', None, 'bar2', 'bar2'])]",
60+
"test_cases": "[(['TimeMap', 'set', 'get', 'get', 'set', 'get', 'get'], [[], ['foo', 'bar', 1], ['foo', 1], ['foo', 3], ['foo', 'bar2', 4], ['foo', 4], ['foo', 5]], [None, None, 'bar', 'bar', None, 'bar2', 'bar2']), (['TimeMap', 'get'], [[], ['key', 1]], [None, '']), (['TimeMap', 'set', 'get'], [[], ['a', 'val', 1], ['a', 1]], [None, None, 'val']), (['TimeMap', 'set', 'get', 'get'], [[], ['key', 'value', 5], ['key', 3], ['key', 7]], [None, None, '', 'value']), (['TimeMap', 'set', 'set', 'get', 'get', 'get'], [[], ['x', 'v1', 1], ['x', 'v2', 2], ['x', 1], ['x', 2], ['x', 3]], [None, None, None, 'v1', 'v2', 'v2']), (['TimeMap', 'set', 'set', 'set', 'get', 'get', 'get'], [[], ['k', 'a', 10], ['k', 'b', 20], ['k', 'c', 30], ['k', 15], ['k', 25], ['k', 35]], [None, None, None, None, 'a', 'b', 'c']), (['TimeMap', 'set', 'set', 'get', 'get'], [[], ['key1', 'val1', 1], ['key2', 'val2', 2], ['key1', 1], ['key2', 2]], [None, None, None, 'val1', 'val2']), (['TimeMap', 'set', 'set', 'set', 'get', 'get', 'get'], [[], ['a', 'x', 1], ['b', 'y', 2], ['c', 'z', 3], ['a', 1], ['b', 2], ['c', 3]], [None, None, None, None, 'x', 'y', 'z']), (['TimeMap', 'set', 'get', 'set', 'get', 'set', 'get'], [[], ['test', 'first', 1], ['test', 1], ['test', 'second', 100], ['test', 50], ['test', 'third', 1000], ['test', 500]], [None, None, 'first', None, 'first', None, 'second']), (['TimeMap', 'set', 'set', 'set', 'set', 'get'], [[], ['data', 'v1', 1], ['data', 'v2', 10], ['data', 'v3', 100], ['data', 'v4', 1000], ['data', 555]], [None, None, None, None, None, 'v3']), (['TimeMap', 'set', 'get', 'get', 'get'], [[], ['single', 'value', 42], ['single', 1], ['single', 42], ['single', 100]], [None, None, '', 'value', 'value']), (['TimeMap', 'set', 'set', 'get', 'get', 'get', 'get'], [[], ['boundary', 'min', 1], ['boundary', 'max', 10000000], ['boundary', 0], ['boundary', 1], ['boundary', 5000000], ['boundary', 10000000]], [None, None, None, '', 'min', 'min', 'max'])]",
6161
"body": " result = run_time_map_operations(TimeMap, operations, inputs)\n assert_time_map_operations(result, expected)"
6262
}
6363
]

leetcode/clone_graph/test_solution.py

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,23 @@ def setup_method(self):
1212

1313
@logged_test
1414
@pytest.mark.parametrize("solution_class", [Solution, SolutionBFS, SolutionDFS])
15-
@pytest.mark.parametrize("adj_list", [[[2, 4], [1, 3], [2, 4], [1, 3]], [[]], []])
15+
@pytest.mark.parametrize(
16+
"adj_list",
17+
[
18+
[[2, 4], [1, 3], [2, 4], [1, 3]],
19+
[[]],
20+
[],
21+
[[2], [1]],
22+
[[2, 3], [1], [1]],
23+
[[2], [3], [4], []],
24+
[[2, 3, 4], [1], [1], [1]],
25+
[[2, 3], [1, 3], [1, 2]],
26+
[[2, 5], [1, 3], [2, 4], [3, 5], [1, 4]],
27+
[[2, 3], [1, 4], [1, 4], [2, 3]],
28+
[[2, 3, 4, 5], [1], [1], [1], [1]],
29+
[[2], [3], [4], [5], []],
30+
],
31+
)
1632
def test_clone_graph(self, solution_class: type, adj_list: list[list[int]]):
1733
result = run_clone_graph(solution_class, adj_list)
1834
assert_clone_graph(result, adj_list)

leetcode/time_based_key_value_store/test_solution.py

Lines changed: 71 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,77 @@ class TestTimeBasedKeyValueStore:
2424
["foo", 5],
2525
],
2626
[None, None, "bar", "bar", None, "bar2", "bar2"],
27-
)
27+
),
28+
(["TimeMap", "get"], [[], ["key", 1]], [None, ""]),
29+
(["TimeMap", "set", "get"], [[], ["a", "val", 1], ["a", 1]], [None, None, "val"]),
30+
(
31+
["TimeMap", "set", "get", "get"],
32+
[[], ["key", "value", 5], ["key", 3], ["key", 7]],
33+
[None, None, "", "value"],
34+
),
35+
(
36+
["TimeMap", "set", "set", "get", "get", "get"],
37+
[[], ["x", "v1", 1], ["x", "v2", 2], ["x", 1], ["x", 2], ["x", 3]],
38+
[None, None, None, "v1", "v2", "v2"],
39+
),
40+
(
41+
["TimeMap", "set", "set", "set", "get", "get", "get"],
42+
[[], ["k", "a", 10], ["k", "b", 20], ["k", "c", 30], ["k", 15], ["k", 25], ["k", 35]],
43+
[None, None, None, None, "a", "b", "c"],
44+
),
45+
(
46+
["TimeMap", "set", "set", "get", "get"],
47+
[[], ["key1", "val1", 1], ["key2", "val2", 2], ["key1", 1], ["key2", 2]],
48+
[None, None, None, "val1", "val2"],
49+
),
50+
(
51+
["TimeMap", "set", "set", "set", "get", "get", "get"],
52+
[[], ["a", "x", 1], ["b", "y", 2], ["c", "z", 3], ["a", 1], ["b", 2], ["c", 3]],
53+
[None, None, None, None, "x", "y", "z"],
54+
),
55+
(
56+
["TimeMap", "set", "get", "set", "get", "set", "get"],
57+
[
58+
[],
59+
["test", "first", 1],
60+
["test", 1],
61+
["test", "second", 100],
62+
["test", 50],
63+
["test", "third", 1000],
64+
["test", 500],
65+
],
66+
[None, None, "first", None, "first", None, "second"],
67+
),
68+
(
69+
["TimeMap", "set", "set", "set", "set", "get"],
70+
[
71+
[],
72+
["data", "v1", 1],
73+
["data", "v2", 10],
74+
["data", "v3", 100],
75+
["data", "v4", 1000],
76+
["data", 555],
77+
],
78+
[None, None, None, None, None, "v3"],
79+
),
80+
(
81+
["TimeMap", "set", "get", "get", "get"],
82+
[[], ["single", "value", 42], ["single", 1], ["single", 42], ["single", 100]],
83+
[None, None, "", "value", "value"],
84+
),
85+
(
86+
["TimeMap", "set", "set", "get", "get", "get", "get"],
87+
[
88+
[],
89+
["boundary", "min", 1],
90+
["boundary", "max", 10000000],
91+
["boundary", 0],
92+
["boundary", 1],
93+
["boundary", 5000000],
94+
["boundary", 10000000],
95+
],
96+
[None, None, None, "", "min", "min", "max"],
97+
),
2898
],
2999
)
30100
def test_time_map_operations(self, operations: list[str], inputs: list[list], expected: list):

0 commit comments

Comments
 (0)