Stress testing solutions for Competitive Programming
Note: A Codeforces blog can be found here on Codeforces
.
A simple bash script which stress tests an optimized solution & a brute
force solution on randomly generated testcases, to find a possible failing testcase.
Clone this repository using git or download manually.
# Clone the Repository.
$ git clone https://github.com/bhupixb/Stress-Testing-bash-script
# Change directory.
$ cd Stress-Testing-bash-script
# Give execute permission to `stress_test` script to current user.
$ sudo chmod u+x stress_test
# Assuming your optmized solution is in main.cpp and brute force solution
# in brute.cpp, to run stress test:
$ ./stress_test -b brute.cpp -m main.cpp
# To print usage, use -h flag
$ ./stress_test -h
This is useful when your optimized solution is failing on some test case during a contest
and you are unable to come up with a failing test case.
In cases like this if you write a brute force solution that you are sure that will produce
correct output and run these 2 solutions on random tests, it can help
you find a test case which fails on your main solution.
tc_generator.cpp
program and runs your main & brute solutionThe file tc_generator.cpp
has some boilerplate code to generate commonly
required testcases like tree
, graph
, array of integers
& strings
.
You can modify this file to generate test cases as per your requirements. E.g.
1) to generate an array calling:
gen_array(10, -5, 10)
;
it will return an array(vector more specifically) with length 10 and elements in the range [-5, 10].
2) to generate a tree calling:
gen_tree(10)
:
will return a tree with 10 nodes.
3) to generate a simple graph calling:
gen_simple_graph(10, 12)
;
will return a simple connected graph with 10 nodes and 12 edges.
You can add things as you need them or use testlib which is the best if you know how to use it.