NOTE In the following days this will get archived and rewritten in bash (Linux, macOS) and possibly batch (Windows).
Portable local testing software (and test case generator TODO: implement this) written in Python for competitive programming in C++.
Unix-like (e.g. macOS, Linux) uses bash and Windows uses Command Prompt.
platform | Unix-like | Windows | WSL2 |
---|---|---|---|
support | ✔️ | ✔️ | ❌ |
shell | bash | cmd | bash |
example folder structure
.
└── foo/
├── bar-tests/
│ ├── 0.in
│ └── 0.out
└── bar.cpp
output generated with -h
usage: lt.py [-h] -p PROGRAM [-c]
optional arguments:
-h, --help show this help message and exit
-p PROGRAM, --program PROGRAM
program pathname
-c, --compile compile program (default=False)
python3 $lt/lt.py -p bar.cpp -c
For simplicity, setup an environment variable for your local-test directory.
echo "export VARIABLE_NAME=value" >> ~/.bash_profile
python %lt%\lt.py -p bar.cpp -c
Unless local-test directory is an environment variable ("lt"), replace "%lt%\lt.py" with its pathname.
Environment Variables > System variables > New
IMPORTANT Make sure to have matching newlines, otherwise correct output might flag your program as defective. Example below.
bar.cpp
#include <cstdio>
using namespace std;
int main() {
int n;
scanf("%d", &n);
printf("%d\n", n);
}
^ Newline character present
0.in
66
^ Would work without newline
0.out
66
^ Newline present
SIO2 (used by POI (POI's SIO2 link)) itself is partially written in Python. Honestly, I found joy writing Python for a change.
BTW check out similar testing program written in bash shell (link).
WARNING Specified compiler will be run in shell.
(not actual JSON below)
"platform": ["Unix", "Windows"]
"compiler": ["clang++", "clang", "g++", "gcc", "etc."]
"generator-prefix": ["gen", "g", "etc."]