From d29fed213caccc7bf2f66ed7a11b94b4bbcac3d1 Mon Sep 17 00:00:00 2001 From: Timotej Lazar Date: Thu, 6 Oct 2016 14:40:16 +0200 Subject: Python: add support for auxiliary code (like for Prolog) --- python/problems/dictionaries/children/common.py | 8 ++++---- python/problems/dictionaries/family/common.py | 8 ++++---- python/problems/dictionaries/following_words/common.py | 8 ++++---- python/problems/dictionaries/freq_following_word/common.py | 8 ++++---- python/problems/dictionaries/grandchildren/common.py | 8 ++++---- python/problems/dictionaries/max_characters/common.py | 8 ++++---- python/problems/dictionaries/most_frequent/common.py | 8 ++++---- python/problems/dictionaries/show_letters/common.py | 8 ++++---- python/problems/dictionaries/successors/common.py | 8 ++++---- python/problems/dictionaries/text/common.py | 8 ++++---- python/problems/dictionaries/transactions/common.py | 8 ++++---- python/problems/dictionaries/waiter/common.py | 8 ++++---- 12 files changed, 48 insertions(+), 48 deletions(-) (limited to 'python/problems/dictionaries') diff --git a/python/problems/dictionaries/children/common.py b/python/problems/dictionaries/children/common.py index 437835e..b97e593 100644 --- a/python/problems/dictionaries/children/common.py +++ b/python/problems/dictionaries/children/common.py @@ -19,7 +19,7 @@ hint_type = { } -def test(python, code): +def test(python, code, aux_code=''): func_name = 'children' tokens = get_tokens(code) if not has_token_sequence(tokens, ['def', func_name]): @@ -45,7 +45,7 @@ def test(python, code): test_in = [(func_name+'%s'%str(l[0]), None) for l in in_out] test_out = [l[1] for l in in_out] - answers = python(code=code, inputs=test_in, timeout=1.0) + answers = python(code=aux_code+code, inputs=test_in, timeout=1.0) n_correct = 0 tin, tout = None, None for i, (ans, to) in enumerate(zip(answers, test_out)): @@ -64,11 +64,11 @@ def test(python, code): return passed, hints -def hint(python, code): +def hint(python, code, aux_code=''): tokens = get_tokens(code) # run one test first to see if there are any exceptions - answer = python(code=code, inputs=[(None, None)], timeout=1.0) + answer = python(code=aux_code+code, inputs=[(None, None)], timeout=1.0) exc = get_exception_desc(answer[0][3]) if exc: return exc diff --git a/python/problems/dictionaries/family/common.py b/python/problems/dictionaries/family/common.py index 8d175e1..4f673a4 100644 --- a/python/problems/dictionaries/family/common.py +++ b/python/problems/dictionaries/family/common.py @@ -21,7 +21,7 @@ hint_type = { 'final_hint': Hint('final_hint') } -def test(python, code): +def test(python, code, aux_code=''): func_name = 'family_tree' tokens = get_tokens(code) if not has_token_sequence(tokens, ['def', func_name]): @@ -51,7 +51,7 @@ def test(python, code): test_in = [(func_name+'(%s)'%str(l[0]), None) for l in in_out] test_out = [l[1] for l in in_out] - answers = python(code=code, inputs=test_in, timeout=1.0) + answers = python(code=aux_code+code, inputs=test_in, timeout=1.0) n_correct = 0 tin, tout = None, None for i, (ans, to) in enumerate(zip(answers, test_out)): @@ -69,11 +69,11 @@ def test(python, code): return passed, hints -def hint(python, code): +def hint(python, code, aux_code=''): tokens = get_tokens(code) # run one test first to see if there are any exceptions - answer = python(code=code, inputs=[(None, None)], timeout=1.0) + answer = python(code=aux_code+code, inputs=[(None, None)], timeout=1.0) exc = get_exception_desc(answer[0][3]) if exc: return exc diff --git a/python/problems/dictionaries/following_words/common.py b/python/problems/dictionaries/following_words/common.py index 501cfd2..0afaf91 100644 --- a/python/problems/dictionaries/following_words/common.py +++ b/python/problems/dictionaries/following_words/common.py @@ -22,7 +22,7 @@ hint_type = { 'final_hint': Hint('final_hint') } -def test(python, code): +def test(python, code, aux_code=''): func_name = 'following_words' tokens = get_tokens(code) if not has_token_sequence(tokens, ['def', func_name]): @@ -40,7 +40,7 @@ def test(python, code): test_in = [(func_name+'("%s")'%str(l[0]), None) for l in in_out] test_out = [l[1] for l in in_out] - answers = python(code=code, inputs=test_in, timeout=1.0) + answers = python(code=aux_code+code, inputs=test_in, timeout=1.0) n_correct = 0 tin, tout = None, None for i, (ans, to) in enumerate(zip(answers, test_out)): @@ -59,11 +59,11 @@ def test(python, code): return passed, hints -def hint(python, code): +def hint(python, code, aux_code=''): tokens = get_tokens(code) # run one test first to see if there are any exceptions - answer = python(code=code, inputs=[(None, None)], timeout=1.0) + answer = python(code=aux_code+code, inputs=[(None, None)], timeout=1.0) exc = get_exception_desc(answer[0][3]) if exc: return exc diff --git a/python/problems/dictionaries/freq_following_word/common.py b/python/problems/dictionaries/freq_following_word/common.py index e00b332..557c76e 100644 --- a/python/problems/dictionaries/freq_following_word/common.py +++ b/python/problems/dictionaries/freq_following_word/common.py @@ -30,7 +30,7 @@ hint_type = { 'final_hint': Hint('final_hint') } -def test(python, code): +def test(python, code, aux_code=''): func_name = 'freq_following_word' tokens = get_tokens(code) if not has_token_sequence(tokens, ['def', func_name]): @@ -51,7 +51,7 @@ def test(python, code): test_in = [(func_name+'("%s")'%str(l[0]), None) for l in in_out] test_out = [l[1] for l in in_out] - answers = python(code=code, inputs=test_in, timeout=1.0) + answers = python(code=aux_code+code, inputs=test_in, timeout=1.0) n_correct = 0 tin, tout = None, None for i, (ans, to) in enumerate(zip(answers, test_out)): @@ -70,11 +70,11 @@ def test(python, code): return passed, hints -def hint(python, code): +def hint(python, code, aux_code=''): tokens = get_tokens(code) # run one test first to see if there are any exceptions - answer = python(code=code, inputs=[(None, None)], timeout=1.0) + answer = python(code=aux_code+code, inputs=[(None, None)], timeout=1.0) exc = get_exception_desc(answer[0][3]) if exc: return exc diff --git a/python/problems/dictionaries/grandchildren/common.py b/python/problems/dictionaries/grandchildren/common.py index 0e71fba..04a8b68 100644 --- a/python/problems/dictionaries/grandchildren/common.py +++ b/python/problems/dictionaries/grandchildren/common.py @@ -26,7 +26,7 @@ hint_type = { } -def test(python, code): +def test(python, code, aux_code=''): func_name = 'grandchildren' tokens = get_tokens(code) if not has_token_sequence(tokens, ['def', func_name]): @@ -54,7 +54,7 @@ def test(python, code): test_in = [(func_name+'%s'%str(l[0]), None) for l in in_out] test_out = [l[1] for l in in_out] - answers = python(code=code, inputs=test_in, timeout=1.0) + answers = python(code=aux_code+code, inputs=test_in, timeout=1.0) n_correct = 0 tin, tout = None, None for i, (ans, to) in enumerate(zip(answers, test_out)): @@ -73,11 +73,11 @@ def test(python, code): return passed, hints -def hint(python, code): +def hint(python, code, aux_code=''): tokens = get_tokens(code) # run one test first to see if there are any exceptions - answer = python(code=code, inputs=[(None, None)], timeout=1.0) + answer = python(code=aux_code+code, inputs=[(None, None)], timeout=1.0) exc = get_exception_desc(answer[0][3]) if exc: return exc diff --git a/python/problems/dictionaries/max_characters/common.py b/python/problems/dictionaries/max_characters/common.py index cb0c4b6..eecf50a 100644 --- a/python/problems/dictionaries/max_characters/common.py +++ b/python/problems/dictionaries/max_characters/common.py @@ -23,7 +23,7 @@ hint_type = { 'final_hint': Hint('final_hint') } -def test(python, code): +def test(python, code, aux_code=''): func_name = 'maxchars' tokens = get_tokens(code) if not has_token_sequence(tokens, ['def', func_name]): @@ -43,7 +43,7 @@ def test(python, code): test_in = [('{0}({1})'.format(func_name, str(l[0])), None) for l in in_out] test_out = [l[1] for l in in_out] - answers = python(code=code, inputs=test_in, timeout=1.0) + answers = python(code=aux_code+code, inputs=test_in, timeout=1.0) n_correct = 0 tin, tout = None, None for i, (ans, to) in enumerate(zip(answers, test_out)): @@ -61,11 +61,11 @@ def test(python, code): return passed, hints -def hint(python, code): +def hint(python, code, aux_code=''): tokens = get_tokens(code) # run one test first to see if there are any exceptions - answer = python(code=code, inputs=[(None, None)], timeout=1.0) + answer = python(code=aux_code+code, inputs=[(None, None)], timeout=1.0) exc = get_exception_desc(answer[0][3]) if exc: return exc diff --git a/python/problems/dictionaries/most_frequent/common.py b/python/problems/dictionaries/most_frequent/common.py index a945f1d..aaaba33 100644 --- a/python/problems/dictionaries/most_frequent/common.py +++ b/python/problems/dictionaries/most_frequent/common.py @@ -35,7 +35,7 @@ hint_type = { 'final_hint': Hint('final_hint') } -def test(python, code): +def test(python, code, aux_code=''): func_name = 'most_frequent' tokens = get_tokens(code) if not has_token_sequence(tokens, ['def', func_name]): @@ -53,7 +53,7 @@ def test(python, code): test_in = [('{0}("{1}")'.format(func_name, str(l[0])), None) for l in in_out] test_out = [l[1] for l in in_out] - answers = python(code=code, inputs=test_in, timeout=1.0) + answers = python(code=aux_code+code, inputs=test_in, timeout=1.0) n_correct = 0 tin, tout = None, None for i, (ans, to) in enumerate(zip(answers, test_out)): @@ -71,11 +71,11 @@ def test(python, code): return passed, hints -def hint(python, code): +def hint(python, code, aux_code=''): tokens = get_tokens(code) # run one test first to see if there are any exceptions - answer = python(code=code, inputs=[(None, None)], timeout=1.0) + answer = python(code=aux_code+code, inputs=[(None, None)], timeout=1.0) exc = get_exception_desc(answer[0][3]) if exc: return exc diff --git a/python/problems/dictionaries/show_letters/common.py b/python/problems/dictionaries/show_letters/common.py index f69565a..29ab749 100644 --- a/python/problems/dictionaries/show_letters/common.py +++ b/python/problems/dictionaries/show_letters/common.py @@ -19,7 +19,7 @@ hint_type = { 'final_hint': Hint('final_hint') } -def test(python, code): +def test(python, code, aux_code=''): func_name = 'show_letters' tokens = get_tokens(code) if not has_token_sequence(tokens, ['def', func_name]): @@ -38,7 +38,7 @@ def test(python, code): test_in = [('{0}{1}'.format(func_name, str(l[0])), None) for l in in_out] test_out = [l[1] for l in in_out] - answers = python(code=code, inputs=test_in, timeout=1.0) + answers = python(code=aux_code+code, inputs=test_in, timeout=1.0) n_correct = 0 tin, tout = None, None for i, (ans, to) in enumerate(zip(answers, test_out)): @@ -56,11 +56,11 @@ def test(python, code): return passed, hints -def hint(python, code): +def hint(python, code, aux_code=''): tokens = get_tokens(code) # run one test first to see if there are any exceptions - answer = python(code=code, inputs=[(None, None)], timeout=1.0) + answer = python(code=aux_code+code, inputs=[(None, None)], timeout=1.0) exc = get_exception_desc(answer[0][3]) if exc: return exc diff --git a/python/problems/dictionaries/successors/common.py b/python/problems/dictionaries/successors/common.py index 5f824f5..722e22e 100644 --- a/python/problems/dictionaries/successors/common.py +++ b/python/problems/dictionaries/successors/common.py @@ -25,7 +25,7 @@ hint_type = { 'final_hint': Hint('final_hint') } -def test(python, code): +def test(python, code, aux_code=''): func_name = 'successors' tokens = get_tokens(code) if not has_token_sequence(tokens, ['def', func_name]): @@ -52,7 +52,7 @@ def test(python, code): test_in = [(func_name+'%s'%str(l[0]), None) for l in in_out] test_out = [l[1] for l in in_out] - answers = python(code=code, inputs=test_in, timeout=1.0) + answers = python(code=aux_code+code, inputs=test_in, timeout=1.0) n_correct = 0 tin, tout = None, None for i, (ans, to) in enumerate(zip(answers, test_out)): @@ -71,11 +71,11 @@ def test(python, code): return passed, hints -def hint(python, code): +def hint(python, code, aux_code=''): tokens = get_tokens(code) # run one test first to see if there are any exceptions - answer = python(code=code, inputs=[(None, None)], timeout=1.0) + answer = python(code=aux_code+code, inputs=[(None, None)], timeout=1.0) exc = get_exception_desc(answer[0][3]) if exc: return exc diff --git a/python/problems/dictionaries/text/common.py b/python/problems/dictionaries/text/common.py index 134f69b..ab6deac 100644 --- a/python/problems/dictionaries/text/common.py +++ b/python/problems/dictionaries/text/common.py @@ -38,7 +38,7 @@ hint_type = { 'final_hint': Hint('final_hint') } -def test(python, code): +def test(python, code, aux_code=''): func_name = 'text' tokens = get_tokens(code) if not has_token_sequence(tokens, ['def', func_name]): @@ -56,7 +56,7 @@ def test(python, code): test_in = [(func_name+'%s'%str(l[0]), None) for l in in_out] test_out = [l[1] for l in in_out] - answers = python(code=code, inputs=test_in, timeout=1.0) + answers = python(code=aux_code+code, inputs=test_in, timeout=1.0) n_correct = 0 tin, tout = None, None for i, (ans, to) in enumerate(zip(answers, test_out)): @@ -75,11 +75,11 @@ def test(python, code): return passed, hints -def hint(python, code): +def hint(python, code, aux_code=''): tokens = get_tokens(code) # run one test first to see if there are any exceptions - answer = python(code=code, inputs=[(None, None)], timeout=1.0) + answer = python(code=aux_code+code, inputs=[(None, None)], timeout=1.0) exc = get_exception_desc(answer[0][3]) if exc: return exc diff --git a/python/problems/dictionaries/transactions/common.py b/python/problems/dictionaries/transactions/common.py index 66d6387..a3a173d 100644 --- a/python/problems/dictionaries/transactions/common.py +++ b/python/problems/dictionaries/transactions/common.py @@ -24,7 +24,7 @@ hint_type = { 'final_hint': Hint('final_hint') } -def test(python, code): +def test(python, code, aux_code=''): func_name = 'transactions' tokens = get_tokens(code) if not has_token_sequence(tokens, ['def', func_name]): @@ -42,7 +42,7 @@ def test(python, code): test_in = [('{0}{1}'.format(func_name, str(l[0])), None) for l in in_out] test_out = [l[1] for l in in_out] - answers = python(code=code, inputs=test_in, timeout=1.0) + answers = python(code=aux_code+code, inputs=test_in, timeout=1.0) n_correct = 0 tin, tout = None, None for i, (ans, to) in enumerate(zip(answers, test_out)): @@ -60,11 +60,11 @@ def test(python, code): return passed, hints -def hint(python, code): +def hint(python, code, aux_code=''): tokens = get_tokens(code) # run one test first to see if there are any exceptions - answer = python(code=code, inputs=[(None, None)], timeout=1.0) + answer = python(code=aux_code+code, inputs=[(None, None)], timeout=1.0) exc = get_exception_desc(answer[0][3]) if exc: return exc diff --git a/python/problems/dictionaries/waiter/common.py b/python/problems/dictionaries/waiter/common.py index bcda759..41b592d 100644 --- a/python/problems/dictionaries/waiter/common.py +++ b/python/problems/dictionaries/waiter/common.py @@ -29,7 +29,7 @@ def comp(solution, test): return True return dict(solution) == test -def test(python, code): +def test(python, code, aux_code=''): func_name = 'orders' tokens = get_tokens(code) if not has_token_sequence(tokens, ['def', func_name]): @@ -52,7 +52,7 @@ def test(python, code): for l in in_out+in_out_empty] test_out = [l[1] for l in in_out+in_out_empty] - answers = python(code=code, inputs=test_in, timeout=1.0) + answers = python(code=aux_code+code, inputs=test_in, timeout=1.0) n_correct = 0 tin, tout = None, None for i, (ans, to) in enumerate(zip(answers, test_out)): @@ -70,11 +70,11 @@ def test(python, code): return passed, hints -def hint(python, code): +def hint(python, code, aux_code=''): tokens = get_tokens(code) # run one test first to see if there are any exceptions - answer = python(code=code, inputs=[(None, None)], timeout=1.0) + answer = python(code=aux_code+code, inputs=[(None, None)], timeout=1.0) exc = get_exception_desc(answer[0][3]) if exc: return exc -- cgit v1.2.1