Test Case Generator and Answer

General topic about Valladolid Online Judge

Moderator: Board moderators

Post Reply
scruff
New poster
Posts: 29
Joined: Wed Dec 24, 2003 5:22 am

Test Case Generator and Answer

Post by scruff »

Hello, I just started programming here and noticed some people having trouble on different problems. So I decided to make a test case generator and answer program. So far I've only created one for problem 101.

If you would like to test your programs I believe this will be the best way. Instead of submitting and then wondering why your solution is wrong. This gives output in the correct manner and also shows how each command affects the blocks.

Here is a sample output:
.
.
.
pile 0 over 18
0:
1: 1
2: 2
3: 3
4: 4
5: 5
6: 6
7: 7
8: 8
9: 9
10: 10
11: 11
12: 12
13: 13
14: 14
15: 15
16: 16
17: 17
18: 18 0
19: 19
20: 20
21: 21
22: 22
23: 23
24: 24
move 2 onto 15
0:
1: 1
2:
3: 3
4: 4
5: 5
6: 6
7: 7
8: 8
9: 9
10: 10
11: 11
12: 12
13: 13
14: 14
15: 15 2
16: 16
17: 17
18: 18 0
19: 19
20: 20
21: 21
22: 22
23: 23
24: 24
move 7 over 13
0:
1: 1
2:
3: 3
4: 4
5: 5
6: 6
7:
8: 8
9: 9
10: 10
11: 11
12: 12
13: 13 7
14: 14
15: 15 2
16: 16
17: 17
18: 18 0
19: 19
20: 20
21: 21
22: 22
23: 23
24: 24
.
.
.
You can just place this executable in your directory where your program resides and run it once to give you a random command input file named "p101.in" and then it will give you the output file "p101.out" as the answer. So all you have to do is read from the input file and then compare your output to that of output file. Once you get your program to get the same the same answer as in the output file, then you can run the executable again to give you another random input file.

Anywho, you can pick the executable up:

http://people.eecs.ku.edu/~rucker/valladolid/p101.exe

I don't have a whole bunch of time to do this sort of thing to all of the problems but I believe this is a good way to help find bugs. So if you would like to help the cause please drop me an email address or private message me.

Thank you
scruff
New poster
Posts: 29
Joined: Wed Dec 24, 2003 5:22 am

Post by scruff »

I just finished a test generator and answer executable for problem 100.

http://people.eecs.ku.edu/~rucker/valladolid/p100.exe

enjoy.
scruff
New poster
Posts: 29
Joined: Wed Dec 24, 2003 5:22 am

Post by scruff »

shamim
A great helper
Posts: 498
Joined: Mon Dec 30, 2002 10:10 am
Location: Bozeman, Montana, USA

Post by shamim »

Good Job, keep it up.

Advice: Try to generate for problems whose input file is difficult to create, such as problem 517 and some geometric problem.
scruff
New poster
Posts: 29
Joined: Wed Dec 24, 2003 5:22 am

Post by scruff »

I was just putting them up as I finished them. As I said I don't have much time to do this... and so it will be a slow process. If you would like to help the community and I would greatly appreciate it. You are correct though. I believe it would be far better to think of troublsome problems with tricky inputs, and create a generator for those problems. Also it would be better to think of interesting inputs to really test your program rather than just random inputs that could cause problems but most of the time will not.

Thanks for your response though.
scruff
New poster
Posts: 29
Joined: Wed Dec 24, 2003 5:22 am

Post by scruff »

Here's problem 103 test case generator and answer. I changed the output to be a little bit more descriptive in this one because the answer is just one of a possible few answers that might not match your solution. Here's an input and sample output
input
10 6
4 94 77 59 79 34
92 98 30 74 53 69
53 45 13 85 38 17
34 93 11 18 54 65
29 74 66 77 56 60
79 18 19 48 27 3
72 79 43 41 58 99
95 97 1 50 70 91
45 38 75 11 74 1
77 39 58 33 74 17
output
sorted input
9 : 1 11 38 45 74 75
8 : 1 50 70 91 95 97
6 : 3 18 19 27 48 79
1 : 4 34 59 77 79 94
4 : 11 18 34 54 65 93
3 : 13 17 38 45 53 85
10 : 17 33 39 58 74 77
5 : 29 56 60 66 74 77
2 : 30 53 69 74 92 98
7 : 41 43 58 72 79 99
output
2
10 7
Anywho... enjoy!

