summaryrefslogtreecommitdiff
path: root/python/problems/comprehensions
diff options
context:
space:
mode:
authorTimotej Lazar <timotej.lazar@fri.uni-lj.si>2016-10-06 14:40:16 +0200
committerTimotej Lazar <timotej.lazar@fri.uni-lj.si>2016-10-06 14:41:03 +0200
commitd29fed213caccc7bf2f66ed7a11b94b4bbcac3d1 (patch)
tree04f96da9e5a4ea6572db9700907959eae295305b /python/problems/comprehensions
parent969812724912512740dbf037940a9e6770df19ed (diff)
Python: add support for auxiliary code (like for Prolog)
Diffstat (limited to 'python/problems/comprehensions')
-rw-r--r--python/problems/comprehensions/inverse_morse/common.py8
-rw-r--r--python/problems/comprehensions/isbn/common.py8
-rw-r--r--python/problems/comprehensions/morse/common.py8
-rw-r--r--python/problems/comprehensions/std/common.py8
-rw-r--r--python/problems/comprehensions/subs/common.py8
-rw-r--r--python/problems/comprehensions/sumsquares/common.py8
-rw-r--r--python/problems/comprehensions/sumsquares_palindrome/common.py8
7 files changed, 28 insertions, 28 deletions
diff --git a/python/problems/comprehensions/inverse_morse/common.py b/python/problems/comprehensions/inverse_morse/common.py
index b7644b5..20488b9 100644
--- a/python/problems/comprehensions/inverse_morse/common.py
+++ b/python/problems/comprehensions/inverse_morse/common.py
@@ -60,7 +60,7 @@ hint_type = {
'has_loop': Hint('has_loop')
}
-def test(python, code):
+def test(python, code, aux_code=''):
func_name = 'morse2txt'
tokens = get_tokens(code)
ast = get_ast(code)
@@ -78,7 +78,7 @@ def test(python, code):
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)):
@@ -103,11 +103,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/comprehensions/isbn/common.py b/python/problems/comprehensions/isbn/common.py
index 4724713..9de9580 100644
--- a/python/problems/comprehensions/isbn/common.py
+++ b/python/problems/comprehensions/isbn/common.py
@@ -19,7 +19,7 @@ hint_type = {
'has_loop': Hint('has_loop')
}
-def test(python, code):
+def test(python, code, aux_code=''):
func_name = 'valid'
tokens = get_tokens(code)
ast = get_ast(code)
@@ -40,7 +40,7 @@ def test(python, code):
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)):
@@ -65,11 +65,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/comprehensions/morse/common.py b/python/problems/comprehensions/morse/common.py
index 785862e..4b112cc 100644
--- a/python/problems/comprehensions/morse/common.py
+++ b/python/problems/comprehensions/morse/common.py
@@ -59,7 +59,7 @@ hint_type = {
'has_loop': Hint('has_loop')
}
-def test(python, code):
+def test(python, code, aux_code=''):
func_name = 'txt2morse'
tokens = get_tokens(code)
ast = get_ast(code)
@@ -77,7 +77,7 @@ def test(python, code):
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)):
@@ -102,11 +102,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/comprehensions/std/common.py b/python/problems/comprehensions/std/common.py
index 05c7357..7ac0662 100644
--- a/python/problems/comprehensions/std/common.py
+++ b/python/problems/comprehensions/std/common.py
@@ -23,7 +23,7 @@ hint_type = {
'has_loop': Hint('has_loop')
}
-def test(python, code):
+def test(python, code, aux_code=''):
func_name = 'std'
tokens = get_tokens(code)
ast = get_ast(code)
@@ -42,7 +42,7 @@ def test(python, code):
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)):
@@ -67,11 +67,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/comprehensions/subs/common.py b/python/problems/comprehensions/subs/common.py
index 6998998..d745578 100644
--- a/python/problems/comprehensions/subs/common.py
+++ b/python/problems/comprehensions/subs/common.py
@@ -19,7 +19,7 @@ hint_type = {
'has_loop': Hint('has_loop')
}
-def test(python, code):
+def test(python, code, aux_code=''):
func_name = 'subs'
tokens = get_tokens(code)
ast = get_ast(code)
@@ -36,7 +36,7 @@ def test(python, code):
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/comprehensions/sumsquares/common.py b/python/problems/comprehensions/sumsquares/common.py
index bda561e..cd23c9c 100644
--- a/python/problems/comprehensions/sumsquares/common.py
+++ b/python/problems/comprehensions/sumsquares/common.py
@@ -18,7 +18,7 @@ hint_type = {
'no_comprehension': Hint('no_comprehension')
}
-def test(python, code):
+def test(python, code, aux_code=''):
func_name = 'sumsquares'
tokens = get_tokens(code)
ast = get_ast(code)
@@ -34,7 +34,7 @@ def test(python, code):
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/comprehensions/sumsquares_palindrome/common.py b/python/problems/comprehensions/sumsquares_palindrome/common.py
index 9e66eb0..dcb565d 100644
--- a/python/problems/comprehensions/sumsquares_palindrome/common.py
+++ b/python/problems/comprehensions/sumsquares_palindrome/common.py
@@ -20,7 +20,7 @@ hint_type = {
'has_loop': Hint('has_loop')
}
-def test(python, code):
+def test(python, code, aux_code=''):
func_name = 'ss_palindrome'
tokens = get_tokens(code)
ast = get_ast(code)
@@ -38,7 +38,7 @@ def test(python, code):
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)):
@@ -63,11 +63,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