diff options
author | ankitjavalkar | 2016-03-22 16:11:28 +0530 |
---|---|---|
committer | ankitjavalkar | 2016-05-05 19:00:33 +0530 |
commit | 1f4542cdbea66899899b9c7de3ea38e39d794112 (patch) | |
tree | 62aa4a8b780888f99464e552ba18557a98bf6ca7 /yaksh/evaluator_tests | |
parent | 597c23866be3ecfdf94c40693b060fe9ebbf6446 (diff) | |
download | online_test-1f4542cdbea66899899b9c7de3ea38e39d794112.tar.gz online_test-1f4542cdbea66899899b9c7de3ea38e39d794112.tar.bz2 online_test-1f4542cdbea66899899b9c7de3ea38e39d794112.zip |
Add anti-cheating for python stdout evaluator and modify test
Diffstat (limited to 'yaksh/evaluator_tests')
-rw-r--r-- | yaksh/evaluator_tests/test_python_evaluation.py | 18 |
1 files changed, 15 insertions, 3 deletions
diff --git a/yaksh/evaluator_tests/test_python_evaluation.py b/yaksh/evaluator_tests/test_python_evaluation.py index e157cde..b23942f 100644 --- a/yaksh/evaluator_tests/test_python_evaluation.py +++ b/yaksh/evaluator_tests/test_python_evaluation.py @@ -148,12 +148,13 @@ class PythonAssertionEvaluationTestCases(unittest.TestCase): class PythonStdoutEvaluationTestCases(unittest.TestCase): def setUp(self): - self.output = ['Hello World\\n'] + self.output = ['0 1 1 2 3'] 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 = "a = 'Hello'\nb = 'World'\nprint '{0} {1}'.format(a, b)" + # user_answer = "a = 'Hello'\nb = 'World'\nprint '{0} {1}'.format(a, b)" + user_answer = "a,b=0,1\nfor i in range(5):\n\tprint a,\n\ta,b=b,a+b" get_class = PythonStdoutEvaluator() kwargs = {'user_answer': user_answer, 'test_case_data': self.output @@ -163,7 +164,7 @@ class PythonStdoutEvaluationTestCases(unittest.TestCase): self.assertTrue(result.get('success')) def test_incorrect_answer(self): - user_answer = "a = 'Goodbye'\nb = 'Name'\nprint '{0} {1}'.format(a, b)" + user_answer = "a,b=0,1\nfor i in range(5):\n\tprint b,\n\ta,b=b,a+b" get_class = PythonStdoutEvaluator() kwargs = {'user_answer': user_answer, 'test_case_data': self.output @@ -172,6 +173,17 @@ class PythonStdoutEvaluationTestCases(unittest.TestCase): self.assertFalse(result.get('success')) self.assertEqual(result.get('error'), "Incorrect Answer") + def test_direct_printed_answer(self): + user_answer = "print '0 1 1 2 3'" + error_msg = "Incorrect Answer: Please avoid printing the expected output directly" + get_class = PythonStdoutEvaluator() + kwargs = {'user_answer': user_answer, + 'test_case_data': self.output + } + result = get_class.evaluate(**kwargs) + self.assertFalse(result.get('success')) + self.assertEqual(result.get('error'), error_msg) + def test_infinite_loop(self): user_answer = "def add(a, b):\n\twhile True:\n\t\tpass" get_class = PythonStdoutEvaluator() |