http://people.eecs.ku.edu/~rucker/valladolid/p103.exe
scruff
New poster
Posts: 29
Joined: Wed Dec 24, 2003 5:22 am

Post by scruff »

here is the test case generator for problem 104

http://people.eecs.ku.edu/~rucker/valladolid/p104.exe

happy coding.
scruff
New poster
Posts: 29
Joined: Wed Dec 24, 2003 5:22 am

Post by scruff »

About 25 lines of code and 10 minutes and here is test generator for 105.

http://people.eecs.ku.edu/~rucker/valladolid/p105.exe

Happy Coding!
Plasdom
New poster
Posts: 2
Joined: Fri Jan 30, 2004 9:26 pm

Post by Plasdom »

My code passed your tests but failed the Judge's tests. Might want to check yours again. Problem 102
Plasdom
New poster
Posts: 2
Joined: Fri Jan 30, 2004 9:26 pm

Post by Plasdom »

Here's my code. Might help you fix it.

[cpp]#include <iostream>
#include <string>

using namespace std;

int main()
{
long cheapest_path = 0;
long temp = 0;
long bin1[3];
long bin2[3];
long bin3[3];
string str= " ";

while (cin >> bin1[0])
{
for (long i=1; i<3; i++)
cin >> bin1;
for (long i=0; i<3; i++)
cin >> bin2;
for (long i=0; i<3; i++)
cin >> bin3;

//GBC
temp = (bin2[1] + bin3[1] + bin1[0] + bin3[0] + bin1[2] + bin2[2]);
str = "GBC";
cheapest_path = temp;

//GCB
temp = (bin2[1] + bin3[1] + bin1[2] + bin3[2] + bin1[0] + bin2[0]);
if (cheapest_path >= temp)
{
if (cheapest_path == temp)
str = "GCB";
else
{
cheapest_path = temp;
str = "GCB";
}
}

//CBG
temp = (bin2[2] + bin3[2] + bin1[0] + bin3[0] + bin1[1] + bin2[1]);
if (cheapest_path >= temp)
{
if (cheapest_path == temp)
str = "CBG";
else
{
cheapest_path = temp;
str = "CBG";
}
}

//CGB
temp = (bin2[2] + bin3[2] + bin1[1] + bin3[1] + bin1[0] + bin2[0]);
if (cheapest_path > temp)
{
if (cheapest_path == temp)
str = "CGB";
else
{
cheapest_path = temp;
str = "CGB";
}
}

//BGC
temp = (bin2[0] + bin3[0] + bin1[1] + bin3[1] + bin1[2] + bin2[2]);
if (cheapest_path >= temp)
{
if (cheapest_path == temp)
string str = "BGC";
else
{
cheapest_path = temp;
str = "BGC";
}
}
//BCG
temp = (bin2[0] + bin3[0] + bin1[2] + bin3[2] + bin1[1] + bin2[1]);
if (cheapest_path >= temp)
{
if (cheapest_path == temp)
str = "BCG";
else
{
cheapest_path = temp;
str = "BCG";
}
}
cout << str << " " << cheapest_path << endl;
}
}[/cpp]
Farqaleet
New poster
Posts: 15
Joined: Wed Jan 28, 2004 11:24 pm

Post by Farqaleet »

Hey Scruff. Can you please either reduce the size of the downloadables or put the source on the website. I think that you are putting debug versions on the web. Please produce some release versions so that the size is reduced comsiderably. below 100 kb is good enough. Half an MB is way too big for anyone's liking. It also arises some suspicions as to what the executable does.
scruff
New poster
Posts: 29
Joined: Wed Dec 24, 2003 5:22 am

Post by scruff »

Plasdom: The program creates a random input and creates the solution to that input. I have not gone through and thought of tricky inputs as this takes a while for each problem and I have other things to do. If your program passes one set of inputs then just run the program again to get another set of inputs. Try it a few times before submittiing. I've lowered the randomization to make it cause differences more now if you would like to try it again. It seems to me that your code does not print out the correct solution for ties though. You should switch all your statements around and you also will save some code this way(ie the inner if statements)

[cpp]#include <iostream>
#include <string>

using namespace std;

