Closed Enigmage closed 3 years ago
@Enigmage - needs a lot of refactoring and improvements, but still merging it because NWoC is over. I've already given you points for this. Thanks for contributing !
@ankingcodes you're right the code can be improved a lot still, I would have done it but I became pretty busy with university stuff, so apologies for that. I just hope there weren't any logical errors or bugs in the new feature added ?
Also, thank you so much for allowing me to contribute to this awesome project idea, I really enjoyed it and learned a lot from it. This tool is very useful and has great potential, I'd love to contribute to this project even in the future as much as I can if that's okay with you. Do ping me on gitter if there is anything I can help you with.
Closes #18
Work done in this PR:
Changes/additions:
Adds optimizations in codemon listen for sample testcases. Now, if the
test_case
(user input ) file is empty, codemon will check the.op
and.in
files of the particular problem for sample testcases and, if they exist, run the program with those sample test cases. In case the output is wrong it will show a diffed output to show the changes needed in the current output to match the expected output. In case no inputs exist, it will show a message and simply run the program without writing anything to the stdin.This PR also handles an edge case. In older codeforces contests and in few problems in newer contests, instead of having a testcase loop, multiple testcases are written separately in some problems. For example in contest_160 and Problem_G in contest 1455 this can be observed. So in this case the program needs to be executed multiple times for each testcase. Changes made to handle this issue:
clean_file_content
ensure that these newlines don't create any issue at the compilation or execution step of the program and also while diffing the current and expected output. Functionget_inputs_and_outputs
returns inputs and outputs in list format, each index being a separate testcase, separate testcases are identified by newline character.( NOTE: This also adds a very good new feature. In case the user wants to test such programs (with no testcase loop) with their own custom testcases, usually they would have to execute the program again and again for each test case. But now, with this, all they have to do is just write their custom cases in the
test_case
file, as many as they like which are separated by at least one newline, and codemon will automatically execute the program multiple times for each test case and show the output. This will be very convenient for the users as with codemon they will be able to take advantage of a testcase loop even on codeforces problems that don't have them. )clean_file_content
function ensures that any extra newlines at the end of I/O files or at beginning or in between separate testcases cause no issue at all in the working of codemon. So even if the user mistakenly input extra newlines intest_case
file before or after their custom testcase, it won't cause any issue.Additional changes:
While testing I noticed that in older codeforces contests (like 160) the sample input and output divs don't have
\n
character, instead they have the<br/>
tag to represent a new line in testcases. This was causing issues as codemon fetch did not check for that. So I've added a backward compatible method that handles this scenario and writes the newline character in case these tags are present. So if the user wants to virtual participate any older contests, they should have no problem doing so.Added support for python. So all the functionality mentioned will also work with python files.
Codebase changes:
CodemonListen
Module, I have added a classRunner
that wraps up similar functionality for running programs with inputs and outputs. This provides a clean interface for adding support for new languages as the common parts of running a program of any language (like getting inputs and displaying outputs) are their own separate functions. This way only thesubprocess
part for each new language will be different and rest of the functionality can be easily shared, avoiding code duplicationFixes
CodemonMeta
module. Header was being appended to template without checking if the template is None or not, so in the case there was no default template added by the user, it would cause error as None type and str type cannot be concatenated. So I added a conditional to check if the template is none or not, only when its not none this header is concatenated.Work left out: