LeeCo: A utility for empowering the local debugging of LeetCode problems with testcases.
Project description
LeeCo: A utility for empowering debugging LeetCode problems locally in Python
Introduction
For some LeetCode problems related to Binary Tree, Linked List, etc., it is always difficult to debug the code locally with testcases provided by LeetCode, since the input and output format is customized (For example, the representation of a binary tree / linked list is a list of integers, and the input of design problems is sequences of operations and parameters.) and you may write a lot of test codes manually to debug the code locally.
This package provides a utility to help you debug the code locally with these testcases without struggling with the input and output format.
Installation
Just run the following command to install the package.
pip install leeco
Usage
In most cases, You just add the __main__ block in your code without modifying the original solution code.
And write the testcases in the __main__ block as follows.
# <Your solution code here>
if __name__ == "__main__":
import leeco
leeco.test("""
<Your testcases here, same as the input format of LeetCode>
""")
If you define more than one outer function (whose name is not started with _) in Solution class,
you should manually specify the main function (defined by LeetCode) to test.
class Solution:
def function1(self, ...):
# The outer function defined by you
pass
def mainPoint(self, ...):
# The main function defined by LeetCode
pass
if __name__ == "__main__":
import leeco
leeco.inject(Solution.mainPoint)
leeco.test("""
<Your testcases here, same as the input format of LeetCode>
""")
For design problems (like 676), if you define more than one outer class (whose name is not started with _) in your code,
you should manually specify the main class (defined by LeetCode) to test.
class YourClass:
""" The class defined by you """
class MainClass:
""" The main class defined by LeetCode """
if __name__ == "__main__":
import leeco
leeco.inject(MainClass)
leeco.test("""
<Your testcases here, same as the input format of LeetCode>
""")
And then debug the code, add breakpoints and do anything you want with your favorite IDE or text editor.
TODOs
- When parse the input of list, support calling the parser of the element type.
- Support the problems related to the probability.
- Support the timing of the function.
- Support fetching the official testcases from LeetCode.
- Support the recursive parsing of the input, e.g., List[List[int]].
- Support the comparison of the output with the expected output.
- Only expose the
testandinjectfunction to the user. - Support the replacement of
ListNodeorTreeNodedefined by the user. - Unit tests.
- Print or store intermediate results for
lru_cache
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file leeco-0.0.1rc0.tar.gz.
File metadata
- Download URL: leeco-0.0.1rc0.tar.gz
- Upload date:
- Size: 10.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
03c3110a84277a1897628cf33f2536354653ec2a81fec82515fc056b8210b11b
|
|
| MD5 |
b8778b84b7b8482fb1094e46486de777
|
|
| BLAKE2b-256 |
5d8f7a2a4683375943b0327ff4a2d8f72de744c38ac17c25c2a4642dcc2450d5
|
File details
Details for the file leeco-0.0.1rc0-py3-none-any.whl.
File metadata
- Download URL: leeco-0.0.1rc0-py3-none-any.whl
- Upload date:
- Size: 12.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
773daec6a7a739b21dea3bd4959efca9eb2cd486a30a5b95337e8b46c4506bc7
|
|
| MD5 |
33301f3daa5c400d597efbf6f9f9125a
|
|
| BLAKE2b-256 |
3acc758547a952d8d31e4e3464c6fa4a520979d95aa60ab31c7e0790c342b5c2
|