diff options
author | adityacp | 2016-06-02 14:24:57 +0530 |
---|---|---|
committer | adityacp | 2016-07-27 22:52:23 +0530 |
commit | f5ea9ecf903360c2860293639d1c6ba7a78b2339 (patch) | |
tree | 05d7b2c516851874d82b1c14efdd52b5945316fc /yaksh/stdio_evaluator.py | |
parent | 344e1e804cee214c0d0f5c41ca16d871e786d4c3 (diff) | |
download | online_test-f5ea9ecf903360c2860293639d1c6ba7a78b2339.tar.gz online_test-f5ea9ecf903360c2860293639d1c6ba7a78b2339.tar.bz2 online_test-f5ea9ecf903360c2860293639d1c6ba7a78b2339.zip |
c,cpp,java evaluators with test cases
Diffstat (limited to 'yaksh/stdio_evaluator.py')
-rw-r--r-- | yaksh/stdio_evaluator.py | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/yaksh/stdio_evaluator.py b/yaksh/stdio_evaluator.py new file mode 100644 index 0000000..037ad3d --- /dev/null +++ b/yaksh/stdio_evaluator.py @@ -0,0 +1,23 @@ +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() + expected_output = expected_output.replace("\r", "") + 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) + else: + err = "Error:"+"\n"+output_err + return success, err |