@@ -50,6 +50,12 @@ Required fields for `leetcode_py/cli/resources/leetcode/json/problems/{problem_n
50
50
- ` playground_assertion ` : Use single quotes for string literals
51
51
- Double quotes in JSON + cookiecutter + Jupyter notebook = triple escaping issues
52
52
53
+ ** Test Cases Format:**
54
+
55
+ - ` test_cases ` : Use structured format with ` {"list": ["..."]} ` instead of string arrays
56
+ - Each test case should be a string representation of the tuple/parameters
57
+ - Example: ` {"list": ["('input1', 'input2', expected)", "('input3', 'input4', expected)"]} `
58
+
53
59
** IMPORTANT: Create actual JSON files, not JSON5**
54
60
55
61
The template below uses JSON5 format with comments for documentation purposes only. When creating the actual ` .json ` file, you must:
@@ -183,9 +189,30 @@ The template below uses JSON5 format with comments for documentation purposes on
183
189
parametrize: " s, t, expected" , // pytest parametrize parameters
184
190
// For tree: "root_list, expected_list"
185
191
// For design: "operations, inputs, expected"
186
- test_cases: " [('anagram', 'nagaram', True), ('rat', 'car', False), ('listen', 'silent', True), ('hello', 'bello', False), ('', '', True), ('a', 'a', True), ('a', 'b', False), ('ab', 'ba', True), ('abc', 'bca', True), ('abc', 'def', False), ('aab', 'abb', False), ('aabbcc', 'abcabc', True), ('abcd', 'abcde', False), ('race', 'care', True), ('elbow', 'below', True), ('study', 'dusty', True), ('night', 'thing', True), ('stressed', 'desserts', True)]" ,
187
- // For tree: "[([4, 2, 7, 1, 3, 6, 9], [4, 7, 2, 9, 6, 3, 1]), ([2, 1, 3], [2, 3, 1]), ([], [])]"
188
- // For design: "[(['LRUCache', 'put', 'get'], [[2], [1, 1], [1]], [None, None, 1])]"
192
+ test_cases: {
193
+ list: [
194
+ " ('anagram', 'nagaram', True)" ,
195
+ " ('rat', 'car', False)" ,
196
+ " ('listen', 'silent', True)" ,
197
+ " ('hello', 'bello', False)" ,
198
+ " ('', '', True)" ,
199
+ " ('a', 'a', True)" ,
200
+ " ('a', 'b', False)" ,
201
+ " ('ab', 'ba', True)" ,
202
+ " ('abc', 'bca', True)" ,
203
+ " ('abc', 'def', False)" ,
204
+ " ('aab', 'abb', False)" ,
205
+ " ('aabbcc', 'abcabc', True)" ,
206
+ " ('abcd', 'abcde', False)" ,
207
+ " ('race', 'care', True)" ,
208
+ " ('elbow', 'below', True)" ,
209
+ " ('study', 'dusty', True)" ,
210
+ " ('night', 'thing', True)" ,
211
+ " ('stressed', 'desserts', True)" ,
212
+ ],
213
+ },
214
+ // For tree: {"list": ["([4, 2, 7, 1, 3, 6, 9], [4, 7, 2, 9, 6, 3, 1])", "([2, 1, 3], [2, 3, 1])", "([], [])"]}
215
+ // For design: {"list": ["(['LRUCache', 'put', 'get'], [[2], [1, 1], [1]], [None, None, 1])"]}
189
216
body: " result = run_is_anagram(Solution, s, t)\n assert_is_anagram(result, expected)" ,
190
217
// For tree: " result = run_invert_tree(Solution, root_list)\n assert_invert_tree(result, expected_list)"
191
218
// For design: " result, _ = run_lru_cache(LRUCache, operations, inputs)\n assert_lru_cache(result, expected)"
@@ -218,29 +245,29 @@ The template below uses JSON5 format with comments for documentation purposes on
218
245
// - solution_class_name: "Solution"
219
246
// - solution_imports: ""
220
247
// - Simple method signatures: "(self, s: str, t: str) -> bool"
221
- // - Basic test cases: string/number parameters
248
+ // - Basic test cases: structured format with {"list": ["..."]}
222
249
// - Playground: single quotes for strings
223
250
//
224
251
// TREE PROBLEMS (invert_binary_tree):
225
252
// - solution_class_name: "Solution"
226
253
// - solution_imports: "from leetcode_py import TreeNode"
227
254
// - Tree method signatures: "(self, root: TreeNode[int] | None) -> TreeNode[int] | None"
228
255
// - Helper functions use TreeNode.from_list()
229
- // - Test cases: list representations of trees
256
+ // - Test cases: structured format with list representations of trees
230
257
// - Playground: TreeNode imports and list conversions
231
258
//
232
259
// LINKED LIST PROBLEMS (merge_two_sorted_lists):
233
260
// - solution_class_name: "Solution"
234
261
// - solution_imports: "from leetcode_py import ListNode"
235
262
// - List method signatures: "(self, list1: ListNode[int] | None, list2: ListNode[int] | None) -> ListNode[int] | None"
236
263
// - Helper functions use ListNode.from_list()
237
- // - Test cases: list representations of linked lists
264
+ // - Test cases: structured format with list representations of linked lists
238
265
// - Playground: ListNode imports and list conversions
239
266
//
240
267
// DESIGN PROBLEMS (lru_cache):
241
268
// - solution_class_name: "LRUCache" (custom class name)
242
269
// - Multiple methods including __init__
243
- // - Operations-based testing: operations, inputs, expected arrays
270
+ // - Operations-based testing: structured format with operations, inputs, expected arrays
244
271
// - Complex test body with operation loops
245
272
// - Helper functions return (results, instance) for debugging
246
273
// - Playground: print results, return instance
@@ -250,7 +277,7 @@ The template below uses JSON5 format with comments for documentation purposes on
250
277
// - solution_class_name: "Trie(DictTree[str])" (with inheritance)
251
278
// - solution_imports: "from leetcode_py.data_structures import DictTree, RecursiveDict"
252
279
// - Custom class with inheritance from DictTree
253
- // - Operations-based testing like design problems
280
+ // - Operations-based testing with structured format like design problems
254
281
// - Helper functions return (results, instance) for debugging
255
282
//
256
283
// MULTIPLE SOLUTIONS (invert_binary_tree, lru_cache):
0 commit comments