diff options
author | maheshgudi | 2016-06-08 11:18:52 +0530 |
---|---|---|
committer | adityacp | 2016-07-27 22:52:23 +0530 |
commit | 53192a5f757064b9f8873ea3fcfc7f9cd01e587c (patch) | |
tree | e14bc50d6b4ae771b72b3453f24525f6f4860620 /yaksh/stdio_evaluator.py | |
parent | d14bf131d60af6eae6c3ff6ce5537af25420c314 (diff) | |
download | online_test-53192a5f757064b9f8873ea3fcfc7f9cd01e587c.tar.gz online_test-53192a5f757064b9f8873ea3fcfc7f9cd01e587c.tar.bz2 online_test-53192a5f757064b9f8873ea3fcfc7f9cd01e587c.zip |
made changes to stdio evaluator and added bash evaluator with test cases
Diffstat (limited to 'yaksh/stdio_evaluator.py')
-rw-r--r-- | yaksh/stdio_evaluator.py | 21 |
1 files changed, 10 insertions, 11 deletions
diff --git a/yaksh/stdio_evaluator.py b/yaksh/stdio_evaluator.py index 037ad3d..236c0ab 100644 --- a/yaksh/stdio_evaluator.py +++ b/yaksh/stdio_evaluator.py @@ -1,23 +1,22 @@ class Evaluator(object): - def evaluate(self, user_answer, proc, expected_input, expected_output): + success = False - if expected_input: - ip = expected_input.replace(",", " ") - proc.stdin.write('{0}\n'.format(ip)) - error_msg = " Given Input is {0} \n Expected Output is {1} ".\ - format(expected_input, expected_output) - else: - error_msg = "Expected output is {0}".format(expected_output) - output_err = proc.stderr.read() - user_output = proc.stdout.read() + ip = expected_input.replace(",", " ") + user_output, output_err = proc.communicate(input='{0}\n'.format(ip)) expected_output = expected_output.replace("\r", "") + if not expected_input: + error_msg = "Expected Output is {0} ".\ + format(repr(expected_output)) + else: + error_msg = " Given Input is {0} \n Expected Output is {1} ".\ + format(expected_input, repr(expected_output)) if output_err == '': if user_output == expected_output: success, err = True, "Correct Answer" else: err = " Incorrect Answer\n" + error_msg +\ - "\n Your output is {0}".format(user_output) + "\n Your output is {0}".format(repr(user_output)) else: err = "Error:"+"\n"+output_err return success, err |