summaryrefslogtreecommitdiff
path: root/python/problems/lists_and_for
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/lists_and_for
parent969812724912512740dbf037940a9e6770df19ed (diff)
Python: add support for auxiliary code (like for Prolog)
Diffstat (limited to 'python/problems/lists_and_for')
-rw-r--r--python/problems/lists_and_for/calculator_polish/common.py8
-rw-r--r--python/problems/lists_and_for/contains_42/common.py8
-rw-r--r--python/problems/lists_and_for/contains_multiples/common.py8
-rw-r--r--python/problems/lists_and_for/contains_string/common.py8
-rw-r--r--python/problems/lists_and_for/counting/common.py8
-rw-r--r--python/problems/lists_and_for/divisors/common.py8
-rw-r--r--python/problems/lists_and_for/divisors_sum/common.py8
-rw-r--r--python/problems/lists_and_for/every_third/common.py8
-rw-r--r--python/problems/lists_and_for/perfect_numbers/common.py8
-rw-r--r--python/problems/lists_and_for/places/common.py8
-rw-r--r--python/problems/lists_and_for/prefix/common.py8
-rw-r--r--python/problems/lists_and_for/split_word/common.py8
-rw-r--r--python/problems/lists_and_for/substrings/common.py8
13 files changed, 52 insertions, 52 deletions
diff --git a/python/problems/lists_and_for/calculator_polish/common.py b/python/problems/lists_and_for/calculator_polish/common.py
index 790f116..cd18f3b 100644
--- a/python/problems/lists_and_for/calculator_polish/common.py
+++ b/python/problems/lists_and_for/calculator_polish/common.py
@@ -42,7 +42,7 @@ hint_type = {
'final_hint': Hint('final_hint')
}
-def test(python, code):
+def test(python, code, aux_code=''):
in_out = [
(['6 3 +'], [9]),
(['6 3 -'], [3]),
@@ -62,7 +62,7 @@ def test(python, code):
test_in = [(None, '\n'.join(s[0])+'\n') for s in in_out]
test_out = [s[1] for s in in_out]
# List of outputs: (expression result, stdout, stderr, exception).
- answers = python(code=code, inputs=test_in, timeout=1.0)
+ answers = python(code=aux_code+code, inputs=test_in, timeout=1.0)
outputs = [ans[1] for ans in answers]
n_correct = 0
@@ -83,11 +83,11 @@ def test(python, code):
hints.append({'id': 'final_hint'})
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/lists_and_for/contains_42/common.py b/python/problems/lists_and_for/contains_42/common.py
index dfaab56..9118c5e 100644
--- a/python/problems/lists_and_for/contains_42/common.py
+++ b/python/problems/lists_and_for/contains_42/common.py
@@ -28,7 +28,7 @@ hint_type = {
'final_hint_nobreak': Hint('final_hint_nobreak')
}
-def test(python, code):
+def test(python, code, aux_code=''):
tokens = get_tokens(code)
test_xs = [[42, 5, 4, -7, 2, 12, -3, -4, 11, 42, 2],
@@ -59,7 +59,7 @@ def test(python, code):
flags = re.DOTALL | re.MULTILINE)
# use python session to call tcode
- answers = python(code=tcode, inputs=[(None, None)], timeout=1.0)
+ answers = python(code=aux_code+tcode, inputs=[(None, None)], timeout=1.0)
output = answers[0][1]
if str(test_out[xs_i]) in output and \
@@ -80,9 +80,9 @@ def test(python, code):
hints.append({'id' : 'final_hint_nobreak'})
return passed, hints
-def hint(python, code):
+def hint(python, code, aux_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/lists_and_for/contains_multiples/common.py b/python/problems/lists_and_for/contains_multiples/common.py
index 84eaca9..4fd349d 100644
--- a/python/problems/lists_and_for/contains_multiples/common.py
+++ b/python/problems/lists_and_for/contains_multiples/common.py
@@ -21,7 +21,7 @@ hint_type = {
'final_hint': Hint('final_hint')
}
-def test(python, code):
+def test(python, code, aux_code=''):
in_out = [
([], False),
([0], True),
@@ -51,7 +51,7 @@ def test(python, code):
flags = re.DOTALL | re.MULTILINE)
# use python session to call tcode
- answers = python(code=tcode, inputs=[(None, None)], timeout=1.0)
+ answers = python(code=aux_code+tcode, inputs=[(None, None)], timeout=1.0)
output = answers[0][1]
if str(test_out[xs_i]) in output and \
@@ -69,11 +69,11 @@ def test(python, code):
hints.append({'id': 'final_hint'})
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/lists_and_for/contains_string/common.py b/python/problems/lists_and_for/contains_string/common.py
index c307a9c..eb724f0 100644
--- a/python/problems/lists_and_for/contains_string/common.py
+++ b/python/problems/lists_and_for/contains_string/common.py
@@ -26,7 +26,7 @@ hint_type = {
'final_hint': Hint('final_hint')
}
-def test(python, code):
+def test(python, code, aux_code=''):
test_xs = [['waldo', 'foo', 'bar', 'baz'],
['foo', 'bar', 'baz', 'Waldo', 'foobar'],
['foo', 'bar', 'baz', 'Waldo'],
@@ -53,7 +53,7 @@ def test(python, code):
flags = re.DOTALL | re.MULTILINE)
# use python session to call tcode
- answers = python(code=tcode, inputs=[(None, None)], timeout=1.0)
+ answers = python(code=aux_code+tcode, inputs=[(None, None)], timeout=1.0)
output = answers[0][1]
if str(test_out[xs_i]) in output and \
@@ -72,9 +72,9 @@ def test(python, code):
return passed, hints
-def hint(python, code):
+def hint(python, code, aux_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/lists_and_for/counting/common.py b/python/problems/lists_and_for/counting/common.py
index 5438030..295ca57 100644
--- a/python/problems/lists_and_for/counting/common.py
+++ b/python/problems/lists_and_for/counting/common.py
@@ -26,7 +26,7 @@ hint_type = {
'final_hint': Hint('final_hint')
}
-def test(python, code):
+def test(python, code, aux_code=''):
test_xs = [[42, 5, 4, -7, 2, 42, -3, -4, 11, 42, 2],
[42, 5, 4, -7, 2, 12, 42, -4, 11, 2],
[5, 4, -7, 2, 12, -3, -4, 11, 2],
@@ -57,7 +57,7 @@ def test(python, code):
flags = re.DOTALL | re.MULTILINE)
# use python session to call tcode
- answers = python(code=tcode, inputs=[(None, None)], timeout=1.0)
+ answers = python(code=aux_code+tcode, inputs=[(None, None)], timeout=1.0)
output = answers[0][1]
if str(test_out[xs_i]) in output:
@@ -74,9 +74,9 @@ def test(python, code):
hints.append({'id': 'final_hint'})
return passed, hints
-def hint(python, code):
+def hint(python, code, aux_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/lists_and_for/divisors/common.py b/python/problems/lists_and_for/divisors/common.py
index 429e212..d1615ff 100644
--- a/python/problems/lists_and_for/divisors/common.py
+++ b/python/problems/lists_and_for/divisors/common.py
@@ -24,7 +24,7 @@ hint_type = {
'last_number': Hint('last_number'),
}
-def test(python, code):
+def test(python, code, aux_code=''):
test_in = [
(None, '8\n'),
(None, '6\n'),
@@ -36,7 +36,7 @@ def test(python, code):
values = [8, 6, 5, 2, 15, 20]
# List of outputs: (expression result, stdout, stderr, exception).
- answers = python(code=code, inputs=test_in, timeout=1.0)
+ answers = python(code=aux_code+code, inputs=test_in, timeout=1.0)
outputs = [ans[1] for ans in answers]
n_correct, tin = 0, None
@@ -65,9 +65,9 @@ def test(python, code):
hints.append({'id': 'final_hint'})
return passed, hints
-def hint(python, code):
+def hint(python, code, aux_code=''):
# run one test first to see if there are any exceptions
- answer = python(code=code, inputs=[(None, '8\n')], timeout=1.0)
+ answer = python(code=aux_code+code, inputs=[(None, '8\n')], timeout=1.0)
exc = get_exception_desc(answer[0][3])
if exc:
if 'ZeroDivisionError' in answer[0][3]:
diff --git a/python/problems/lists_and_for/divisors_sum/common.py b/python/problems/lists_and_for/divisors_sum/common.py
index 65333f0..69e6ade 100644
--- a/python/problems/lists_and_for/divisors_sum/common.py
+++ b/python/problems/lists_and_for/divisors_sum/common.py
@@ -27,7 +27,7 @@ hint_type = {
'summing': Hint('summing'),
}
-def test(python, code):
+def test(python, code, aux_code=''):
test_in = [
(None, '8\n'),
(None, '6\n'),
@@ -45,7 +45,7 @@ def test(python, code):
22]
# List of outputs: (expression result, stdout, stderr, exception).
- answers = python(code=code, inputs=test_in, timeout=1.0)
+ answers = python(code=aux_code+code, inputs=test_in, timeout=1.0)
outputs = [ans[1] for ans in answers]
n_correct, tin = 0, None
@@ -64,10 +64,10 @@ def test(python, code):
hints.append({'id': 'final_hint'})
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, '8\n')], timeout=1.0)
+ answer = python(code=aux_code+code, inputs=[(None, '8\n')], timeout=1.0)
exc = get_exception_desc(answer[0][3])
if exc:
if 'ZeroDivisionError' in answer[0][3]:
diff --git a/python/problems/lists_and_for/every_third/common.py b/python/problems/lists_and_for/every_third/common.py
index da4a2fa..3ad1ae6 100644
--- a/python/problems/lists_and_for/every_third/common.py
+++ b/python/problems/lists_and_for/every_third/common.py
@@ -22,7 +22,7 @@ hint_type = {
'final_hint': Hint('final_hint')
}
-def test(python, code):
+def test(python, code, aux_code=''):
in_out = [
([], []),
([0], []),
@@ -47,7 +47,7 @@ def test(python, code):
flags = re.DOTALL | re.MULTILINE)
# use python session to call tcode
- answers = python(code=tcode, inputs=[(None, None)], timeout=1.0)
+ answers = python(code=aux_code+tcode, inputs=[(None, None)], timeout=1.0)
output = answers[0][1]
if str(test_out[xs_i]) in output:
@@ -64,11 +64,11 @@ def test(python, code):
hints.append({'id': 'final_hint'})
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/lists_and_for/perfect_numbers/common.py b/python/problems/lists_and_for/perfect_numbers/common.py
index 1369188..64a4348 100644
--- a/python/problems/lists_and_for/perfect_numbers/common.py
+++ b/python/problems/lists_and_for/perfect_numbers/common.py
@@ -30,7 +30,7 @@ hint_type = {
'summing': Hint('summing'),
}
-def test(python, code):
+def test(python, code, aux_code=''):
test_in = [
(None, '8\n'),
(None, '6\n'),
@@ -48,7 +48,7 @@ def test(python, code):
22]
# List of outputs: (expression result, stdout, stderr, exception).
- answers = python(code=code, inputs=test_in, timeout=1.0)
+ answers = python(code=aux_code+code, inputs=test_in, timeout=1.0)
outputs = [ans[1] for ans in answers]
n_correct, tin = 0, None
@@ -67,10 +67,10 @@ def test(python, code):
hints.append({'id': 'final_hint'})
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, '8\n')], timeout=1.0)
+ answer = python(code=aux_code+code, inputs=[(None, '8\n')], timeout=1.0)
exc = get_exception_desc(answer[0][3])
if exc:
if 'ZeroDivisionError' in answer[0][3]:
diff --git a/python/problems/lists_and_for/places/common.py b/python/problems/lists_and_for/places/common.py
index df62e7a..01a003d 100644
--- a/python/problems/lists_and_for/places/common.py
+++ b/python/problems/lists_and_for/places/common.py
@@ -21,7 +21,7 @@ hint_type = {
'final_hint': Hint('final_hint')
}
-def test(python, code):
+def test(python, code, aux_code=''):
in_out = [
([], []),
([0], []),
@@ -50,7 +50,7 @@ def test(python, code):
flags = re.DOTALL | re.MULTILINE)
# use python session to call tcode
- answers = python(code=tcode, inputs=[(None, None)], timeout=1.0)
+ answers = python(code=aux_code+tcode, inputs=[(None, None)], timeout=1.0)
output = answers[0][1]
if str(test_out[xs_i]) in output:
@@ -67,11 +67,11 @@ def test(python, code):
hints.append({'id': 'final_hint'})
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/lists_and_for/prefix/common.py b/python/problems/lists_and_for/prefix/common.py
index 3cc57fb..9725350 100644
--- a/python/problems/lists_and_for/prefix/common.py
+++ b/python/problems/lists_and_for/prefix/common.py
@@ -20,7 +20,7 @@ hint_type = {
'final_hint': Hint('final_hint')
}
-def test(python, code):
+def test(python, code, aux_code=''):
in_out = [
('a', ['', 'a']),
('ab', ['', 'a', 'ab']),
@@ -31,7 +31,7 @@ def test(python, code):
test_in = [(None, s[0]+'\n') for s in in_out]
test_out = [str(s[1]) for s in in_out]
# List of outputs: (expression result, stdout, stderr, exception).
- answers = python(code=code, inputs=test_in, timeout=1.0)
+ answers = python(code=aux_code+code, inputs=test_in, timeout=1.0)
outputs = [ans[1] for ans in answers]
n_correct = 0
@@ -51,11 +51,11 @@ def test(python, code):
hints.append({'id': 'final_hint'})
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/lists_and_for/split_word/common.py b/python/problems/lists_and_for/split_word/common.py
index 95f87f7..6412ddc 100644
--- a/python/problems/lists_and_for/split_word/common.py
+++ b/python/problems/lists_and_for/split_word/common.py
@@ -20,7 +20,7 @@ hint_type = {
'final_hint': Hint('final_hint')
}
-def test(python, code):
+def test(python, code, aux_code=''):
in_out = [
('a', [('', 'a'), ('a', '')]),
('ab', [('', 'ab'), ('a', 'b'), ('ab', '')]),
@@ -31,7 +31,7 @@ def test(python, code):
test_in = [(None, s[0]+'\n') for s in in_out]
test_out = [str(s[1]) for s in in_out]
# List of outputs: (expression result, stdout, stderr, exception).
- answers = python(code=code, inputs=test_in, timeout=1.0)
+ answers = python(code=aux_code+code, inputs=test_in, timeout=1.0)
outputs = [ans[1] for ans in answers]
n_correct = 0
@@ -52,11 +52,11 @@ def test(python, code):
hints.append({'id': 'final_hint'})
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/lists_and_for/substrings/common.py b/python/problems/lists_and_for/substrings/common.py
index 3a996c2..0efcc6c 100644
--- a/python/problems/lists_and_for/substrings/common.py
+++ b/python/problems/lists_and_for/substrings/common.py
@@ -23,7 +23,7 @@ hint_type = {
'final_hint': Hint('final_hint')
}
-def test(python, code):
+def test(python, code, aux_code=''):
in_out = [
('a', ['', 'a']),
('ab', ['', 'a', 'b', 'ab']),
@@ -34,7 +34,7 @@ def test(python, code):
test_in = [(None, s[0]+'\n') for s in in_out]
test_out = [str(s[1]) for s in in_out]
# List of outputs: (expression result, stdout, stderr, exception).
- answers = python(code=code, inputs=test_in, timeout=1.0)
+ answers = python(code=aux_code+code, inputs=test_in, timeout=1.0)
outputs = [ans[1] for ans in answers]
n_correct = 0
@@ -55,11 +55,11 @@ def test(python, code):
hints.append({'id': 'final_hint'})
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