No project description provided
Project description
Leetcode-local-tester
Leetcode test utils for local environment
Background
Because of Leetcode's special design for test cases, if you want to test your code locally, you need to write some boilerplate code to read the test cases from the file and parse them into the format that your code can understand, which is very annoying. Especially in a contest, you may not have enough time to write the boilerplate code. So I wrote this tool to help me generate the boilerplate code automatically. It will improve your efficiency in a contest.
The design is really like TopCoder's test cases, but TopCoder has a very good tool (TZTester) to generate the boilerplate code for you, which is very convenient.
Usage
Install
pip install leetcode-local-tester
Command
leetcode-local-tester work --help
Options:
--kind TEXT The question kind. Now support: `contest`, `problem`,
`season`, and `contest` includes `weekly` and `biweekly`.
Default is `problem`.
--detail TEXT The detail of the question. If type is `contest` or
`problem`, the detail is the url. Such as
`https://leetcode.com/contest/weekly-contest-326/`,
`https://leetcode.con/problems/minimum-number-of-
operations-to-reinitialize-a-permutation/`. If type is
`season`, the detail is the season name. Such as
`2020-fall-solo` or `2020-fall-team`.
--language TEXT The language of the code. Now support: `cpp`. Default is
`cpp`.
--location TEXT The location of the code. Default is `./leetcode/`.
--help Show this message and exit.
Example
leetcode-local-tester work --kind contest --detail https://leetcode.com/contest/weekly-contest-326/ --language cpp --location ./leetcode/
After running the command, you will get the following files:
weekly-contest-326
: The folder of the contest. It contains all test cases and the code file.
utils
: The folder of the utils. It contains code that is used to parse the test cases.
Pay attention: utils
folder is only generated once. After generated the first time, it will not be updated. So you can add your own code in it.
You can write your code in solution.h
. We take the first question in weekly-contest-300
as an example.
The solution.h
file is like this:
/*
Code generated by https://github.com/goodstudyqaq/leetcode-local-tester
*/
#if __has_include("../utils/cpp/help.hpp")
#include "../utils/cpp/help.hpp"
#elif __has_include("../../utils/cpp/help.hpp")
#include "../../utils/cpp/help.hpp"
#else
#define debug(...) 42
#endif
class Solution {
public:
string decodeMessage(string key, string message) {
int res[26];
memset(res, -1, sizeof(res));
int cnt = 0;
for (auto v : key) {
int cur = v - 'a';
if (cur >= 0 && cur < 26) {
if (res[cur] != -1) continue;
res[cur] = cnt++;
}
}
string fin;
for (auto v : message) {
if (v == ' ')
fin += ' ';
else {
char cur = 'a' + res[v - 'a'];
fin += cur;
}
}
return fin;
}
};
After you finish your own code, you can run main.cpp
to test your code.
g++ main.cpp -std=c++11 -o main && ./main
Case 1 testing...
[my_ans]: "this is a secret"
[result]: "this is a secret"
Case 1 passed!
Case 2 testing...
[my_ans]: "the five boxing wizards jump quickly"
[result]: "the five boxing wizards jump quickly"
Case 2 passed!
The number of test cases: 2
The number of test cases failed: 0
If you get Wrong answer
, you can snip the test case and paste it into data
to debug your code.
Pay attention: data
's format is Input + Output.
In this example, the test case is:
"the quick brown fox jumps over the lazy dog"
"vkbs bs t suepuv"
TODO
- Support
python
License
This software is licensed under the MIT License. See the LICENSE file in the top distribution directory for the full license text.
Maintaining the project is hard and time-consuming, and I've put much ❤️ and effort into this.
If you've appreciated my work, you can back me up with a donation! Thank you 😊
Project details
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
File details
Details for the file leetcode_local_tester-0.2.0.tar.gz
.
File metadata
- Download URL: leetcode_local_tester-0.2.0.tar.gz
- Upload date:
- Size: 5.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.2.2 CPython/3.7.15 Darwin/22.3.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 09886e3ae4960cbc1ba1f01cba701c6b06654c9946d84d61b1d7ecdcb949b899 |
|
MD5 | 20364194b046eda9b583b98a1c5c659a |
|
BLAKE2b-256 | 842099e2da1deb1384cdbda07ffed86f78c5b23eaa9539a563ba7bf228ee056c |
File details
Details for the file leetcode_local_tester-0.2.0-py3-none-any.whl
.
File metadata
- Download URL: leetcode_local_tester-0.2.0-py3-none-any.whl
- Upload date:
- Size: 6.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.2.2 CPython/3.7.15 Darwin/22.3.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 798cf8b329290515cc655ea1fba4093c48793617e96c02315f16d4832e9a9a75 |
|
MD5 | 35389b5918da1073dbf170c77856f815 |
|
BLAKE2b-256 | 87c68889004d637b09f4ffbe614e727a0be9995cd316dc616b3c82e32453e50b |