testing your code

when you write program in practice section and you want check witch part of your code have bug … you can create random test case and check your result with other result that have this.
but in contest you must first solve your problem with low point(simple approach that take a 10pt or 20pt)
now you have a problem that give true answer for low test case! then you can write advance code and compare this result with that …

1 Like

this is really helpful in long contests, but in short contest we usually don’t get time to write test case generator. Do you have any template? or Can you tell me how to write test cases quickly?

1 Like

thank you @ahmadreza1994

1 Like

You can use file handling for that. Create a brute solution, a test cases generator and your optimized solution. Generate test cases in an input file and get output for both brute and optimized solutions.

Then, compare your output files using the fc command in windows or diff in linux!

Example:

TestCaseGen.cpp

//Header and starting code

freopen(“input.txt”,“w”,stdout);

//Test Generator code

Brute.cpp file

//Header and starting code

freopen(“input.txt”, “r”, stdin);

freopen(“output_brute.txt”, “w”, stdout);

//Brute code

CompleteSolution.cpp

//Header and starting code

freopen(“input.txt”, “r”, stdin);

freopen(“output_full.txt”, “w”, stdout);

//optimized complete code

2 Likes

Mostly short contest doesn’t have a subtask to apply bruteforce first and then check it for rest of them…

If You wanna use template then should use this in optimal way for getting minimizing the overhead after all… Go through c++ faster input/output or use built in function as much as possible.

Basically these input and output handling are used in generating or making a test cases of a particular question so think in that way, if you wanna use this!..

I mean they all used rand() function in C language! They are very usefull if you wanna check your program for large input etc!

Thank You!

1 Like
//