summaryrefslogtreecommitdiff
path: root/yaksh/stdio_evaluator.py
diff options
context:
space:
mode:
Diffstat (limited to 'yaksh/stdio_evaluator.py')
-rw-r--r--yaksh/stdio_evaluator.py23
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