How should I test my program

the biggest problem I’m having is the codechef runs the code, then says ‘wrong answer’, but no feedback as to what was wrong with the output from my program.

My program works for the presented inputs and meets (as I read the criteria) all the listed criteria.

How should I proceed in such cases?

7 Likes

Use ideone(online ide) or other ide for testing.

i want to know why compile error at include<conio.h> in using c

Learn gdb from here and here (vedios from CS50 by harvard).It is a commandline runtime debugging tool. It supports many languges but the tutorials are specifically for c and can be extended to c++ easily. For other languages also you can find the tutorials.
It makes debuggig really faster and you dont have to change your program again and again for debugging,

in manually u can check all the possible inputs into it and can check out. i used this method to test my last work about kerala houseboat packages. also there are a lot of testing tools are available in the market.

import java.io.*;
class firstpro{
public static void main(String args[])throws IOException{

int[] a={1,2,88,42,99};
int i;
System.out.println("Input:");
for(i=0;i<5;i++){
System.out.println(a[i]);
}
System.out.println();

System.out.println("Output:");

for(i=0;i<5;i++){
	if(a[i]==42)
		break;
	else
		System.out.println(a[i]);
}   	

}

}
This is my program for input and output processing but codechef is giving me wrong answer. I even tested this answer on ideone and there it got successfully executed. so why codechef is giving me wrong answer??

#include<stdio.h>
int main()
{

int i,n,a,b,s=0;
printf(“enter the number\n”);
scanf("%d",&n);
for(i=1;n>0;i++)
{
a=n%10;
b=n/10;
n=b;
s=s+a;
}
printf(“sum is %d”,s);
return 0;
}

You can check your code on https://www.codechef.com/ide...Write test case and give the custom input and check the corresponding output

Can anyone tell me whether the time limit given for a program is for individual test cases or for the entire test cases

@princelegolas

Excuse Me Sir/Ma’am…

What about C++'s double and long double?

Even they won’t be able to store 100! ?

I don’t think so…

After putting my code on ideone, ideone is giving correct output on the sample input but codechef is saying the solution is wrong.Why??

Use codechef compile and run ide Compile and run the code with online compiler and IDE | CodeChef

Codechef should improve its testing technique.

We test our code in other sites and ide they work fine there, but when submit in codechef it simply says WRONG ANSWER. seriuosly? shouldn’t it clearly state whats went wrong. Its so irritating ti see that message again and again having no idea what did go wrong.

1 Like

Or use freopen(“in.txt”,“r”,stdin); and freopen(“out.txt”,“w”,stdout);

1 Like

seriously man,
workin on a code, i submit solution to the problem it accepts subtask1 and showing wa for subtask 2. i have test almost all possible inputs but it simply shows wa all time,
it should give feedback of what went wrong…

1 Like

This is the most irritating issue i face here.
CodeChef should provide hints or useful feedback when it throws WA. Let them reduce points/stars but provide a meaningful response. Thats the least i expect !
The current UI doesn’t look intuitive & reduces engagement levels of beginners like me :sleepy:

If it tells, whats wrong in your code, what did you learn then? Like this, every other person will get AC, because of the hints. At the end of each round, editorial is published. Do refer to that, if you were not able to solve any problem

In that case lets extend your argument and ask What is the fun in revealing full editorial afterwards but hiding the test case failure reason when the person is actually engrossed?

No / delayed feedback == Delayed learning && Low engagement.

PS: Not everyone is here for the stars / ratings. Most beginners look for smooth learning curve.

1 Like

Thats the mistake beginners do. Take example of this long challenge, 6th problem, Dr. Chef. Its a good implementation type problem where you need to spend atleast 1-2 day(even hours) to find edge cases, learn different implementation etc.
Even after writing code, it gives WA suppose.
What did you learn in these 1-2 days spent in this problem?- Learnt to debug, learnt to find edge case, leart to implement harder things or above your skills, learnt to understand question.
Now suppose, you submit within 1 hour of trying and it gives WA and you get the hint. Now you learnt nothing out of the question.

Sometimes try out codeforces. You are new here, so being impatient. We have been practising for 2 years now. We had the same mindset as you, but gradually it improved.

Ok will try codeforces next.

Personally, i tried CodeWars ( https://www.codewars.com/ ) & totally liked it !
I highly recommend to any beginner, it has better UI & provides instant error logs so that we atleast know what went wrong. Thats how it should be, more realistic to actual development where can analyze the logs incase theres an error!

BTW, looking at your submissions, you don’t seem to be 2 years old on CodeChef :thinking:

1 Like