The CPH VS Code Extension helps simplify local testing for competitive programming problems. However, LeetCode's default templates require slight modifications for local testing in VS Code. Follow this guide to adapt your code for seamless testing.
- Use the
CPH: Fetch Test Cases
command from the command palette (Ctrl+Shift+P
). - Paste the LeetCode problem URL (e.g.,
https://leetcode.com/problems/two-sum/
). - The extension will download the problem's test cases and save them locally in the
test_cases
folder:- Inputs:
test_cases/input_1.txt
,test_cases/input_2.txt
, etc. - Outputs:
test_cases/output_1.txt
,test_cases/output_2.txt
, etc.
- Inputs:
LeetCode templates provide function signatures for input arguments. For local testing in VS Code, add an entry point (main
function or equivalent) to handle inputs and outputs.
-
Input Handling:
- Read input using appropriate methods:
cin
/scanf
in C++input()
in Pythonprocess.stdin
in JavaScript
- You can either hardcode test cases or read them from the saved test case files (e.g.,
test_cases/input_1.txt
).
- Read input using appropriate methods:
-
Function Invocation:
- Instantiate the class (if required) and call the function with parsed inputs.
-
Output Verification:
- Print the function's result and manually compare it with the expected output in the corresponding file (e.g.,
test_cases/output_1.txt
).
- Print the function's result and manually compare it with the expected output in the corresponding file (e.g.,
- Use the
CPH: Run Test Cases
command to execute your code against all test cases saved in thetest_cases
folder. - The extension will:
- Compare your code's output with the expected output.
- Highlight any mismatches for debugging.
- VS Code: You need to have Visual Studio Code installed.
- Node.js: The extension requires Node.js for running the commands.
-
Clone the repository:
- Clone this repository to your local machine using the following command:
git clone https://github.com/your-repo/cph-vs-code-extension.git
- Clone this repository to your local machine using the following command:
-
Install dependencies:
- Navigate to the extension directory and install the necessary dependencies:
cd cph-vs-code-extension npm install
- Navigate to the extension directory and install the necessary dependencies:
-
Open in VS Code:
- Open the extension folder in VS Code:
code .
- Open the extension folder in VS Code:
-
Install the extension:
- Go to the Extensions view in VS Code (
Ctrl+Shift+X
), search forCPH: LeetCode Helper
, and click Install.
- Go to the Extensions view in VS Code (
You can configure the extension's settings to suit your preferred programming languages. The following settings can be added to your settings.json
file in VS Code:
{
"cph.language.cpp.compile": "g++ -std=c++17 -o $fileNameWithoutExt $fileName",
"cph.language.cpp.run": "./$fileNameWithoutExt"
}