How to make test cases?

I want to test my solution against a number of test cases, so I want to make of test cases in accordance to the constraints of the problem. How to do this?

For the solution part - do I have to manually solve for each test case and check my solution against those, or is there any other way? Also, how to check for the time the code takes to run on all test cases.

Test cases can be classified into these.

  1. Simple cases :
  2. Corner/Edge cases : These are cases with more fine tuned input like large input/small input, 0 input, negative values etc…
  3. Boundary Cases: These are to check if your solution has considered all the constraints.
  4. Stress test cases => These are to check your solution is optimal enough and produces answer within time limits.

There is no definitive way, you can generate randomly and verify them manually (or programmatically )as you understand the problem. For some problems you can try in reverse way , i.e., arrive to the input from output.

Check the official test generation discussion approach here.

Also you can take the testing approach of equivalence class partitioning , boundary value analysis ( a bit tricky in most cases and might not help you much but good if you are stuck and have time to spare, like in Long contests ) and some .

Take a look in the following links with similar questions.

http://discuss.codechef.com/questions/37953/testing-of-own-code

http://discuss.codechef.com/questions/13234/test-case-generation

http://discuss.codechef.com/questions/35281/generating-test-cases

2 Likes