Stress Testing is a tool for competitive programming and algorithm development that helps you verify the correctness and efficiency of your C++ solutions by comparing them against a brute-force solution on randomly generated test cases.
- Modular, extensible C++ test case generators (arrays, graphs, strings, numbers, etc.)
- Cross-platform: works on macOS, Linux, and Windows
- Flexible: set number of test cases and time limit via CLI or prompt
- Clear output for Accepted, Wrong Answer, Time Limit Exceeded, and Runtime Error
- Easy to extend with your own generators and solutions
- Python 3
- g++ (or g++-13 on macOS; can be set via the
CXXenvironment variable) - CMake (optional, for building with CMake)
- macOS: Pre-installed, or install via Homebrew:
brew install python3
- Linux (Debian/Ubuntu):
sudo apt update && sudo apt install python3 python3-pip - Windows: Download Python and add to PATH.
- macOS: Install Xcode Command Line Tools:
xcode-select --install
- Linux (Debian/Ubuntu):
sudo apt update && sudo apt install build-essential g++ - Windows: Install MinGW-w64 or use WSL.
- macOS:
brew install cmake
- Linux:
sudo apt install cmake
- Windows: Download CMake and add to PATH.
git clone https://github.com/7oSkaaa/stress_testing.git
cd stress_testingπ¦ Stress_Testing
βββ π CMakeLists.txt
βββ π README.md
βββ π stress_testing.py
βββ ποΈ build/
β βββ π cmake_install.cmake
β βββ π CMakeCache.txt
β βββ βοΈ Makefile
β βββ ποΈ CMakeFiles/
β β βββ ...
β βββ βοΈ correct
β βββ βοΈ generator
β βββ βοΈ test
β βββ ...
βββ ποΈ cpp/
β βββ π correct.cpp
β βββ π generator.cpp
β βββ π test.cpp
β βββ ποΈ generators/
β βββ π generator_arrays.h
β βββ π generator_graphs.h
β βββ π generator_numbers.h
β βββ π generator_strings.h
β βββ π generator_utils.h
βββ ποΈ data/
β βββ π correct_output.txt
β βββ π input.txt
β βββ π test_output.txt
βββ ποΈ src/
β βββ π __init__.py
β βββ ποΈ utils/
β βββ π __init__.py
β βββ π cpp_compiler.py
β βββ π file_handler.py
β βββ π terminal_colors.py
βββ ...
- Place your brute-force solution in
cpp/correct.cpp. - Place your optimized solution in
cpp/test.cpp. - Edit
cpp/generator.cppto generate test cases using the modular generators fromcpp/generators/.
Edit generator.cpp to use the flexible generators. Example:
#include "generators/generator_numbers.h"
#include "generators/generator_arrays.h"
#include "generators/generator_strings.h"
#include "generators/generator_graphs.h"
#include "generators/generator_utils.h"
int main() {
std::mt19937_64 rng(std::chrono::steady_clock::now().time_since_epoch().count());
int n = gen_numbers::random<int>(5, 15, rng);
auto arr = gen_arrays::random<int>(n, 1, 100, rng);
gen_utils::print(arr);
auto s = gen_strings::random(n, gen_strings::CaseType::Lower, rng);
std::cout << s << '\n';
auto tree = gen_graphs::tree(n, rng);
gen_utils::print(tree);
// ... more generators ...
return 0;
}The script will compile everything for you.
cmake -S . -B build
cmake --build buildThis will create executables for generator, test, and correct in the build directory.
You can run the stress test from the terminal or an IDE:
python stress_testing.py --tests 100 --time 2--tests(optional): Number of test cases (if not provided, you will be prompted)--time(optional): Time limit per test case in seconds (if not provided, you will be prompted)
- Accepted: Your solution matches the brute-force output.
- Wrong Answer: Shows the input, expected output, and your output for the failed test case.
- Time Limit Exceeded: Your solution exceeded the time limit.
- Runtime Error: Your solution crashed.
random < T > (T l, T r, rng): Random integer in [l, r].random_range < T > (T l, T r, int count, rng): Vector of random integers in [l, r].random_exclude < T > (T l, T r, set < T > exclude, rng): Random integer in [l, r] not in exclude.random_range_exclude < T > (T l, T r, int count, set < T > exclude, rng): Vector of random integers not in exclude.random_weighted < T > (vector < T > values, vector < double > weights, rng): Random value from values with custom weights.random_real < T > (T l, T r, rng): Random floating-point in [l, r].random_real_exclude < T > (T l, T r, T excl_l, T excl_r, rng): Random real in [l, r] excluding [excl_l, excl_r].
random < T > (int len, T l, T r, rng, unique, sorted): Random array of length len in [l, r].permutation < T > (int n, rng): Random permutation of 1..n.matrix < T > (int rows, int cols, T l, T r, rng, unique_rows, sorted_rows): 2D array.pairs < T > (int len, T l1, T r1, T l2, T r2, rng, ordered): Vector of pairs.subset < T > (T l, T r, int k, rng, sorted): Unique subset of size k from [l, r].partition < T > (T sum, int k, T min_val, T max_val, rng): Partition sum into k parts.arithmetic_progression < T > (int len, T start, T step): Arithmetic progression.geometric_progression < T > (int len, T start, T ratio): Geometric progression.constant_array < T > (int len, T value): Array with all elements equal.bit_array < T > (int len, double prob_one, rng): Bit array (0/1) with probability for 1s.shuffled < T > (vector < T > v, rng): Shuffled copy of v.strictly_increasing < T > (int len, T start, T step_min, T step_max, rng): Strictly increasing array.strictly_decreasing < T > (int len, T start, T step_min, T step_max, rng): Strictly decreasing array.random_with_sum < T > (int len, T sum, T min_val, T max_val, rng): Random array with given sum.
random (int len, CaseType, rng, char l, char r): Random string.palindrome (int len, CaseType, rng, char l, char r): Palindrome string.random_alphanum (int len, bool letters, bool digits, CaseType, rng): Alphanumeric string.random_custom (int len, string alphabet, rng): String from custom alphabet.random_strings (int count, int len, CaseType, rng): Vector of random strings.palindromes (int count, int len, CaseType, rng): Vector of palindromes.
tree (int n, rng): Random tree (edges).simple_graph (int n, int m, rng): Simple connected graph.weighted_graph (int n, int m, int min_w, int max_w, rng): Weighted graph.directed_graph (int n, int m, rng): Directed graph.dag (int n, int m, rng): Directed acyclic graph.bipartite (int n1, int n2, int m, rng): Bipartite graph.star (int n, rng, int center): Star graph.cycle (int n, rng): Cycle graph.complete (int n): Complete graph.regular (int n, int d, rng): Regular graph.tree_with_diameter (int n, int diameter, rng): Tree with given diameter.chain_tree (int n): Chain tree (path).
print (const vector < T > &v): Print vector.print (const vector < pair < T, U > > &v): Print vector of pairs.print (const vector < vector < T > > &mat): Print 2D vector.print (const vector < tuple < Args... > > &v): Print vector of tuples.print (const T &val): Print single value.print (const vector < string > &v): Print vector of strings.
Each function is documented in the header files with parameter and return type. For more details, see the comments in each header.
- The C++ compiler can be set via the
CXXenvironment variable. On macOS, the script will useg++-13if available, otherwiseg++. - All generators and scripts are cross-platform and tested on macOS, Linux, and Windows.
- The project is modular and easy to extend for your own needs.