From 6c64cabdf4c4a1e8a4120aa3b6e51326ec5b9101 Mon Sep 17 00:00:00 2001 From: "Hassan @VirtualBox" Date: Tue, 21 Feb 2017 01:15:23 +0300 Subject: [PATCH] Improve checking code. --- src/CheckOutput.cpp | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/src/CheckOutput.cpp b/src/CheckOutput.cpp index 4e08f51..56857b3 100644 --- a/src/CheckOutput.cpp +++ b/src/CheckOutput.cpp @@ -13,27 +13,28 @@ 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"; @@ -41,9 +42,11 @@ int main(int argc, char * argv[]) { } 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; -} \ No newline at end of file