- Write your code to
solutions/Problem_*/algorithm.pyunder the problem folder. - Copy and paste testcases to
solutions/Problem_*/testcases/sample_*.inandsolutions/Problem_*/testcases/sample_*.outfrom Kattis. It is okay to leave one empty if there are less than 3 testcases on Kattis. You can also add more test files. - Run
python3 main.pyto execute all solutions against their samples. - (Optional) Run
python3 main.py --clean Problem_Xorpython3 main.py --clean-allwhen you want to clear stored samples.
A lightweight CLI harness for running CMPUT 403 Kattis-style solutions against curated samples. It auto-discovers each problem, executes its algorithm.py, and reports unified diffs when output mismatches are encountered.
- Python 3.8+ (the runner invokes whatever interpreter launches
main.py).
main.py– orchestrates discovery and execution of solutions and their testcases.solutions/Problem_X/algorithm.py– Python entry point expected to read fromstdinand write tostdout.testcases/– six files namedsample_1.in/.outthroughsample_3.in/.outholding paired inputs and expected outputs. Additional*.in/.outpairs are also picked up automatically if needed.
python3 main.pyThe runner locates every solutions/Problem_*/algorithm.py, streams each sample_*.in into the script, and compares the captured stdout with the corresponding .out. Results are printed per sample with a final summary. A non-zero exit code indicates at least one failure, timeout, or missing artifact.
Use the built-in cleanup helpers when you need to discard sample files:
# Remove all .in/.out files for a single problem
python3 main.py --clean Problem_X
# Purge samples for every problem
python3 main.py --clean-allCleaning only touches .in/.out files inside each testcases/ folder; it leaves other assets intact.
Each test execution inherits a 10 second timeout. When a timeout or runtime error occurs, stderr (if any) is reported with the failure message.
- Create a new folder
solutions/Problem_<NAME>/. - Add an
algorithm.pythat exposes amain()style entry point (reading stdin, writing stdout). - Populate
testcases/with at least the canonicalsample_1.in/.out,sample_2.in/.out, andsample_3.in/.out. You can add more*.in/.outpairs for stress or edge cases—the runner will execute them all. - (Optional) Include helper functions like
solve()and inline unit tests to streamline manual verification.
- Adjust
TIMEOUT_SECinmain.pyto change per-sample execution limits. - Introduce additional validation or scripting (e.g., formatting, linting) by extending
main.pyor wrapping it with shell scripts.
- Missing files: The summary flags absent
algorithm.py,testcases/folders, or unmatched.in/.outpairs. - Unexpected diffs: The runner normalizes line endings and trims trailing blank lines before comparison to reduce false positives.
- Different interpreter: Set
PYTHONPATHor launch with the desired interpreter viapython3 main.pyto control imports and runtime.
- Co-locate quick assertions (e.g.,
test_solve) inside eachalgorithm.pyfor fast feedback. - Use descriptive sample cases that mirror Kattis “Sample Input/Output” plus custom edge cases so the harness doubles as regression protection.
- Consider scripting additional samples (stress tests) and naming them clearly (e.g.,
large_01.in)—the runner accepts any*.in/.outpair.