int main()
{
long cheapest_path = 0;
long temp = 0;
long bin1[3];
long bin2[3];
long bin3[3];
string str= " ";

while (cin >> bin1[0])
{
for (long i=1; i<3; i++)
cin >> bin1;
for (long i=0; i<3; i++)
cin >> bin2;
for (long i=0; i<3; i++)
cin >> bin3;

//BCG
cheapest_path= temp = (bin2[0] + bin3[0] + bin1[2] + bin3[2] + bin1[1] + bin2[1]);
str="BCG";

//BGC
temp = (bin2[0] + bin3[0] + bin1[1] + bin3[1] + bin1[2] + bin2[2]);
if (cheapest_path > temp){
cheapest_path = temp;
str = "BGC";
}

//CBG
temp = (bin2[2] + bin3[2] + bin1[0] + bin3[0] + bin1[1] + bin2[1]);
if (cheapest_path > temp)
{
cheapest_path = temp;
str = "CBG";
}

//CGB
temp = (bin2[2] + bin3[2] + bin1[1] + bin3[1] + bin1[0] + bin2[0]);
if (cheapest_path > temp)
{
cheapest_path = temp;
str = "CGB";
}

//GBC
temp = (bin2[1] + bin3[1] + bin1[0] + bin3[0] + bin1[2] + bin2[2]);
if(cheapest_path>temp){
str = "GBC";
cheapest_path = temp;
}

//GCB
temp = (bin2[1] + bin3[1] + bin1[2] + bin3[2] + bin1[0] + bin2[0]);
if (cheapest_path > temp){
cheapest_path = temp;
str = "GCB";
}

cout << str << " " << cheapest_path << endl;
}
}[/cpp]

Farqaleet: You are correct the programs are too big. I have lowered them to around 150kb. Hope this is good enough.

You can find the new exe's here.
http://people.eecs.ku.edu/~rucker/valladolid/

Thank you for your inputs. I wasn't sure if people were actually going to use these things.

Happy coding.
Farqaleet
New poster
Posts: 15
Joined: Wed Jan 28, 2004 11:24 pm

Some easy to go code with Scruff's sample inputs

Post by Farqaleet »

Here is some handy code I wrote for my self when I used Scruff's input files as my sample tests. I hope that this will come handy to many.

Thanx scruff, your inputs really helped me get the problems right as I had the right data to test for. :D

[cpp]
/* Use cin and cout as you normally do in your programs. Place the sample input and output
from scruff into your programs directory, compile it and run it. If it works simply submit all the code to the judge.
. It is better to include all this code in a header file, place it in your compilers include directory and use it as any other header file except to always include it in #ifndef ONLINE_JUDGE directive because the judge wouldn't have that file.
*/

#ifndef ONLINE_JUDGE

#include <fstream.h>

#define cin __inputs.fin /* If you change these then you have to uncomment and change the else portion */
#define cout __inputs.fout /* same case here, but why would you do that */

#define PROBLEM "100" /* The Problem Number */

#define EXAMPLE_INPUT PROBLEM ".in" /* Your own or Judge's Sample input */
#define OUTPUT_FILE PROBLEM ".out" /* Your programs output */

#define INPUT_FILE "p" PROBLEM ".in" /* scruff's input file */
#define CORRECT_FILE "p" PROBLEM ".out" /* scruff's output file */

#define TEST_OUTPUT __inputs.Test(); /* Place this just before end of main to test output */
/* This just example code that checks character for character */
/* If you want robust code, write your self and send it to us too */

class CInputs
{
public:
ifstream fin;
ofstream fout;
CInputs()
{
fin.open(INPUT_FILE);
fout.open(OUTPUT_FILE, ios::out | ios::trunc);
}
~CInputs()
{
fin.close();
fout.close();
}

int Test()
{
ifstream imyfile(OUTPUT_FILE);
ifstream ioutfile(CORRECT_FILE);
unsigned long nMine, nCorrect;
while(imyfile>>nMine || ioutfile>>nCorrect)
if(nMine!=nCorrect)
return 0;
imyfile.close();
ioutfile.close();
}
};

CInputs __inputs; /* if you add all this in a single header for easy inclusion do not forget to enclose the header inclusion within an ifndef ONLINE_JUDGE */

#else
/* Change IN and OUT to whatever you change the "cin" and "cout" to on the top 2 defines*/
/*
#define IN cin
#define OUT cout
*/
#endif


[/cpp]
Post Reply

Return to “General”