summaryrefslogtreecommitdiff
path: root/yaksh/stdio_evaluator.py
diff options
context:
space:
mode:
authorPrabhu Ramachandran2016-09-01 17:59:39 +0530
committerGitHub2016-09-01 17:59:39 +0530
commit01e08dd15b59ce353043d541c9be81592cda3fe0 (patch)
treeba1a9f7ffee92b79262b83fa9eb6eed303550f98 /yaksh/stdio_evaluator.py
parent27e7a443ef132e04cc5aeece7a5bf34d0687f482 (diff)
parenta4b636508d572cbe00ae8d0336c7b30494bad4a6 (diff)
downloadonline_test-01e08dd15b59ce353043d541c9be81592cda3fe0.tar.gz
online_test-01e08dd15b59ce353043d541c9be81592cda3fe0.tar.bz2
online_test-01e08dd15b59ce353043d541c9be81592cda3fe0.zip
Merge pull request #105 from adityacp/stdin_stdout_evaluator
Stdin stdout evaluators
Diffstat (limited to 'yaksh/stdio_evaluator.py')
-rw-r--r--yaksh/stdio_evaluator.py22
1 files changed, 22 insertions, 0 deletions
diff --git a/yaksh/stdio_evaluator.py b/yaksh/stdio_evaluator.py
new file mode 100644
index 0000000..4f5cfaf
--- /dev/null
+++ b/yaksh/stdio_evaluator.py
@@ -0,0 +1,22 @@
+class Evaluator(object):
+
+ def evaluate(self, user_answer, proc, expected_input, expected_output):
+ success = False
+ 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\n {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(repr(user_output))
+ else:
+ err = "Error:"+"\n"+output_err
+ return success, err