diff options
author | adityacp | 2016-09-02 12:59:20 +0530 |
---|---|---|
committer | adityacp | 2016-09-02 12:59:20 +0530 |
commit | 3c1bbe9d8c53c419d2fa2a254228484ea74aab96 (patch) | |
tree | 505e646133b52fe56fe1006ad48007cf01c61125 /yaksh/evaluator_tests/test_bash_evaluation.py | |
parent | 83fe192987c239287bf816a31f4da31910eb7087 (diff) | |
parent | 01e08dd15b59ce353043d541c9be81592cda3fe0 (diff) | |
download | online_test-3c1bbe9d8c53c419d2fa2a254228484ea74aab96.tar.gz online_test-3c1bbe9d8c53c419d2fa2a254228484ea74aab96.tar.bz2 online_test-3c1bbe9d8c53c419d2fa2a254228484ea74aab96.zip |
refactor in test_models and updated with latest changes
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 1070c6a..addc5e6 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"} @@ -66,5 +69,81 @@ class BashEvaluationTestCases(unittest.TestCase): self.assertTrue(result.get("success")) self.assertEquals(result.get("error"), "Correct answer") +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': '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.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() |