How Does my Batch-Testing for CodeForces Application work
By Asim Krishna Prasad
Posted on 13/02/15
Tag :
Project
Let's first get the outline of the things that we need to do to make the application work. Coding part is not that tough. So let's list the things that are needed to be done for the application to work.
If you want to read the ReadMe file of the application, refer THIS POST
If you want to read about the V.1.0 of application, refer THIS POST
- Get the test-cases from codeforces for a particular round
- The test-cases should be saved in such a way so that we can run the .exe and match the outputs
- The test-cases should be downloaded in a clean format so that the user doesn't get messed up
- A way to compile the program and convert it to an executable
- A text-editor which allows our application to run the executables on desired key-strokes
The first challenge is to get the test cases from the CodeForces website and save them in a way which allows us to run an .exe file easily and match the outputs. What my application does is, use requests to make HTTP connection to the problem-set page of a particular round and then use BeautifulSoup to get the test-cases separately. These test cases are saved in their respective problem-folders in separate text-files. There is also a feature of template code which allows the user to have a template code for the solutions. This template code is transferred to all the problem-folders.
The next task is to compile the code and make executable. For that there is a requisite that the host-system has a g++-compiler installed and working. For this task I chose Sublime to integrate my application with. There is a custom sublime-build file which is needed to be fed into the host-system. What it does is, make an .exe file of the source file of the user and then run it on each of the input files while matching them with the correct-output files. All the inputs and outputs are shown on a cmd window. Once this testing is done, you can go on and submit your code.
For a better understanding of the application we need to understand the use of each source file. You can find all the source files here
-
start.bat
It is the batch file which drives the entire application. It first takes the round number as the input and passes it to the ini.exe. After ini.exe has completed it's task, start.bat opens the contest-folder in Sublime, and opens the template for the first problem, after that it opens the Problems-Webpage in the default browser and ends.
-
ini.exe
ini.exe is the executable format of the python script ini.py. The python script ini.py uses requests and BeautifulSoup to fetch the data from the CodeForces site. The driver batch file, start.bat, passes the round number to the python script so that the script fetches the problems of the required round. ini.exe also makes the folders, according to the question numbers, and puts the test-cases as well as the template code into them. Another bat file, f.bat is also transferred to all the folders.
-
f.bat
This batch file holds the responsibility to run the .exe file generated by the program of the user on all the test-files and show the outputs with verdicts, in a cmd-window.
-
template.cpp
This file is to allow user to set a template code for his solutions. This code will be transferred to each problem-folder as prog.cpp
-
CF.sublime-build
This is the sublime-build file. This is a custom build which compiles cpp code and makes an exe file on Ctrl+B, and runs the f.bat file on Ctrl+Shift+B.
Hope it helps :)
Asim Krishna Prasad
COMMENTS :