diff options
author | maheshgudi | 2016-09-26 18:15:04 +0530 |
---|---|---|
committer | maheshgudi | 2016-09-26 18:15:04 +0530 |
commit | ed46c4a2cf6bbf41f50faafc785f001e3d10d195 (patch) | |
tree | 7b9175135c6b66702dcdb03b1eaa34b63e6f2855 | |
parent | 0845f5f67aabd311a4b0bf70d099be07d688bb80 (diff) | |
download | online_test-ed46c4a2cf6bbf41f50faafc785f001e3d10d195.tar.gz online_test-ed46c4a2cf6bbf41f50faafc785f001e3d10d195.tar.bz2 online_test-ed46c4a2cf6bbf41f50faafc785f001e3d10d195.zip |
refactored stdio_evaluator
-rw-r--r-- | yaksh/bash_stdio_evaluator.py | 17 | ||||
-rw-r--r-- | yaksh/cpp_stdio_evaluator.py | 15 | ||||
-rw-r--r-- | yaksh/java_stdio_evaluator.py | 14 | ||||
-rw-r--r-- | yaksh/python_stdio_evaluator.py | 4 | ||||
-rw-r--r-- | yaksh/stdio_evaluator.py | 20 |
5 files changed, 39 insertions, 31 deletions
diff --git a/yaksh/bash_stdio_evaluator.py b/yaksh/bash_stdio_evaluator.py index 56f2e35..8ff0743 100644 --- a/yaksh/bash_stdio_evaluator.py +++ b/yaksh/bash_stdio_evaluator.py @@ -3,12 +3,12 @@ import subprocess import os from os.path import isfile -#local imports -from code_evaluator import CodeEvaluator -from stdio_evaluator import Evaluator +# local imports +from stdio_evaluator import StdIOEvaluator from file_utils import copy_files, delete_files -class BashStdioEvaluator(CodeEvaluator): + +class BashStdioEvaluator(StdIOEvaluator): """Evaluates Bash StdIO based code""" def setup(self): @@ -41,9 +41,8 @@ class BashStdioEvaluator(CodeEvaluator): stdout=subprocess.PIPE, stderr=subprocess.PIPE ) - evaluator = Evaluator() - success, err = evaluator.evaluate(user_answer, proc, - expected_input, - expected_output - ) + success, err = self.evaluate_stdio(user_answer, proc, + expected_input, + expected_output + ) return success, err diff --git a/yaksh/cpp_stdio_evaluator.py b/yaksh/cpp_stdio_evaluator.py index 4ea1bbf..720ed0f 100644 --- a/yaksh/cpp_stdio_evaluator.py +++ b/yaksh/cpp_stdio_evaluator.py @@ -4,12 +4,12 @@ import os from os.path import isfile #local imports -from code_evaluator import CodeEvaluator -from stdio_evaluator import Evaluator + +from stdio_evaluator import StdIOEvaluator from file_utils import copy_files, delete_files -class CppStdioEvaluator(CodeEvaluator): +class CppStdioEvaluator(StdIOEvaluator): """Evaluates C StdIO based code""" def setup(self): @@ -76,11 +76,10 @@ class CppStdioEvaluator(CodeEvaluator): stdout=subprocess.PIPE, stderr=subprocess.PIPE ) - evaluator = Evaluator() - success, err = evaluator.evaluate(user_answer, proc, - expected_input, - expected_output - ) + success, err = self.evaluate_stdio(user_answer, proc, + expected_input, + expected_output + ) os.remove(self.ref_output_path) else: err = "Error:" diff --git a/yaksh/java_stdio_evaluator.py b/yaksh/java_stdio_evaluator.py index 27dd4a9..f4b8773 100644 --- a/yaksh/java_stdio_evaluator.py +++ b/yaksh/java_stdio_evaluator.py @@ -4,12 +4,11 @@ import os from os.path import isfile #local imports -from code_evaluator import CodeEvaluator -from stdio_evaluator import Evaluator +from stdio_evaluator import StdIOEvaluator from file_utils import copy_files, delete_files -class JavaStdioEvaluator(CodeEvaluator): +class JavaStdioEvaluator(StdIOEvaluator): """Evaluates Java StdIO based code""" def setup(self): @@ -61,11 +60,10 @@ class JavaStdioEvaluator(CodeEvaluator): stdout=subprocess.PIPE, stderr=subprocess.PIPE ) - evaluator = Evaluator() - success, err = evaluator.evaluate(user_answer, proc, - expected_input, - expected_output - ) + success, err = self.evaluate_stdio(user_answer, proc, + expected_input, + expected_output + ) os.remove(self.user_output_path) else: err = "Compilation Error:" diff --git a/yaksh/python_stdio_evaluator.py b/yaksh/python_stdio_evaluator.py index 4a02267..2cfd9c8 100644 --- a/yaksh/python_stdio_evaluator.py +++ b/yaksh/python_stdio_evaluator.py @@ -53,11 +53,11 @@ class PythonStdioEvaluator(CodeEvaluator): tb = None if self.output_value == expected_output: success = True - err = "Correct Answer" + err = "Correct answer" else: success = False err = dedent(""" - Incorrect Answer: + Incorrect answer: Given input - {0} Expected output - {1} Your output - {2} diff --git a/yaksh/stdio_evaluator.py b/yaksh/stdio_evaluator.py index 4f5cfaf..efb2ae5 100644 --- a/yaksh/stdio_evaluator.py +++ b/yaksh/stdio_evaluator.py @@ -1,6 +1,18 @@ -class Evaluator(object): +# Local imports +from code_evaluator import CodeEvaluator - def evaluate(self, user_answer, proc, expected_input, expected_output): + +class StdIOEvaluator(CodeEvaluator): + + def setup(self): + super(StdIOEvaluator, self).setup() + pass + + def teardown(self): + super(StdIOEvaluator, self).teardown() + pass + + def evaluate_stdio(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)) @@ -13,9 +25,9 @@ class Evaluator(object): format(expected_input, repr(expected_output)) if output_err == '': if user_output == expected_output: - success, err = True, "Correct Answer" + success, err = True, "Correct answer" else: - err = " Incorrect Answer\n" + error_msg +\ + err = " Incorrect answer\n" + error_msg +\ "\n Your output is {0}".format(repr(user_output)) else: err = "Error:"+"\n"+output_err |