Package: leetcode-local-tester
Leetcode-local-testerLeetcode test utils for local environmentBackgroundBecause 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.UsageInstallpipinstallleetcode-local-testerCommandleetcode-local-testerwork--help

Options:--kindTEXTThequestionkind.Nowsupport:`contest`,`problem`,`season`,and`contest`includes`weekly`and`biweekly`.Defaultis`problem`.--detailTEXTThedetailofthequestion.Iftypeis`contest`or`problem`,thedetailistheurl.Suchas`https://leetcode.com/contest/weekly-contest-326/`,`https://leetcode.cn/problems/minimum-number-of-operations-to-reinitialize-a-permutation/`.Iftypeis`season`,thedetailistheseasonname.Suchas`2020-fall-solo`or`2020-fall-team`.--languageTEXTThelanguageofthecode.Nowsupport:`cpp`,`python3`.Defaultis`python3`.--locationTEXTThelocationofthecode.Defaultis`./leetcode/`.--helpShowthismessageandexit.Before you useBecause the utility needs to login to Leetcode to get some information, there are two ways to login. One is to use username and password. You need to set these value to environment variables:LEETCODE_USERNAMEandLEETCODE_PASSWORD. The other is to use cookie. You need to set the cookie to environment variable:LEETCODE_COOKIE. You can read the articleHow to get the cookieto get the cookie.Note: If you useleetcode.com. You cannot use username and password to login, becauseleetcode.comhas recaptcha. So you need to use cookie to login.Exampleleetcode-local-testerwork--kindcontest--detailhttps://leetcode.com/contest/weekly-contest-326/--languagecpp--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:utilsfolder 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 insolution.h. We take the first question inweekly-contest-300as an example.
Thesolution.hfile 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#endifclassSolution{public:stringdecodeMessage(stringkey,stringmessage){intres[26];memset(res,-1,sizeof(res));intcnt=0;for(autov:key){intcur=v-'a';if(cur>=0&&cur<26){if(res[cur]!=-1)continue;res[cur]=cnt++;}}stringfin;for(autov:message){if(v==' ')fin+=' ';else{charcur='a'+res[v-'a'];fin+=cur;}}returnfin;}};After you finish your own code, you can runmain.cppto test your code.g++main.cpp-std=c++11-omain&&./main

Case1testing...[my_ans]:"this is a secret"[result]:"this is a secret"Case1passed!
Case2testing...[my_ans]:"the five boxing wizards jump quickly"[result]:"the five boxing wizards jump quickly"Case2passed!
Thenumberoftestcases:2Thenumberoftestcasesfailed:0If you getWrong answer, you can snip the test case and paste it intodatato 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"TODOSupportpython(completed)LicenseThis 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 😊If there is any problem, please create an issue. I will reply to you as soon as possible.