Stress Tester
A template harness for stress-testing competitive programming solutions — compare a fast solution against a brute-force reference on random inputs.
Stress Tester
A template harness for stress testing any competitive-programming task: you write a fast solution and a slow-but-obviously-correct brute, generate random tests, and stop at the first mismatch.
How the Pieces Fit
| File | Purpose |
|---|---|
solution.cpp |
Your optimized implementation for the task you are debugging |
brute.cpp |
A simple, trusted reference solution (may be slower) |
gen.cpp |
Input generator — customize to emit random or edge-case inputs; accepts an optional seed for reproducibility |
tester.py |
Orchestrates the loop: compile → generate → run solution vs. brute → report first difference |
gen_notes.md |
Documentation for the reusable RNG helpers inside gen.cpp |
gen_approach.md |
Broader notes on designing generators and edge cases |
gen_tree.cpp / gen_tree2.cpp |
Standalone tree generators for problems that need random trees |
input.txt |
Overwritten with the latest generated test case |
Quick Start
Requirements: C++17 compiler (g++) and Python 3
# Run the harness
python tester.py
This will:
- Compile
solution.cpp,brute.cpp, andgen.cppwith-std=c++17 -O2 - For each seed, generate an input, run both binaries, compare outputs (whitespace-agnostic)
- Stop on the first mismatch with the failing case echoed from
input.txt
Customizing for Your Problem
- Edit
gen.cppto emit inputs matching your problem statement (sizes, distributions, edge cases) - Keep the brute simple and obviously correct — speed is secondary
- Tweak
START_SEEDandMAX_TESTSintester.pyto skip early seeds or cap runs
Manual reproduction
# Generate a specific test case
gen 123 > input.txt
# Run both solutions
solution < input.txt
brute < input.txt
Workflow Diagram
┌──────────┐ ┌──────────┐ ┌──────────────┐
│ gen.cpp │────▶│ input.txt │────▶│ solution.cpp │──┐
│ (seed N) │ └──────────┘ └──────────────┘ │
└──────────┘ │ ┌──────────────┐ │ Compare
└──────────▶│ brute.cpp │──┘ outputs
└──────────────┘
│
Match? ──▶ Next seed
Mismatch? ──▶ STOP & report
Tips
- When a mismatch appears, inspect
input.txtalong with both outputs printed by the tester - Use the tree generators directly when the task needs random trees; otherwise ignore them
- Recompile happens automatically each run; fix compile errors before rerunning
Tech Stack
- C++17 — Solution, brute, and generator code
- Python 3 — Test orchestration and comparison logic