Generating test cases

How to generate good test cases such that all the cases like corner cases or any hidden case can be covered in that.

And how any online judge generate test cases both for straight forward and challenge programs.

even i am not very experienced at test cases but normally you generate corner test cases by using the various limits given in the problem or observing places where some values are becoming 0 or some specific value in your formula .eg in x%p value becomes 0 when x is a multiple of p so that is a corner case. for normal cases you can randomly generate numbers and then test the o/p of your code with the reverse formula.

Most of the time, generating test cases is not a simple task. In fact a test generator sometimes can be more complex than the solution itself!

For finding corner-cases and inputs which cause worst case performance - you need to think deeply. There is no well-defined procedure for it.

However you can generate random test files, by writing a simple program. This can help you analyse the efficiency of your code, and find obscure bugs in your code. A lot of time random files do contain corner cases.


My understanding of corner case is slightly different - corner case is one or only a few cases for which your algorithm/idea is not working properly. It’s an exceptional input, you have to handle separately.

For example we can assume that primes are odd, but corner case is 2.

You can generate some random tests for bigger n, but I see 2 problems here

  1. not always your random generation generates valid input
  2. you are not testing your algorithm (idea), but your implementation - such tests almost never find corner and/or worst cases

I agree with @vinayak garg that test cases generation is not a simple task, for example you can easily generate test file for T = 100 and S = 1000, but how you will find that your algorithm is working fine for such input? You can find only execution time and hope…

Several times I was thinking about creating thread to discuss how to test some concrete problem to grab some ideas for next contests, but never did it :-/