summaryrefslogtreecommitdiff
path: root/yaksh
diff options
context:
space:
mode:
Diffstat (limited to 'yaksh')
-rw-r--r--yaksh/bash_stdio_evaluator.py17
-rw-r--r--yaksh/cpp_stdio_evaluator.py15
-rw-r--r--yaksh/java_stdio_evaluator.py14
-rw-r--r--yaksh/python_stdio_evaluator.py4
-rw-r--r--yaksh/stdio_evaluator.py20
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