summaryrefslogtreecommitdiff
path: root/yaksh/evaluator_tests
diff options
context:
space:
mode:
Diffstat (limited to 'yaksh/evaluator_tests')
-rw-r--r--yaksh/evaluator_tests/test_bash_evaluation.py81
-rw-r--r--yaksh/evaluator_tests/test_c_cpp_evaluation.py2
-rw-r--r--yaksh/evaluator_tests/test_java_evaluation.py2
-rw-r--r--yaksh/evaluator_tests/test_python_evaluation.py2
4 files changed, 83 insertions, 4 deletions
diff --git a/yaksh/evaluator_tests/test_bash_evaluation.py b/yaksh/evaluator_tests/test_bash_evaluation.py
index 4ff3e0a..f954ef0 100644
--- a/yaksh/evaluator_tests/test_bash_evaluation.py
+++ b/yaksh/evaluator_tests/test_bash_evaluation.py
@@ -1,9 +1,12 @@
import unittest
import os
from yaksh.bash_code_evaluator import BashCodeEvaluator
+from yaksh.bash_stdio_evaluator import BashStdioEvaluator
from yaksh.settings import SERVER_TIMEOUT
+from textwrap import dedent
-class BashEvaluationTestCases(unittest.TestCase):
+
+class BashAssertionEvaluationTestCases(unittest.TestCase):
def setUp(self):
self.test_case_data = [
{"test_case": "bash_files/sample.sh,bash_files/sample.args"}
@@ -48,5 +51,81 @@ class BashEvaluationTestCases(unittest.TestCase):
self.assertEquals(result.get("error"), self.timeout_msg)
+class BashStdioEvaluationTestCases(unittest.TestCase):
+ def setUp(self):
+ self.timeout_msg = ("Code took more than {0} seconds to run. "
+ "You probably have an infinite loop in your"
+ " code.").format(SERVER_TIMEOUT)
+
+ def test_correct_answer(self):
+ user_answer = dedent(""" #!/bin/bash
+ read A
+ read B
+ echo -n `expr $A + $B`
+ """
+ )
+ test_case_data = [{'expected_output': '11', 'expected_input': '5\n6'}]
+ get_class = BashStdioEvaluator()
+ kwargs = {"user_answer": user_answer,
+ "test_case_data": test_case_data
+ }
+ result = get_class.evaluate(**kwargs)
+ self.assertEquals(result.get('error'), "Correct Answer")
+ self.assertTrue(result.get('success'))
+
+ def test_array_input(self):
+ user_answer = dedent(""" readarray arr;
+ COUNTER=0
+ while [ $COUNTER -lt 3 ]; do
+ echo -n "${arr[$COUNTER]}"
+ let COUNTER=COUNTER+1
+ done
+ """
+ )
+ test_case_data = [{'expected_output': '1 2 3\n4 5 6\n7 8 9\n',
+ 'expected_input': '1,2,3\n4,5,6\n7,8,9'
+ }]
+ get_class = BashStdioEvaluator()
+ kwargs = {"user_answer": user_answer,
+ "test_case_data": test_case_data
+ }
+ result = get_class.evaluate(**kwargs)
+ self.assertEquals(result.get('error'), "Correct Answer")
+ self.assertTrue(result.get('success'))
+
+ def test_incorrect_answer(self):
+ user_answer = dedent(""" #!/bin/bash
+ read A
+ read B
+ echo -n `expr $A + $B`
+ """
+ )
+ test_case_data = [{'expected_output': '12', 'expected_input': '5\n6'}]
+ get_class = BashStdioEvaluator()
+ kwargs = {"user_answer": user_answer,
+ "test_case_data": test_case_data
+ }
+ result = get_class.evaluate(**kwargs)
+ self.assertIn("Incorrect", result.get('error'))
+ self.assertFalse(result.get('success'))
+
+ def test_stdout_only(self):
+ user_answer = dedent(""" #!/bin/bash
+ A=6
+ B=4
+ echo -n `expr $A + $B`
+ """
+ )
+ test_case_data = [{'expected_output': '10',
+ 'expected_input': ''
+ }]
+ get_class = BashStdioEvaluator()
+ kwargs = {"user_answer": user_answer,
+ "test_case_data": test_case_data
+ }
+ result = get_class.evaluate(**kwargs)
+ self.assertEquals(result.get('error'), "Correct Answer")
+ self.assertTrue(result.get('success'))
+
if __name__ == '__main__':
unittest.main()
diff --git a/yaksh/evaluator_tests/test_c_cpp_evaluation.py b/yaksh/evaluator_tests/test_c_cpp_evaluation.py
index 7a87d87..3d2e9fe 100644
--- a/yaksh/evaluator_tests/test_c_cpp_evaluation.py
+++ b/yaksh/evaluator_tests/test_c_cpp_evaluation.py
@@ -6,7 +6,7 @@ from yaksh.settings import SERVER_TIMEOUT
from textwrap import dedent
-class CEvaluationTestCases(unittest.TestCase):
+class CAssertionEvaluationTestCases(unittest.TestCase):
def setUp(self):
self.test_case_data = [{"test_case": "c_cpp_files/main.cpp"}]
self.in_dir = "/tmp"
diff --git a/yaksh/evaluator_tests/test_java_evaluation.py b/yaksh/evaluator_tests/test_java_evaluation.py
index fa8d68c..211b324 100644
--- a/yaksh/evaluator_tests/test_java_evaluation.py
+++ b/yaksh/evaluator_tests/test_java_evaluation.py
@@ -7,7 +7,7 @@ from yaksh.settings import SERVER_TIMEOUT
from textwrap import dedent
-class JavaEvaluationTestCases(unittest.TestCase):
+class JavaAssertionEvaluationTestCases(unittest.TestCase):
def setUp(self):
self.test_case_data = [
{"test_case": "java_files/main_square.java"}
diff --git a/yaksh/evaluator_tests/test_python_evaluation.py b/yaksh/evaluator_tests/test_python_evaluation.py
index dfdc6ec..a935f1d 100644
--- a/yaksh/evaluator_tests/test_python_evaluation.py
+++ b/yaksh/evaluator_tests/test_python_evaluation.py
@@ -181,7 +181,7 @@ class PythonAssertionEvaluationTestCases(unittest.TestCase):
self.assertIn(msg, result.get("error"))
-class PythonStdioEvaluationTestCases(unittest.TestCase):
+class PythonStdoutEvaluationTestCases(unittest.TestCase):
def setUp(self):
self.test_case_data = [{"expected_input": None,
"expected_output": "0 1 1 2 3"