From 23ec34bf985eceb12dcd198950697f805b997517 Mon Sep 17 00:00:00 2001 From: ShaoWei Teo Date: Sun, 30 Oct 2016 20:58:27 +0800 Subject: [PATCH] Write a sample that test whether a function is an iteration (fixes issue #3). --- prog_question_test/tests/autograde.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/prog_question_test/tests/autograde.py b/prog_question_test/tests/autograde.py index 9d9b6cb..fe167e4 100755 --- a/prog_question_test/tests/autograde.py +++ b/prog_question_test/tests/autograde.py @@ -62,6 +62,20 @@ def is_recursion_node(func_def_node): self.assertTrue(is_recursion(user_function)) + @timeout_decorator.timeout(2) + def test_private_iteration(self): + def is_iteration(func): + children_nodes = list(ast.walk(ast.parse(inspect.getsource(func)))) + + return len(list(filter(lambda node: type(node) in (ast.For, ast.While), children_nodes))) > 0 + + self.meta['expression'] = 'test iteration' + self.meta['expected'] = 'True' + self.meta['output'] = str(is_iteration(user_function)) + self.meta['hint'] = 'Your function is not iterative.' + + self.assertTrue(is_iteration(user_function)) + class ProgQuestionEvaluation(unittest.TestCase): def setUp(self): # clears the dictionary containing meta data for each test