SIR,

I am new to codechef problems, but i have been programmming all the basic algorithms like: finding GCD, array manipulations ,prime no. etc in C++ since more than one year but i never encountered the term:

“**TEST CASES**” for any such problems,

After seeing questions in Easy section in Practice section i feel like i will solve it,

but then i see term “**TEST CASE**” included in every questions

Can you Please kindly explain me the meaning and use of such test cases in any of(rather all) coding problems…

Abhilash

Test cases are the input for the problem. Could you be more specific as to what’s confusing about it? Look at the Life, Universe and Everything problem.

Hello,

Well, putting it in terms you can understand:

Given two numbers A and B, you find their GCD by doing:

GCD(A,B)

If this was a programming question, you would see something like:

“Given several pairs of numbers you need to output their GCD as a result. The 1st line of input contains a number N, the number of test cases. N test cases follow, each containing two space separated integers. For each test case, you need to output the greatest common divisor of the numbers.”

Example:

Input:

2

5 0

54 24

Output:

5

6

Here, we say that:

5 0 **1st test case**

54 24 **2nd test case**

5 **Output for first test case**

6 **Output for second test case**

Test cases are the essential “tools” that allow the online judge to verify if your algorithm to solve a given problem is correct.

Best regards,

Bruno

@kuruma described test case very well, I just add some contemplation about “why so many coders ask for test case?”

In contests like CodeChef’s you can get several results when you submit your solution. One very “popular” is wrong answer (WA). This one is the worst you can get - you think your code is correct, but judge says it’s not. Trust me in 99.999% judge is correct - there is problem in your code.

Maybe you tried to think about the problem for few more hours and still you believe you are correct, you found all corner cases, it works fine for all your inputs. There is one problem with testing - is NOT true, that if all your tests passed, there is no bug, that’s sad truth. I such cases coders ask others for help - because on CodeChef and SPOJ (and maybe other contest sites) inputs are not known.

Let say we have simple problem - read two positive integers a, b <= 1000.000 from input and print a * b to the output. One can think “I’m not so stupid, that I do not know how to multiply two numbers” and the code will be

```
#include <cstdio>
int main() {
int a, b;
scanf( "%d%d", &a, &b );
printf( "%d\n", a*b );
return 0;
}
```

but judge will return WA. Newcommer will claim “judge is incorrect”, “input is incorrect”, “C++ is not working fine” and so on. Experienced coder will ask: “Hi guys, I believe my code is correct, but I’m getting WA, do you know the test case when my code fails?” (it’s also good practice to describe your approach). It’s knows, that you will remember better what was the problem if you solve it, so experienced coder is not asking “why is my code not working?”, but “help me with some counter example and I’ll find myself why it’s not working”.

Maybe you already know where the problem is, but in more difficult problems to find such test cases is more difficult too, typically the solution is a lot longer also. Problem in code above is, when one inputs f.e. `200000 300000`

, code (on my PC) returns `-129542144`

, every mathematician knows that the result of multilication of two positive numbers is positive number, and there is not problem in C++ language, compiler, judge, it’s in implementation.

thanks for your answer i got it now