diff options
author | maheshgudi | 2016-06-08 11:18:52 +0530 |
---|---|---|
committer | adityacp | 2016-07-27 22:52:23 +0530 |
commit | 53192a5f757064b9f8873ea3fcfc7f9cd01e587c (patch) | |
tree | e14bc50d6b4ae771b72b3453f24525f6f4860620 /yaksh/evaluator_tests/test_bash_evaluation.py | |
parent | d14bf131d60af6eae6c3ff6ce5537af25420c314 (diff) | |
download | online_test-53192a5f757064b9f8873ea3fcfc7f9cd01e587c.tar.gz online_test-53192a5f757064b9f8873ea3fcfc7f9cd01e587c.tar.bz2 online_test-53192a5f757064b9f8873ea3fcfc7f9cd01e587c.zip |
made changes to stdio evaluator and added bash evaluator with test cases
Diffstat (limited to 'yaksh/evaluator_tests/test_bash_evaluation.py')
-rw-r--r-- | yaksh/evaluator_tests/test_bash_evaluation.py | 81 |
1 files changed, 80 insertions, 1 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() |