...and decided to post your code and ask for more test inputs/outputs, you will probably find this thing useful:
[cpp]
#include <cstdlib>
#include <fstream>
#include <iostream>
using namespace std;
class Autotester{
public:
virtual void generate_test(ofstream&) = 0;
virtual void run_test();
virtual bool check_if_results_matched(ifstream&, ifstream&);
};
/******** cfg section ********/
const int number_of_tests=100;
const char* ac_launch_command = "ac.exe <in.txt >out1.txt";
const char* wa_launch_command = "wa.exe <in.txt >out2.txt";
// if you need global variables,
// declare them here
class TestGeneratorAndChecker : public Autotester{
private:
// any data you need to generate tests
// and check results
public:
void generate_test(ofstream& out){
// this function will be called number_of_tests times;
// it must generate test data and write it to its parameter,
// which is associated with in.txt file
}
/* virtual bool check_if_results_matched(
ifstream& ac_result, ifstream& wa_result)
// after calling generate_test, Autotester
// passes generated input data to both programs by
// executing ac_launch_command and wa_launch_command;
// Autotester assumes that executing these commands
// will generate files out1.txt and out2.txt, containing
// AC program's and your program's output.
// After that, these files will be opened and passed
// to check_if_results_matched function.
// This function must compare these files and
// return true if they are equivalent.
// Default implementation should be overloaded
// only for problems with special correction program.
// if this function return false, Autotester will print
// "mismatch!" and exit, leaving test data in in.txt,
// AC program output in out1.txt and your program
// output in out2.txt
} */
};
/***** end of cfg section *****/
bool Autotester::check_if_results_matched(
ifstream& ac_result, ifstream& wa_result){
while(!ac_result.eof() && !wa_result.eof()){
if(ac_result.get()!=wa_result.get())
return false;
}
return (ac_result.eof()==wa_result.eof());
}
void Autotester::run_test(){
system(ac_launch_command);
system(wa_launch_command);
}
int main(){
randomize(); // in case someone'll forget...
Autotester* tester = new TestGeneratorAndChecker;
for(int i=0; i<number_of_tests; i++){
cout<<'.';
ofstream testfile("in.txt");
tester->generate_test(testfile);
testfile.close();
tester->run_test();
ifstream ac_result("out1.txt");
ifstream wa_result("out2.txt");
bool tmp =
tester->check_if_results_matched(ac_result, wa_result);
ac_result.close(); wa_result.close();
if(!tmp){
cout<<"\nmismatch!\n";
break;
}
}
delete tester;
}
[/cpp]
You can overload generate_test(ofstream&) and probably check_if_results_matched(ifstream&, ifstream&) and post them with your code. Then someone who is willing to help can place your program to wa.cpp, his/her accepted program to ac.cpp, that code above to tester.cpp (Java will probably require some code editing and modification of launch commands), compile them and generate/launch many tests with a single command (probably several hundreds random tests; useful if your program generates WA only in few very special cases which you cannot find). Takes far less time than re-reading problem statement, analysing your program, composing tests, typing them in and comparing outputs.
(Autotester) If you keep getting WA
Post here if you don't find any other place for your post. But please, stay on-topic: algorithms, programming or something related to this web site and its services.
Moderator: Board moderators
-
- New poster
- Posts: 15
- Joined: Fri Aug 08, 2003 8:13 pm
- Location: Russia, Moscow
- Contact:
(Autotester) If you keep getting WA
Post by Ruslan Shevelyov »
www.Find-a-Drug.org distributed computing project
Jump to
- Real Time Contests and Last Minute Information
- ↳ General
- ↳ Real Time Clarification
- ↳ Fixing Mistakes
- ↳ HOWTOs
- ↳ Bugs and suggestions
- New system
- ↳ FAQ
- ↳ Bugs and suggestions
- Let's make some programs!
- ↳ Other words
- ↳ Algorithms
- ↳ New features
- Help on the Problemset
- ↳ Volume 1 (100-199)
- ↳ Volume 2 (200-299)
- ↳ Volume 3 (300-399)
- ↳ Volume 4 (400-499)
- ↳ Volume 5 (500-599)
- ↳ Volume 6 (600-699)
- ↳ Volume 7 (700-799)
- ↳ Volume 8 (800-899)
- ↳ Volume 9 (900-999)
- ↳ Volume 10 (1000-1099)
- ↳ Volume 11 (1100-1199)
- ↳ Volume 12 (1200-1299)
- ↳ Volume 13 (1300-1399)
- ↳ Volume 14 (1400-1499)
- ↳ Volume 15 (1500-1599)
- ↳ Volume 16 (1600-1699)
- ↳ Volume 17 (1700-1799)
- ↳ Volume 100 (10000-10099)
- ↳ Volume 101 (10100-10199)
- ↳ Volume 102 (10200-10299)
- ↳ Volume 103 (10300-10399)
- ↳ Volume 104 (10400-10499)
- ↳ Volume 105 (10500-10599)
- ↳ Volume 106 (10600-10699)
- ↳ Volume 107 (10700-10799)
- ↳ Volume 108 (10800-10899)
- ↳ Volume 109 (10900-10999)
- ↳ Volume 110 (11000-11099)
- ↳ Volume 111 (11100-11199)
- ↳ Volume 112 (11200-11299)
- ↳ Volume 113 (11300-11399)
- ↳ Volume 114 (11400-11499)
- ↳ Volume 115 (11500-11599)
- ↳ Volume 116 (11600-11699)
- ↳ Volume 117 (11700-11799)
- ↳ Volume 118 (11800-11899)
- ↳ Volume 119 (11900-11999)
- ↳ Volume 120 (12000-12099)
- ↳ Volume 121 (12100-12199)
- ↳ Volume 122 (12200-12299)
- ↳ Volume 123 (12300-12399)
- ↳ Volume 124 (12400-12499)
- ↳ Volume 125 (12500-12599)
- ↳ Volume 126 (12600-12699)
- ↳ Volume 127 (12700-12799)
- ↳ Volume 128 (12800-12899)
- ↳ Volume 129 (12900-12999)
- ↳ Volume 130 (13000-13099)
- ↳ Volume 131 (13100-13199)
- Help on languages
- ↳ C
- ↳ C++
- ↳ Pascal
- ↳ Java
- Off Topic
- ↳ Off topic (General chit-chat)
- Category
- ↳ ACM ICPC Archive Board