Many times while solving problems, we face issues like time limit exceeds, wrong solution, runtime error, and memory limit exceeds because after designing algorithm we don’t test algorithm efficiency, correctness, time complexity and running the algorithm on a large set of inputs for testing purpose.
This is where stress testing comes for rescue. Stress testing is the common way to find the bug in the algorithm.
which involves generating a large set of random test cases and checking if a brute force algorithm and an efficient algorithm always agree with each other. Many programmers are not familiar with this kind of comprehensive testing.
stress testing helps in finding an efficient algorithm and correct algorithms to problems but also see why certain approaches do not work. In particular, it is easy to sketch intuitive greedy solutions to any problems, but such solutions often do not work in reality.
Write a Generator program which output some random input.
Step’s Involed In Stress Testing
– Generate a random input.
– Run your solution on it.
– Check if the output is correct.
– if not-stop and output the test cases.
Generate small tests for faster and easier debugging especially for trivial solution. make parameters to easily tweak test size. Do not loose generality and check for special cases.
1 Stress test after manual test.
2 No Point if generator/trivial solution / checker is too complex
3 Start with very small test sizes.
4 Couple of minutes running testing program is usually enough.
5 if bug is not found, generate larger tests.
Input Example: 3 1 2 3 Output: 6 Input Example: 7 7 5 6 1 3 7 10 Output: 140
Summary Test your solution before to avoid errors. Start testing with given samples. check for corner cases. special/hidden test cases. Manual cases like min-max, problem-type specific and anything you could imagine. test different part separately. If everything else fails, run stress-test
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready. Get hold of all the important mathematical concepts for competitive programming with the Essential Maths for CP Course at a student-friendly price.
In case you wish to attend live classes with industry experts, please refer Geeks Classes Live