How should I test my program

One of the way of testing is to generate random test cases that can be solved manually for solutions and test your code against those test cases to figure out the bug…

For Example these are some of the random cases generator for problems of March Long Contest in PYTH 2.7.x

### Test case generator for DEVCLASS

import random

task=[0,1,2]
case=["B","G"]

test=100
print test

for i in range(test):
    a=''
    print random.choice(task)
    siz=random.randrange(1,15)
    for j in range(siz):
        a+=random.choice(case)
    print a


#------------------------------------------------#
#------------------------------------------------#

### Random Test case generator for SINEWAVE

import random

#number of test cases = 50
T=50

def task1():
    print T
    for i in range(T):
        a=""
        s=random.randrange(0,12+1)
        c=random.randrange(0,12+1)
        k=random.randrange(1,25+1)
        a+=str(s)+" "+str(c)+" "+str(k)
        print a

def task2():
    print T
    for i in range(T):
        a=""
        s=random.randrange(0,50+1)
        c=0
        k=random.randrange(1,50+1)
        a+=str(s)+" "+str(c)+" "+str(k)
        print a

def task3():
    print T
    for i in range(T):
        a=""
        s=random.randrange(0,50+1)
        c=random.randrange(0,50+1)
        k=1
        a+=str(s)+" "+str(c)+" "+str(k)
        print a

def task4():
    print T
    for i in range(T):
        a=""
        s=random.randrange(0,50+1)
        c=random.randrange(0,50+1)
        k=random.randrange(1,100+1)
        a+=str(s)+" "+str(c)+" "+str(k)
        print a

def forTesting():
    print T
    for i in range(T):
        a=""
        s=random.randrange(0,10+1)
        c=random.randrange(0,10+1)
        k=random.randrange(1,10+1)
        a+=str(s)+" "+str(c)+" "+str(k)
        print a

forTesting()

If you are using C/C++, add this in your code

    #ifndef ONLINE_JUDGE
	freopen("test.in", "r" , stdin);
	freopen("test.out", "w", stdout);
    #endif

Copy random test cases in a file named test with extension .in in same directory your source code is saved and test your code or you may use ideone or codechef IDE …

Believe me you need patience but this works for 70-80% of the time…

Good Luck!! … :slight_smile:

import java.io.*;
class cc1
{
public static void main(String args[])throws IOException
{
int N[]=new int[1000];
int r[]=new int[1000];
int T,i;
InputStreamReader read=new InputStreamReader(System.in);
BufferedReader br=new BufferedReader(read);
T=Integer.parseInt(br.readLine());
if(T>0 && T<1001)
{
for(i=0;i<T;i++)
{
N[i]=Integer.parseInt(br.readLine());

		if(N[i]>0 && N[i]<100001)
		{
		while( N[i] != 0 )
		{	
        r[i] = r[i] * 10;
        r[i] = r[i] + N[i]%10;
        N[i] = N[i]/10;
		}
		System.out.println(r[i]);
        }
	}
	
	
}

}

}

please check my program and tell why code chef is giving wrong answer for it
question link is-FLOW007 Problem - CodeChef

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