diff options
author | maheshgudi | 2017-11-06 16:34:37 +0530 |
---|---|---|
committer | maheshgudi | 2017-11-07 14:50:09 +0530 |
commit | 70a35ac2a001bd9638d9db5ed645d00f94ae4666 (patch) | |
tree | d404d9f9413b25fcc224fe3dea15eee1bc8ca88d /yaksh/compare_stdio.py | |
parent | 72b3d672735f624064431cbb0751d3cc3b08b6ba (diff) | |
download | online_test-70a35ac2a001bd9638d9db5ed645d00f94ae4666.tar.gz online_test-70a35ac2a001bd9638d9db5ed645d00f94ae4666.tar.bz2 online_test-70a35ac2a001bd9638d9db5ed645d00f94ae4666.zip |
Change module compare_stdio to error_messages
Diffstat (limited to 'yaksh/compare_stdio.py')
-rw-r--r-- | yaksh/compare_stdio.py | 44 |
1 files changed, 0 insertions, 44 deletions
diff --git a/yaksh/compare_stdio.py b/yaksh/compare_stdio.py deleted file mode 100644 index 9c13a98..0000000 --- a/yaksh/compare_stdio.py +++ /dev/null @@ -1,44 +0,0 @@ -try: - from itertools import zip_longest -except ImportError: - from itertools import izip_longest as zip_longest - - -def _get_incorrect_user_lines(exp_lines, user_lines): - err_line_numbers = [] - for line_no, (expected_line, user_line) in \ - enumerate(zip_longest(exp_lines, user_lines)): - if not user_line or not expected_line or \ - user_line.strip() != expected_line.strip(): - err_line_numbers.append(line_no) - return err_line_numbers - -def compare_outputs(expected_output, user_output, given_input=None): - given_lines = user_output.splitlines() - exp_lines = expected_output.splitlines() - msg = {"given_input":given_input, - "expected_output": exp_lines, - "user_output":given_lines, - "type": "stdio" - } - ng = len(given_lines) - ne = len(exp_lines) - err_line_numbers = _get_incorrect_user_lines(exp_lines, given_lines) - msg["error_line_numbers"] = err_line_numbers - if ng != ne: - msg["error_msg"] = ("Incorrect Answer: " - + "We had expected {} number of lines. ".format(ne) - + "We got {} number of lines.".format(ng) - ) - return False, msg - else: - if err_line_numbers: - msg["error_msg"] = ("Incorrect Answer: " - + "Line number(s) {0} did not match." - .format(", ".join(map( - str,[x+1 for x in err_line_numbers] - )))) - return False, msg - else: - msg["error_msg"] = "Correct Answer" - return True, msg |