Skip to content

Commit

Permalink
Improve checking code.
Browse files Browse the repository at this point in the history
  • Loading branch information
hassansalehe committed Feb 20, 2017
1 parent e5d3401 commit 6c64cab
Showing 1 changed file with 16 additions and 13 deletions.
29 changes: 16 additions & 13 deletions src/CheckOutput.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,37 +13,40 @@ int main(int argc, char * argv[]) {

FILE * res_fd;
char holder[20];
const char * program = argv[1];
std::string program = "./"; program.append( argv[1] );

int numRuns = atoi( argv[2] );
int expectedResult = atoi( argv[3] );

int numCorrect = 0;

for(int i = 0; i < numRuns; i++) {
res_fd = popen(argv[1], "r");
res_fd = popen( program.c_str(), "r" );

if( !res_fd ) {
std::cerr << "Something wrong happened" << std::endl;
return 1; // something wrong happened
std::cerr << "Something wrong happened while executing your program" << std::endl;
return 1;

}

int bytes = fread(holder, 1, sizeof(holder), res_fd);
int result = atoi(holder);
int bytes = fread( holder, 1, sizeof( holder ), res_fd );
int result = atoi( holder );

if( result = expectedResult )
if( result == expectedResult )
numCorrect++;
pclose(res_fd);
pclose( res_fd );

std::cout << "run " << i+1 << "/" << numRuns << "\r";

//std::cout <<"bytes: " << bytes << " result "<< result << std::endl;
}
std::cout << "\r";

std::cout << "program: " << program << std::endl
<< "# of runs: " << numRuns << std::endl
<< "correct runs: " << numCorrect << "(" << (numCorrect*100/numRuns) << "%)" << std::endl;
std::cout << "program: " << program << std::endl
<< "# of runs: " << numRuns << std::endl
<< "correct runs: " << numCorrect << "("
<< ( numCorrect * 100 / numRuns ) << "%)" << std::endl;

return 0;
}

std::cout << argv[1] << " " << numRuns << " " << expectedResult << std::endl;
}

0 comments on commit 6c64cab

Please sign in to comment.