From 95e107bf9e6a288969e4a83aee1a7062990f3b67 Mon Sep 17 00:00:00 2001
From: Martin
Date: Fri, 9 Oct 2015 16:35:23 +0200
Subject: Fixed testing for most problems.
---
python/problems/functions/assign_numbers/common.py | 24 +++++++++++--
.../problems/functions/body_mass_index/common.py | 27 +++++++++++++--
.../problems/functions/body_mass_index_2/common.py | 26 ++++++++++++--
python/problems/functions/common.py | 1 +
python/problems/functions/divisors/common.py | 30 ++++++++++++++--
python/problems/functions/divisors_sum/common.py | 28 +++++++++++++--
.../problems/functions/friendly_numbers/common.py | 31 ++++++++++++++---
python/problems/functions/friendly_numbers/en.py | 4 +--
python/problems/functions/friendly_numbers/sl.py | 6 ++--
python/problems/functions/greatest/common.py | 4 +++
.../functions/greatest_absolutist/common.py | 4 +++
.../problems/functions/greatest_negative/common.py | 4 +++
python/problems/functions/palindrome/common.py | 31 +++++++++++++++--
.../functions/palindromic_numbers/common.py | 28 +++++++++++++--
.../problems/functions/perfect_numbers/common.py | 27 +++++++++++++--
python/problems/functions/prime_numbers/common.py | 27 +++++++++++++--
.../problems/functions_and_modules/all/common.py | 32 +++++++++++++++--
.../problems/functions_and_modules/any/common.py | 30 ++++++++++++++--
.../functions_and_modules/caesar_cipher/common.py | 36 ++++++++++++++++---
python/problems/functions_and_modules/common.py | 2 ++
.../functions_and_modules/dominoes/common.py | 29 ++++++++++++++--
.../largest_sublist/common.py | 27 +++++++++++++--
.../functions_and_modules/lists_sum/common.py | 29 ++++++++++++++--
.../functions_and_modules/longest_word/common.py | 30 ++++++++++++++--
.../problems/functions_and_modules/map/common.py | 25 ++++++++++++--
.../multiplicative_range/common.py | 27 +++++++++++++--
.../functions_and_modules/similarity/common.py | 32 +++++++++++++++--
.../suspicious_words/common.py | 29 ++++++++++++++--
.../lists_and_for/calculator_polish/common.py | 33 ++++++++++++++++--
python/problems/lists_and_for/common.py | 1 +
.../lists_and_for/contains_multiples/common.py | 40 ++++++++++++++++++++--
python/problems/lists_and_for/divisors/common.py | 2 +-
.../problems/lists_and_for/divisors_sum/common.py | 2 +-
.../problems/lists_and_for/every_third/common.py | 34 ++++++++++++++++--
.../lists_and_for/perfect_numbers/common.py | 2 +-
python/problems/lists_and_for/places/common.py | 38 ++++++++++++++++++--
python/problems/lists_and_for/prefix/common.py | 25 ++++++++++++--
python/problems/lists_and_for/split_word/common.py | 26 +++++++++++---
python/problems/lists_and_for/substrings/common.py | 24 +++++++++++--
python/problems/while_and_if/common.py | 1 +
python/sl.py | 2 +-
41 files changed, 764 insertions(+), 96 deletions(-)
create mode 100644 python/problems/functions_and_modules/common.py
(limited to 'python')
diff --git a/python/problems/functions/assign_numbers/common.py b/python/problems/functions/assign_numbers/common.py
index f00305a..c9e87bf 100644
--- a/python/problems/functions/assign_numbers/common.py
+++ b/python/problems/functions/assign_numbers/common.py
@@ -23,12 +23,30 @@ hint_type = {
}
def test(python, code):
- test_in = [1]
+ func_name = 'numbers'
+ tokens = get_tokens(code)
+ if not has_token_sequence(tokens, ['def', func_name]):
+ return False, [{'id' : 'no_func_name', 'args' : {'func_name' : func_name}}]
+
+ in_out = [
+ ([], []),
+ ([1], [(0, 1)]),
+ ([5, 1, 4, 2, 3], [(0, 5), (1, 1), (2, 4), (3, 2), (4, 3)]),
+ ]
+
+ 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)
n_correct = 0
+ tin, tout = None, None
+ for i, (ans, to) in enumerate(zip(answers, test_out)):
+ n_correct += ans[0] == to
+ if ans[0] != to:
+ tin = test_in[i][0]
+ tout = to
passed = n_correct == len(test_in)
- tin = None
- tout = None
hints = [{'id': 'test_results', 'args': {'passed': n_correct, 'total': len(test_in)}}]
if tin:
hints.append({'id': 'problematic_test_case', 'args': {'testin': str(tin), 'testout': str(tout)}})
diff --git a/python/problems/functions/body_mass_index/common.py b/python/problems/functions/body_mass_index/common.py
index fba7570..22defeb 100644
--- a/python/problems/functions/body_mass_index/common.py
+++ b/python/problems/functions/body_mass_index/common.py
@@ -23,12 +23,33 @@ hint_type = {
}
def test(python, code):
- test_in = [1]
+ func_name = 'bmi'
+ tokens = get_tokens(code)
+ if not has_token_sequence(tokens, ['def', func_name]):
+ return False, [{'id' : 'no_func_name', 'args' : {'func_name' : func_name}}]
+
+ in_out = [
+ ([], []),
+ ([('Ana', 55, 165), ('Berta', 60, 153)],
+ [('Ana', 20.202020202020204), ('Berta', 25.63116749967961)]),
+ ([('Ana', 55, 165), ('Berta', 60, 153), ('Cilka', 70, 183)],
+ [('Ana', 20.202020202020204), ('Berta', 25.63116749967961), ('Cilka', 20.902385858042937)]),
+ ]
+
+ 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)
n_correct = 0
+ tin, tout = None, None
+ for i, (ans, to) in enumerate(zip(answers, test_out)):
+ n_correct += ans[0] == to
+ if ans[0] != to:
+ tin = test_in[i][0]
+ tout = to
passed = n_correct == len(test_in)
- tin = None
- tout = None
+
hints = [{'id': 'test_results', 'args': {'passed': n_correct, 'total': len(test_in)}}]
if tin:
hints.append({'id': 'problematic_test_case', 'args': {'testin': str(tin), 'testout': str(tout)}})
diff --git a/python/problems/functions/body_mass_index_2/common.py b/python/problems/functions/body_mass_index_2/common.py
index 58c7ab1..c94b7d1 100644
--- a/python/problems/functions/body_mass_index_2/common.py
+++ b/python/problems/functions/body_mass_index_2/common.py
@@ -23,12 +23,32 @@ hint_type = {
}
def test(python, code):
- test_in = [1]
+ func_name = 'bmi2'
+ tokens = get_tokens(code)
+ if not has_token_sequence(tokens, ['def', func_name]):
+ return False, [{'id' : 'no_func_name', 'args' : {'func_name' : func_name}}]
+
+ in_out = [
+ (([], [], []), []),
+ ((['Ana', 'Berta'], [55, 60], [165, 153]),
+ [('Ana', 20.202020202020204), ('Berta', 25.63116749967961)]),
+ ((['Ana', 'Berta', 'Cilka'], [55, 60, 70], [165, 153, 183]),
+ [('Ana', 20.202020202020204), ('Berta', 25.63116749967961), ('Cilka', 20.902385858042937)]),
+ ]
+
+ 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)
n_correct = 0
+ tin, tout = None, None
+ for i, (ans, to) in enumerate(zip(answers, test_out)):
+ n_correct += ans[0] == to
+ if ans[0] != to:
+ tin = test_in[i][0]
+ tout = to
passed = n_correct == len(test_in)
- tin = None
- tout = None
hints = [{'id': 'test_results', 'args': {'passed': n_correct, 'total': len(test_in)}}]
if tin:
hints.append({'id': 'problematic_test_case', 'args': {'testin': str(tin), 'testout': str(tout)}})
diff --git a/python/problems/functions/common.py b/python/problems/functions/common.py
index 1367877..ede78e6 100644
--- a/python/problems/functions/common.py
+++ b/python/problems/functions/common.py
@@ -1 +1,2 @@
id = 17
+number = 4
\ No newline at end of file
diff --git a/python/problems/functions/divisors/common.py b/python/problems/functions/divisors/common.py
index c3e71d8..0b6ba0d 100644
--- a/python/problems/functions/divisors/common.py
+++ b/python/problems/functions/divisors/common.py
@@ -22,12 +22,36 @@ hint_type = {
}
def test(python, code):
- test_in = [1]
+ func_name = 'divisors'
+ tokens = get_tokens(code)
+ if not has_token_sequence(tokens, ['def', func_name]):
+ return False, [{'id' : 'no_func_name', 'args' : {'func_name' : func_name}}]
+
+ in_out = [
+ (8, [1,2,4]),
+ (6, [1,2,3]),
+ (5, [1]),
+ (1, []),
+ (2, [1]),
+ (15, [1,3,5]),
+ (20, [1,2,4,5,10])
+ ]
+
+ 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)
n_correct = 0
+ tin, tout = None, None
+ for i, (ans, to) in enumerate(zip(answers, test_out)):
+ numbers = sorted(int(n) for n in get_numbers(ans[1]))
+ if numbers == to:
+ n_correct += 1
+ else:
+ tin = test_in[i][0]
+ tout = to
passed = n_correct == len(test_in)
- tin = None
- tout = None
hints = [{'id': 'test_results', 'args': {'passed': n_correct, 'total': len(test_in)}}]
if tin:
hints.append({'id': 'problematic_test_case', 'args': {'testin': str(tin), 'testout': str(tout)}})
diff --git a/python/problems/functions/divisors_sum/common.py b/python/problems/functions/divisors_sum/common.py
index d6a2b88..256fdc3 100644
--- a/python/problems/functions/divisors_sum/common.py
+++ b/python/problems/functions/divisors_sum/common.py
@@ -24,12 +24,34 @@ hint_type = {
}
def test(python, code):
- test_in = [1]
+ func_name = 'divisors_sum'
+ tokens = get_tokens(code)
+ if not has_token_sequence(tokens, ['def', func_name]):
+ return False, [{'id' : 'no_func_name', 'args' : {'func_name' : func_name}}]
+
+ in_out = [
+ (8, 7),
+ (6, 6),
+ (5, 1),
+ (1, 0),
+ (2, 1),
+ (15, 9),
+ (20, 22)
+ ]
+
+ 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)
n_correct = 0
+ tin, tout = None, None
+ for i, (ans, to) in enumerate(zip(answers, test_out)):
+ n_correct += ans[0] == to
+ if ans[0] != to:
+ tin = test_in[i][0]
+ tout = to
passed = n_correct == len(test_in)
- tin = None
- tout = None
hints = [{'id': 'test_results', 'args': {'passed': n_correct, 'total': len(test_in)}}]
if tin:
hints.append({'id': 'problematic_test_case', 'args': {'testin': str(tin), 'testout': str(tout)}})
diff --git a/python/problems/functions/friendly_numbers/common.py b/python/problems/functions/friendly_numbers/common.py
index 415040e..6588242 100644
--- a/python/problems/functions/friendly_numbers/common.py
+++ b/python/problems/functions/friendly_numbers/common.py
@@ -18,7 +18,7 @@ def divisors_sum(n):
s += i
return s
-def friendly_number(n):
+def amicable_number(n):
s = divisors_sum(n)
if n == divisors_sum(s):
return s
@@ -29,12 +29,35 @@ hint_type = {
}
def test(python, code):
- test_in = [1]
+ func_name = 'amicable_number'
+ tokens = get_tokens(code)
+ if not has_token_sequence(tokens, ['def', func_name]):
+ return False, [{'id' : 'no_func_name', 'args' : {'func_name' : func_name}}]
+
+ in_out = [
+ (220, 284),
+ (284, 220),
+ (1010, None),
+ (6, None),
+ (2620, 2924),
+ (1, None),
+ (10, None),
+ (1210, 1184)
+ ]
+
+ 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)
n_correct = 0
+ tin, tout = None, None
+ for i, (ans, to) in enumerate(zip(answers, test_out)):
+ n_correct += ans[0] == to
+ if ans[0] != to:
+ tin = test_in[i][0]
+ tout = to
passed = n_correct == len(test_in)
- tin = None
- tout = None
hints = [{'id': 'test_results', 'args': {'passed': n_correct, 'total': len(test_in)}}]
if tin:
hints.append({'id': 'problematic_test_case', 'args': {'testin': str(tin), 'testout': str(tout)}})
diff --git a/python/problems/functions/friendly_numbers/en.py b/python/problems/functions/friendly_numbers/en.py
index ba740ae..c77dca1 100644
--- a/python/problems/functions/friendly_numbers/en.py
+++ b/python/problems/functions/friendly_numbers/en.py
@@ -1,8 +1,8 @@
# coding=utf-8
id = 233
-name = 'Friendly numbers'
-slug = 'Friendly numbers'
+name = 'Amicable numbers'
+slug = 'Amicable numbers'
description = '''\
(translation missing)
'''
diff --git a/python/problems/functions/friendly_numbers/sl.py b/python/problems/functions/friendly_numbers/sl.py
index d1c15ff..51d47ae 100644
--- a/python/problems/functions/friendly_numbers/sl.py
+++ b/python/problems/functions/friendly_numbers/sl.py
@@ -12,12 +12,12 @@ description = '''\
220 in 284 sta prijateljski števili. Delitelji 220 so 1, 2, 4, 5, 10, 11, 20, 22, 44, 55 in 110.
Če jih seštejemo, dobimo 284. Delitelji 284 pa so 1, 2, 4, 71 in 142. Vsota teh števil pa je 220.
-Napiši funkcijo friendly_number(n)
, ki vrne prijateljsko število številu n
, če ga ima, oz.
+Napiši funkcijo amicable_number(n)
, ki vrne prijateljsko število številu n
, če ga ima, oz.
vrne None
, če ga nima. Primer:
->>> friendly_number(220)
+>>> amicable_number(220)
284
->>> friendly_number(222)
+>>> amicable_number(222)
None
diff --git a/python/problems/functions/greatest/common.py b/python/problems/functions/greatest/common.py
index 6857603..e6b7139 100644
--- a/python/problems/functions/greatest/common.py
+++ b/python/problems/functions/greatest/common.py
@@ -32,6 +32,10 @@ hint_type = {
}
def test(python, code):
+ tokens = get_tokens(code)
+ if not has_token_sequence(tokens, ['def', 'max_val']):
+ return False, [{'id' : 'no_func_name', 'args' : {'func_name' : 'max_val'}}]
+
test_lists = [[6, 4, 2, 0],
[4, 6, 2, 0],
[4, 2, 6, 0],
diff --git a/python/problems/functions/greatest_absolutist/common.py b/python/problems/functions/greatest_absolutist/common.py
index 2d80097..564d0c8 100644
--- a/python/problems/functions/greatest_absolutist/common.py
+++ b/python/problems/functions/greatest_absolutist/common.py
@@ -35,6 +35,10 @@ hint_type = {
def test(python, code):
+ tokens = get_tokens(code)
+ if not has_token_sequence(tokens, ['def', 'max_abs']):
+ return False, [{'id' : 'no_func_name', 'args' : {'func_name' : 'max_abs'}}]
+
test_lists = [[6, 4, 2, 0],
[4, 6, 2, 0],
[4, 2, 6, 0],
diff --git a/python/problems/functions/greatest_negative/common.py b/python/problems/functions/greatest_negative/common.py
index 5d65438..7ab3aca 100644
--- a/python/problems/functions/greatest_negative/common.py
+++ b/python/problems/functions/greatest_negative/common.py
@@ -35,6 +35,10 @@ hint_type = {
def test(python, code):
+ tokens = get_tokens(code)
+ if not has_token_sequence(tokens, ['def', 'max_neg']):
+ return False, [{'id' : 'no_func_name', 'args' : {'func_name' : 'max_neg'}}]
+
test_lists = [[6, 4, 2, 0],
[4, 6, 2, -1],
[4, -2, -6, 0],
diff --git a/python/problems/functions/palindrome/common.py b/python/problems/functions/palindrome/common.py
index e012e8d..9bd82f4 100644
--- a/python/problems/functions/palindrome/common.py
+++ b/python/problems/functions/palindrome/common.py
@@ -20,12 +20,37 @@ hint_type = {
}
def test(python, code):
- test_in = [1]
+ func_name = 'palindrome'
+ tokens = get_tokens(code)
+ if not has_token_sequence(tokens, ['def', func_name]):
+ return False, [{'id' : 'no_func_name', 'args' : {'func_name' : func_name}}]
+
+ in_out = [
+ ('', True),
+ ('a', True),
+ ('aa', True),
+ ('ab', False),
+ ('aba', True),
+ ('abc', False),
+ ('abcdefedcba', True),
+ ('abcdefgedcba', False),
+ ('pericarezeracirep', True),
+ ('perica', False),
+ ]
+
+ 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)
n_correct = 0
+ tin, tout = None, None
+ for i, (ans, to) in enumerate(zip(answers, test_out)):
+ n_correct += ans[0] == to
+ if ans[0] != to:
+ tin = test_in[i][0]
+ tout = to
passed = n_correct == len(test_in)
- tin = None
- tout = None
hints = [{'id': 'test_results', 'args': {'passed': n_correct, 'total': len(test_in)}}]
if tin:
hints.append({'id': 'problematic_test_case', 'args': {'testin': str(tin), 'testout': str(tout)}})
diff --git a/python/problems/functions/palindromic_numbers/common.py b/python/problems/functions/palindromic_numbers/common.py
index ba518c7..b649719 100644
--- a/python/problems/functions/palindromic_numbers/common.py
+++ b/python/problems/functions/palindromic_numbers/common.py
@@ -25,12 +25,34 @@ hint_type = {
}
def test(python, code):
- test_in = [1]
+ func_name = 'numbers'
+ tokens = get_tokens(code)
+ if not has_token_sequence(tokens, ['def', func_name]):
+ return False, [{'id' : 'no_func_name', 'args' : {'func_name' : func_name}}]
+
+ in_out = [
+ (906609, True),
+ (123456, False),
+ (1, True),
+ (11, True),
+ (12, False),
+ (113, False),
+ (131, True)
+ ]
+
+ 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)
n_correct = 0
+ tin, tout = None, None
+ for i, (ans, to) in enumerate(zip(answers, test_out)):
+ n_correct += ans[0] == to
+ if ans[0] != to:
+ tin = test_in[i][0]
+ tout = to
passed = n_correct == len(test_in)
- tin = None
- tout = None
hints = [{'id': 'test_results', 'args': {'passed': n_correct, 'total': len(test_in)}}]
if tin:
hints.append({'id': 'problematic_test_case', 'args': {'testin': str(tin), 'testout': str(tout)}})
diff --git a/python/problems/functions/perfect_numbers/common.py b/python/problems/functions/perfect_numbers/common.py
index ad1a7cd..64acb23 100644
--- a/python/problems/functions/perfect_numbers/common.py
+++ b/python/problems/functions/perfect_numbers/common.py
@@ -27,12 +27,33 @@ hint_type = {
}
def test(python, code):
- test_in = [1]
+ func_name = 'perfect'
+ tokens = get_tokens(code)
+ if not has_token_sequence(tokens, ['def', func_name]):
+ return False, [{'id' : 'no_func_name', 'args' : {'func_name' : func_name}}]
+
+ in_out = [
+ (6, True),
+ (28, True),
+ (1, False),
+ (5, False),
+ (496, True),
+ (497, False),
+ ]
+
+ 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)
n_correct = 0
+ tin, tout = None, None
+ for i, (ans, to) in enumerate(zip(answers, test_out)):
+ n_correct += ans[0] == to
+ if ans[0] != to:
+ tin = test_in[i][0]
+ tout = to
passed = n_correct == len(test_in)
- tin = None
- tout = None
hints = [{'id': 'test_results', 'args': {'passed': n_correct, 'total': len(test_in)}}]
if tin:
hints.append({'id': 'problematic_test_case', 'args': {'testin': str(tin), 'testout': str(tout)}})
diff --git a/python/problems/functions/prime_numbers/common.py b/python/problems/functions/prime_numbers/common.py
index 0447c61..6806a08 100644
--- a/python/problems/functions/prime_numbers/common.py
+++ b/python/problems/functions/prime_numbers/common.py
@@ -25,12 +25,33 @@ hint_type = {
}
def test(python, code):
- test_in = [1]
+ func_name = 'prime'
+ tokens = get_tokens(code)
+ if not has_token_sequence(tokens, ['def', func_name]):
+ return False, [{'id' : 'no_func_name', 'args' : {'func_name' : func_name}}]
+
+ in_out = [
+ (3, [2]),
+ (10, [2, 3, 5, 7]),
+ (100, [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97]),
+ ]
+
+ 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)
n_correct = 0
+ tin, tout = None, None
+ for i, (ans, to) in enumerate(zip(answers, test_out)):
+ numbers = sorted([int(n) for n in get_numbers(ans[1])])
+
+ if numbers == to:
+ n_correct += 1
+ else:
+ tin = test_in[i][0]
+ tout = to
passed = n_correct == len(test_in)
- tin = None
- tout = None
hints = [{'id': 'test_results', 'args': {'passed': n_correct, 'total': len(test_in)}}]
if tin:
hints.append({'id': 'problematic_test_case', 'args': {'testin': str(tin), 'testout': str(tout)}})
diff --git a/python/problems/functions_and_modules/all/common.py b/python/problems/functions_and_modules/all/common.py
index 7fb60f5..e87aa74 100644
--- a/python/problems/functions_and_modules/all/common.py
+++ b/python/problems/functions_and_modules/all/common.py
@@ -23,12 +23,37 @@ hint_type = {
}
def test(python, code):
- test_in = [1]
+ func_name = 'all'
+ tokens = get_tokens(code)
+ if not has_token_sequence(tokens, ['def', func_name]):
+ return False, [{'id' : 'no_func_name', 'args' : {'func_name' : func_name}}]
+
+ in_out = [
+ ([True, True, False], False),
+ ([True, True], True),
+ ([1, 2, 3, 0], False),
+ (['foo', 42, True], True),
+ (['foo', '', 42, True], False),
+ (['foo', 0.0, 42, True], False),
+ (['foo', None, 42, True], False),
+ (['foo', (), 42, True], False),
+ (['foo', [], 42, True], False),
+ ([], True),
+ ]
+
+ 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)
n_correct = 0
+ tin, tout = None, None
+ for i, (ans, to) in enumerate(zip(answers, test_out)):
+ n_correct += ans[0] == to
+ if ans[0] != to:
+ tin = test_in[i][0]
+ tout = to
passed = n_correct == len(test_in)
- tin = None
- tout = None
hints = [{'id': 'test_results', 'args': {'passed': n_correct, 'total': len(test_in)}}]
if tin:
hints.append({'id': 'problematic_test_case', 'args': {'testin': str(tin), 'testout': str(tout)}})
@@ -36,6 +61,7 @@ def test(python, code):
hints.append({'id': 'final_hint'})
return passed, hints
+
def hint(python, code):
tokens = get_tokens(code)
diff --git a/python/problems/functions_and_modules/any/common.py b/python/problems/functions_and_modules/any/common.py
index 78867c5..a96ae04 100644
--- a/python/problems/functions_and_modules/any/common.py
+++ b/python/problems/functions_and_modules/any/common.py
@@ -23,12 +23,35 @@ hint_type = {
}
def test(python, code):
- test_in = [1]
+ func_name = 'any'
+ tokens = get_tokens(code)
+ if not has_token_sequence(tokens, ['def', func_name]):
+ return False, [{'id' : 'no_func_name', 'args' : {'func_name' : func_name}}]
+
+ in_out = [
+ ([2, 3, 0], True),
+ ([], False),
+ ([True, False, False], True),
+ ([False, False], False),
+ (['foo', 42, True], True),
+ ([False, 0, 0.0, '', None, (), []], False),
+ ([False, 0, 0.42, '', None, (), []], True),
+ ([False, 0, 0.0, '', None, (), [42]], True),
+ ]
+
+ 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)
n_correct = 0
+ tin, tout = None, None
+ for i, (ans, to) in enumerate(zip(answers, test_out)):
+ n_correct += ans[0] == to
+ if ans[0] != to:
+ tin = test_in[i][0]
+ tout = to
passed = n_correct == len(test_in)
- tin = None
- tout = None
hints = [{'id': 'test_results', 'args': {'passed': n_correct, 'total': len(test_in)}}]
if tin:
hints.append({'id': 'problematic_test_case', 'args': {'testin': str(tin), 'testout': str(tout)}})
@@ -36,6 +59,7 @@ def test(python, code):
hints.append({'id': 'final_hint'})
return passed, hints
+
def hint(python, code):
tokens = get_tokens(code)
diff --git a/python/problems/functions_and_modules/caesar_cipher/common.py b/python/problems/functions_and_modules/caesar_cipher/common.py
index 494a7f9..3c53369 100644
--- a/python/problems/functions_and_modules/caesar_cipher/common.py
+++ b/python/problems/functions_and_modules/caesar_cipher/common.py
@@ -20,7 +20,7 @@ def caesar(s):
cipher += chr(ord(c) - 23)
else:
cipher += c
- return cipher)
+ return cipher
'''
hint_type = {
@@ -28,12 +28,39 @@ hint_type = {
}
def test(python, code):
- test_in = [1]
+ func_name = 'caesar'
+ tokens = get_tokens(code)
+ if not has_token_sequence(tokens, ['def', func_name]):
+ return False, [{'id' : 'no_func_name', 'args' : {'func_name' : func_name}}]
+
+ in_out = [
+ ('', ''),
+ ('a', 'd'),
+ ('aa', 'dd'),
+ ('ab', 'de'),
+ ('z', 'c'),
+ ('xyz', 'abc'),
+ (' ', ' '),
+ ('a a', 'd d'),
+ ('julij cezar je seveda uporabljal cezarjevo sifro',
+ 'mxolm fhcdu mh vhyhgd xsrudeomdo fhcdumhyr vliur'),
+ ('the quick brown fox jumps over the lazy dog',
+ 'wkh txlfn eurzq ira mxpsv ryhu wkh odcb grj'),
+ ]
+
+ 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)
n_correct = 0
+ tin, tout = None, None
+ for i, (ans, to) in enumerate(zip(answers, test_out)):
+ n_correct += ans[0] == to
+ if ans[0] != to:
+ tin = test_in[i][0]
+ tout = to
passed = n_correct == len(test_in)
- tin = None
- tout = None
hints = [{'id': 'test_results', 'args': {'passed': n_correct, 'total': len(test_in)}}]
if tin:
hints.append({'id': 'problematic_test_case', 'args': {'testin': str(tin), 'testout': str(tout)}})
@@ -41,6 +68,7 @@ def test(python, code):
hints.append({'id': 'final_hint'})
return passed, hints
+
def hint(python, code):
tokens = get_tokens(code)
diff --git a/python/problems/functions_and_modules/common.py b/python/problems/functions_and_modules/common.py
new file mode 100644
index 0000000..915b041
--- /dev/null
+++ b/python/problems/functions_and_modules/common.py
@@ -0,0 +1,2 @@
+id = 18
+number = 5
\ No newline at end of file
diff --git a/python/problems/functions_and_modules/dominoes/common.py b/python/problems/functions_and_modules/dominoes/common.py
index 5e73d8e..4a0f439 100644
--- a/python/problems/functions_and_modules/dominoes/common.py
+++ b/python/problems/functions_and_modules/dominoes/common.py
@@ -23,12 +23,34 @@ hint_type = {
}
def test(python, code):
- test_in = [1]
+ func_name = 'dominoes'
+ tokens = get_tokens(code)
+ if not has_token_sequence(tokens, ['def', func_name]):
+ return False, [{'id' : 'no_func_name', 'args' : {'func_name' : func_name}}]
+
+ in_out = [
+ ([], True),
+ ([(2, 4), (4, 4)], True),
+ ([(2, 4), (4, 4), (4, 2)], True),
+ ([(2, 4), (4, 4), (4, 2), (2, 9), (9, 1)], True),
+ ([(2, 4), (4, 3), (4, 2), (2, 9), (9, 1)], False),
+ ([(3, 6), (6, 6), (6, 1), (1, 0)], True),
+ ([(3, 6), (6, 6), (2, 3)], False),
+ ]
+
+ 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)
n_correct = 0
+ tin, tout = None, None
+ for i, (ans, to) in enumerate(zip(answers, test_out)):
+ n_correct += ans[0] == to
+ if ans[0] != to:
+ tin = test_in[i][0]
+ tout = to
passed = n_correct == len(test_in)
- tin = None
- tout = None
hints = [{'id': 'test_results', 'args': {'passed': n_correct, 'total': len(test_in)}}]
if tin:
hints.append({'id': 'problematic_test_case', 'args': {'testin': str(tin), 'testout': str(tout)}})
@@ -36,6 +58,7 @@ def test(python, code):
hints.append({'id': 'final_hint'})
return passed, hints
+
def hint(python, code):
tokens = get_tokens(code)
diff --git a/python/problems/functions_and_modules/largest_sublist/common.py b/python/problems/functions_and_modules/largest_sublist/common.py
index 372e34f..90e3ae4 100644
--- a/python/problems/functions_and_modules/largest_sublist/common.py
+++ b/python/problems/functions_and_modules/largest_sublist/common.py
@@ -29,12 +29,32 @@ hint_type = {
}
def test(python, code):
- test_in = [1]
+ func_name = 'largest_sublist'
+ tokens = get_tokens(code)
+ if not has_token_sequence(tokens, ['def', func_name]):
+ return False, [{'id' : 'no_func_name', 'args' : {'func_name' : func_name}}]
+
+ in_out = [
+ ([[0]], [0]),
+ ([[1, 2]], [1, 2]),
+ ([[1, 2], [], [0]], [1, 2]),
+ ([[2, 4, 1], [3, 1], [], [8, 2], [1, 1, 1, 1]], [8, 2]),
+ ([[5, 3, 6, 3], [1, 2, 3, 4], [5, -1, 0]], [5, 3, 6, 3]),
+ ]
+
+ 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)
n_correct = 0
+ tin, tout = None, None
+ for i, (ans, to) in enumerate(zip(answers, test_out)):
+ n_correct += ans[0] == to
+ if ans[0] != to:
+ tin = test_in[i][0]
+ tout = to
passed = n_correct == len(test_in)
- tin = None
- tout = None
hints = [{'id': 'test_results', 'args': {'passed': n_correct, 'total': len(test_in)}}]
if tin:
hints.append({'id': 'problematic_test_case', 'args': {'testin': str(tin), 'testout': str(tout)}})
@@ -42,6 +62,7 @@ def test(python, code):
hints.append({'id': 'final_hint'})
return passed, hints
+
def hint(python, code):
tokens = get_tokens(code)
diff --git a/python/problems/functions_and_modules/lists_sum/common.py b/python/problems/functions_and_modules/lists_sum/common.py
index d3afef4..d6ba72f 100644
--- a/python/problems/functions_and_modules/lists_sum/common.py
+++ b/python/problems/functions_and_modules/lists_sum/common.py
@@ -26,12 +26,34 @@ hint_type = {
}
def test(python, code):
- test_in = [1]
+ func_name = 'lists_sum'
+ tokens = get_tokens(code)
+ if not has_token_sequence(tokens, ['def', func_name]):
+ return False, [{'id' : 'no_func_name', 'args' : {'func_name' : func_name}}]
+
+ in_out = [
+ ([], []),
+ ([[]], [0]),
+ ([[0]], [0]),
+ ([[1, 2]], [3]),
+ ([[1, 2], [], [0]], [3, 0, 0]),
+ ([[2, 4, 1], [3, 1], [], [8, 2], [1, 1, 1, 1]], [7, 4, 0, 10, 4]),
+ ([[5, 3, 6, 3], [1, 2, 3, 4], [5, -1, 0]], [17, 10, 4]),
+ ]
+
+ 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)
n_correct = 0
+ tin, tout = None, None
+ for i, (ans, to) in enumerate(zip(answers, test_out)):
+ n_correct += ans[0] == to
+ if ans[0] != to:
+ tin = test_in[i][0]
+ tout = to
passed = n_correct == len(test_in)
- tin = None
- tout = None
hints = [{'id': 'test_results', 'args': {'passed': n_correct, 'total': len(test_in)}}]
if tin:
hints.append({'id': 'problematic_test_case', 'args': {'testin': str(tin), 'testout': str(tout)}})
@@ -39,6 +61,7 @@ def test(python, code):
hints.append({'id': 'final_hint'})
return passed, hints
+
def hint(python, code):
tokens = get_tokens(code)
diff --git a/python/problems/functions_and_modules/longest_word/common.py b/python/problems/functions_and_modules/longest_word/common.py
index 1201c1d..3ddb269 100644
--- a/python/problems/functions_and_modules/longest_word/common.py
+++ b/python/problems/functions_and_modules/longest_word/common.py
@@ -24,12 +24,35 @@ hint_type = {
}
def test(python, code):
- test_in = [1]
+ func_name = 'longest'
+ tokens = get_tokens(code)
+ if not has_token_sequence(tokens, ['def', func_name]):
+ return False, [{'id' : 'no_func_name', 'args' : {'func_name' : func_name}}]
+
+ in_out = [
+ ('beseda', 'beseda'),
+ ('an ban', 'ban'),
+ ('an ban pet podgan', 'podgan'),
+ ('an ban pet podgan stiri misi', 'podgan'),
+ ('ta clanek je lepo napisan', 'napisan'),
+ ('123456 12345 1234 123 12 1', '123456'),
+ ('12345 123456 12345 1234 123 12 1', '123456'),
+ ('1234 12345 123456 12345 1234 123 12 1', '123456'),
+ ]
+
+ 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)
n_correct = 0
+ tin, tout = None, None
+ for i, (ans, to) in enumerate(zip(answers, test_out)):
+ n_correct += ans[0] == to
+ if ans[0] != to:
+ tin = test_in[i][0]
+ tout = to
passed = n_correct == len(test_in)
- tin = None
- tout = None
hints = [{'id': 'test_results', 'args': {'passed': n_correct, 'total': len(test_in)}}]
if tin:
hints.append({'id': 'problematic_test_case', 'args': {'testin': str(tin), 'testout': str(tout)}})
@@ -37,6 +60,7 @@ def test(python, code):
hints.append({'id': 'final_hint'})
return passed, hints
+
def hint(python, code):
tokens = get_tokens(code)
diff --git a/python/problems/functions_and_modules/map/common.py b/python/problems/functions_and_modules/map/common.py
index e28f356..ace0a09 100644
--- a/python/problems/functions_and_modules/map/common.py
+++ b/python/problems/functions_and_modules/map/common.py
@@ -23,12 +23,30 @@ hint_type = {
}
def test(python, code):
- test_in = [1]
+ func_name = 'map'
+ tokens = get_tokens(code)
+ if not has_token_sequence(tokens, ['def', func_name]):
+ return False, [{'id' : 'no_func_name', 'args' : {'func_name' : func_name}}]
+
+ in_out = [
+ (('abs', [-5, 8, -3, -1, 3]), [5, 8, 3, 1, 3]),
+ (('len', 'Daydream delusion limousine eyelash'.split()), [8, 8, 9, 7]),
+ (('int', '1 3 5 42'.split()), [1, 3, 5, 42]),
+ ]
+
+ test_in = [(func_name+'({l[0]},{l[1]})'.format(l = 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)
n_correct = 0
+ tin, tout = None, None
+ for i, (ans, to) in enumerate(zip(answers, test_out)):
+ n_correct += ans[0] == to
+ if ans[0] != to:
+ tin = test_in[i][0]
+ tout = to
passed = n_correct == len(test_in)
- tin = None
- tout = None
hints = [{'id': 'test_results', 'args': {'passed': n_correct, 'total': len(test_in)}}]
if tin:
hints.append({'id': 'problematic_test_case', 'args': {'testin': str(tin), 'testout': str(tout)}})
@@ -36,6 +54,7 @@ def test(python, code):
hints.append({'id': 'final_hint'})
return passed, hints
+
def hint(python, code):
tokens = get_tokens(code)
diff --git a/python/problems/functions_and_modules/multiplicative_range/common.py b/python/problems/functions_and_modules/multiplicative_range/common.py
index 9a52dce..0cb2fef 100644
--- a/python/problems/functions_and_modules/multiplicative_range/common.py
+++ b/python/problems/functions_and_modules/multiplicative_range/common.py
@@ -24,12 +24,32 @@ hint_type = {
}
def test(python, code):
- test_in = [1]
+ func_name = 'mrange'
+ tokens = get_tokens(code)
+ if not has_token_sequence(tokens, ['def', func_name]):
+ return False, [{'id' : 'no_func_name', 'args' : {'func_name' : func_name}}]
+
+ in_out = [
+ ((32, 2, 0), []),
+ ((32, 2, 1), [32]),
+ ((32, 2, 2), [32, 64]),
+ ((42, -1, 5), [42, -42, 42, -42, 42]),
+ ((7, 4, 7), [7, 28, 112, 448, 1792, 7168, 28672]),
+ ]
+
+ 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)
n_correct = 0
+ tin, tout = None, None
+ for i, (ans, to) in enumerate(zip(answers, test_out)):
+ n_correct += ans[0] == to
+ if ans[0] != to:
+ tin = test_in[i][0]
+ tout = to
passed = n_correct == len(test_in)
- tin = None
- tout = None
hints = [{'id': 'test_results', 'args': {'passed': n_correct, 'total': len(test_in)}}]
if tin:
hints.append({'id': 'problematic_test_case', 'args': {'testin': str(tin), 'testout': str(tout)}})
@@ -37,6 +57,7 @@ def test(python, code):
hints.append({'id': 'final_hint'})
return passed, hints
+
def hint(python, code):
tokens = get_tokens(code)
diff --git a/python/problems/functions_and_modules/similarity/common.py b/python/problems/functions_and_modules/similarity/common.py
index 5cb8fe7..d71137e 100644
--- a/python/problems/functions_and_modules/similarity/common.py
+++ b/python/problems/functions_and_modules/similarity/common.py
@@ -24,12 +24,37 @@ hint_type = {
}
def test(python, code):
- test_in = [1]
+ func_name = 'similarity'
+ tokens = get_tokens(code)
+ if not has_token_sequence(tokens, ['def', func_name]):
+ return False, [{'id' : 'no_func_name', 'args' : {'func_name' : func_name}}]
+
+ in_out = [
+ (('sobota', 'robot'), 4),
+ (('', 'robot'), 0),
+ (('sobota', ''), 0),
+ (('', ''), 0),
+ (('a', 'b'), 0),
+ (('a', 'a'), 1),
+ (('aaa', 'a'), 1),
+ (('amper', 'amonijak'), 2),
+ (('1000 let', 'tisoc let'), 0),
+ (('hamming distance', 'haming distance'), 12)
+ ]
+
+ 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)
n_correct = 0
+ tin, tout = None, None
+ for i, (ans, to) in enumerate(zip(answers, test_out)):
+ n_correct += ans[0] == to
+ if ans[0] != to:
+ tin = test_in[i][0]
+ tout = to
passed = n_correct == len(test_in)
- tin = None
- tout = None
hints = [{'id': 'test_results', 'args': {'passed': n_correct, 'total': len(test_in)}}]
if tin:
hints.append({'id': 'problematic_test_case', 'args': {'testin': str(tin), 'testout': str(tout)}})
@@ -37,6 +62,7 @@ def test(python, code):
hints.append({'id': 'final_hint'})
return passed, hints
+
def hint(python, code):
tokens = get_tokens(code)
diff --git a/python/problems/functions_and_modules/suspicious_words/common.py b/python/problems/functions_and_modules/suspicious_words/common.py
index 74868ab..e6e119a 100644
--- a/python/problems/functions_and_modules/suspicious_words/common.py
+++ b/python/problems/functions_and_modules/suspicious_words/common.py
@@ -24,12 +24,34 @@ hint_type = {
}
def test(python, code):
- test_in = [1]
+ func_name = 'suspicious'
+ tokens = get_tokens(code)
+ if not has_token_sequence(tokens, ['def', func_name]):
+ return False, [{'id' : 'no_func_name', 'args' : {'func_name' : func_name}}]
+
+ in_out = [
+ ('', []),
+ ('aa uu', []),
+ ('aa uu au', ['au']),
+ ('muha', ['muha']),
+ ('Muha pa je rekla: "Tale juha se je pa res prilegla, najlepša huala," in odletela.',
+ ['Muha', 'juha', 'huala,"']),
+ ('ameba nima aja in uja, ampak samo a', ['uja,']),
+ ]
+
+ test_in = [(func_name+"('"+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)
n_correct = 0
+ tin, tout = None, None
+ for i, (ans, to) in enumerate(zip(answers, test_out)):
+ n_correct += ans[0] == to
+ if ans[0] != to:
+ tin = test_in[i][0]
+ tout = to
passed = n_correct == len(test_in)
- tin = None
- tout = None
hints = [{'id': 'test_results', 'args': {'passed': n_correct, 'total': len(test_in)}}]
if tin:
hints.append({'id': 'problematic_test_case', 'args': {'testin': str(tin), 'testout': str(tout)}})
@@ -37,6 +59,7 @@ def test(python, code):
hints.append({'id': 'final_hint'})
return passed, hints
+
def hint(python, code):
tokens = get_tokens(code)
diff --git a/python/problems/lists_and_for/calculator_polish/common.py b/python/problems/lists_and_for/calculator_polish/common.py
index d08f19c..7ea25ce 100644
--- a/python/problems/lists_and_for/calculator_polish/common.py
+++ b/python/problems/lists_and_for/calculator_polish/common.py
@@ -46,12 +46,39 @@ hint_type = {
}
def test(python, code):
- test_in = [1]
+ in_out = [
+ (['6 3 +'], [9]),
+ (['6 3 -'], [3]),
+ (['6 3 /'], [2]),
+ (['7 3 /'], [2]),
+ (['6 3 *'], [18]),
+ (['6 3 %'], [0]),
+ (['1 2 +', '2 3 +', '1 2 3 4 5 * * * *'], [3, 5, 120]),
+ (['1 2 + 3 +'], [6]),
+ (['1 2 3 + +'], [6]),
+ (['1 2 + 3 4 + *'], [21]),
+ (['1 2 3 * 4 + +'], [11]),
+ (['3 5 + 2 * 10 2 1 - * -'], [6]),
+ (['11 22 33 * * 7 + 2 / 100 % 1 2 - -'], [97]),
+ ]
+
+ 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)
+ outputs = [ans[1] for ans in answers]
+
n_correct = 0
+ tin = None
+ for i, (output, correct) in enumerate(zip(outputs, test_out)):
+ if all(string_almost_equal(output, c, prec=2) for c in correct):
+ n_correct += 1
+ else:
+ tin = test_in[i][1]
+ tout = correct
passed = n_correct == len(test_in)
- tin = None
- tout = None
+
hints = [{'id': 'test_results', 'args': {'passed': n_correct, 'total': len(test_in)}}]
if tin:
hints.append({'id': 'problematic_test_case', 'args': {'testin': str(tin), 'testout': str(tout)}})
diff --git a/python/problems/lists_and_for/common.py b/python/problems/lists_and_for/common.py
index b490107..fe6aa94 100644
--- a/python/problems/lists_and_for/common.py
+++ b/python/problems/lists_and_for/common.py
@@ -1 +1,2 @@
id = 16
+number = 3
\ No newline at end of file
diff --git a/python/problems/lists_and_for/contains_multiples/common.py b/python/problems/lists_and_for/contains_multiples/common.py
index 8bdcc36..4712106 100644
--- a/python/problems/lists_and_for/contains_multiples/common.py
+++ b/python/problems/lists_and_for/contains_multiples/common.py
@@ -25,12 +25,46 @@ hint_type = {
}
def test(python, code):
- test_in = [1]
+ in_out = [
+ ([], False),
+ ([0], True),
+ ([42], True),
+ ([42 * 43], True),
+ ([4, 2], False),
+ ([42, 42], True),
+ ([1, 2, 3, 4, 5, 5, 4, 3, 2, 1], False),
+ ([1, 2, 3, 4, 5, 5, 4, 3, 2, 1, -42], True),
+ ([1, 2, 3, 4, 5, 42 * 3, 5, 4, 3, 2, 1], True),
+ ([1, 2, 42, 4, 5, 42 * 5, 5, 4, 42 * 3, 2, 1], True),
+ ([42, 5, 4, -7, 2, 12, -3, -4, 11, 42, 2], True)
+ ]
+
+
+ test_in = [t[0] for t in in_out]
+ test_out = [t[1] for t in in_out]
+
n_correct = 0
+ tin = None
+ for xs_i, xs in enumerate(test_in):
+ # change code to contain new xs instead of the one
+ # given by user
+ tcode = re.sub(r'^xs\s*=\s*\[.*?\]',
+ 'xs = ' + str(xs),
+ code,
+ flags = re.DOTALL | re.MULTILINE)
+ # use python session to call tcode
+ answers = python(code=tcode, inputs=[(None, None)], timeout=1.0)
+ output = answers[0][1]
+
+ if str(test_out[xs_i]) in output and \
+ str((not test_out[xs_i])) not in output:
+ n_correct += 1
+ else:
+ tin = test_in[xs_i]
+ tout = test_out[xs_i]
passed = n_correct == len(test_in)
- tin = None
- tout = None
+
hints = [{'id': 'test_results', 'args': {'passed': n_correct, 'total': len(test_in)}}]
if tin:
hints.append({'id': 'problematic_test_case', 'args': {'testin': str(tin), 'testout': str(tout)}})
diff --git a/python/problems/lists_and_for/divisors/common.py b/python/problems/lists_and_for/divisors/common.py
index f9334be..89092eb 100644
--- a/python/problems/lists_and_for/divisors/common.py
+++ b/python/problems/lists_and_for/divisors/common.py
@@ -8,7 +8,7 @@ from server.hints import Hint
id = 204
group = 'lists_and_for'
number = 20
-visible = False
+visible = True
solution = '''\
n = int(input('Vnesi število: '))
diff --git a/python/problems/lists_and_for/divisors_sum/common.py b/python/problems/lists_and_for/divisors_sum/common.py
index 651f657..c557278 100644
--- a/python/problems/lists_and_for/divisors_sum/common.py
+++ b/python/problems/lists_and_for/divisors_sum/common.py
@@ -8,7 +8,7 @@ from server.hints import Hint
id = 216
group = 'lists_and_for'
number = 21
-visible = False
+visible = True
solution = '''\
n = int(input('Vnesi število: '))
diff --git a/python/problems/lists_and_for/every_third/common.py b/python/problems/lists_and_for/every_third/common.py
index 9c27446..6f42663 100644
--- a/python/problems/lists_and_for/every_third/common.py
+++ b/python/problems/lists_and_for/every_third/common.py
@@ -26,12 +26,40 @@ hint_type = {
}
def test(python, code):
- test_in = [1]
+ in_out = [
+ ([], []),
+ ([0], []),
+ ([0, 1], []),
+ ([0, 1, 2], [2]),
+ ([1, 2, 3, 4, 5, 5, 4, 3, 2, 1], [3, 5, 2]),
+ ([42, 5, 4, -7, 2, 12, -3, -4, 11, 42, 2], [4, 12, 11]),
+ (list(range(15)), [2, 5, 8, 11, 14])
+ ]
+
+ test_in = [t[0] for t in in_out]
+ test_out = [t[1] for t in in_out]
+
n_correct = 0
+ tin = None
+ for xs_i, xs in enumerate(test_in):
+ # change code to contain new xs instead of the one
+ # given by user
+ tcode = re.sub(r'^xs\s*=\s*\[.*?\]',
+ 'xs = ' + str(xs),
+ code,
+ flags = re.DOTALL | re.MULTILINE)
+ # use python session to call tcode
+ answers = python(code=tcode, inputs=[(None, None)], timeout=1.0)
+ output = answers[0][1]
+
+ if str(test_out[xs_i]) in output:
+ n_correct += 1
+ else:
+ tin = test_in[xs_i]
+ tout = test_out[xs_i]
passed = n_correct == len(test_in)
- tin = None
- tout = None
+
hints = [{'id': 'test_results', 'args': {'passed': n_correct, 'total': len(test_in)}}]
if tin:
hints.append({'id': 'problematic_test_case', 'args': {'testin': str(tin), 'testout': str(tout)}})
diff --git a/python/problems/lists_and_for/perfect_numbers/common.py b/python/problems/lists_and_for/perfect_numbers/common.py
index c1c7645..2628fab 100644
--- a/python/problems/lists_and_for/perfect_numbers/common.py
+++ b/python/problems/lists_and_for/perfect_numbers/common.py
@@ -8,7 +8,7 @@ from server.hints import Hint
id = 217
group = 'lists_and_for'
number = 22
-visible = False
+visible = True
solution = '''\
n = int(input('Vnesi število: '))
diff --git a/python/problems/lists_and_for/places/common.py b/python/problems/lists_and_for/places/common.py
index 66db7a3..0a90771 100644
--- a/python/problems/lists_and_for/places/common.py
+++ b/python/problems/lists_and_for/places/common.py
@@ -25,12 +25,44 @@ hint_type = {
}
def test(python, code):
- test_in = [1]
+ in_out = [
+ ([], []),
+ ([0], []),
+ ([42], [0]),
+ ([4, 2], []),
+ ([42, 42], [0, 1]),
+ ([1, 2, 3, 4, 5, 5, 4, 3, 2, 1], []),
+ ([1, 2, 3, 4, 5, 5, 4, 3, 2, 1, 42], [10]),
+ ([1, 2, 3, 4, 5, 42, 5, 4, 3, 2, 1], [5]),
+ ([1, 2, 42, 4, 5, 42, 5, 4, 42, 2, 1], [2, 5, 8]),
+ ([42, 5, 4, -7, 2, 12, -3, -4, 11, 42, 2], [0, 9]),
+ ([42] * 10, [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]),
+ ]
+
+ test_in = [t[0] for t in in_out]
+ test_out = [t[1] for t in in_out]
+
n_correct = 0
+ tin = None
+ for xs_i, xs in enumerate(test_in):
+ # change code to contain new xs instead of the one
+ # given by user
+ tcode = re.sub(r'^xs\s*=\s*\[.*?\]',
+ 'xs = ' + str(xs),
+ code,
+ flags = re.DOTALL | re.MULTILINE)
+
+ # use python session to call tcode
+ answers = python(code=tcode, inputs=[(None, None)], timeout=1.0)
+ output = answers[0][1]
+
+ if str(test_out[xs_i]) in output:
+ n_correct += 1
+ else:
+ tin = test_in[xs_i]
+ tout = test_out[xs_i]
passed = n_correct == len(test_in)
- tin = None
- tout = None
hints = [{'id': 'test_results', 'args': {'passed': n_correct, 'total': len(test_in)}}]
if tin:
hints.append({'id': 'problematic_test_case', 'args': {'testin': str(tin), 'testout': str(tout)}})
diff --git a/python/problems/lists_and_for/prefix/common.py b/python/problems/lists_and_for/prefix/common.py
index cb8d706..1198e65 100644
--- a/python/problems/lists_and_for/prefix/common.py
+++ b/python/problems/lists_and_for/prefix/common.py
@@ -24,12 +24,29 @@ hint_type = {
}
def test(python, code):
- test_in = [1]
+ in_out = [
+ ('a', ['', 'a']),
+ ('ab', ['', 'a', 'ab']),
+ ('abc', ['', 'a', 'ab', 'abc']),
+ ('drevo', ['', 'd', 'dr', 'dre', 'drev', 'drevo']),
+ ]
+
+ 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)
+ outputs = [ans[1] for ans in answers]
+
n_correct = 0
+ tin = None
+ for i, (output, correct) in enumerate(zip(outputs, test_out)):
+ if correct in output:
+ n_correct += 1
+ else:
+ tin = test_in[i][1]
+ tout = correct
passed = n_correct == len(test_in)
- tin = None
- tout = None
hints = [{'id': 'test_results', 'args': {'passed': n_correct, 'total': len(test_in)}}]
if tin:
hints.append({'id': 'problematic_test_case', 'args': {'testin': str(tin), 'testout': str(tout)}})
@@ -46,3 +63,5 @@ def hint(python, code):
if exc: return exc
return None
+
+
diff --git a/python/problems/lists_and_for/split_word/common.py b/python/problems/lists_and_for/split_word/common.py
index 0947b09..0f5c5b9 100644
--- a/python/problems/lists_and_for/split_word/common.py
+++ b/python/problems/lists_and_for/split_word/common.py
@@ -16,7 +16,7 @@ s = input('Vpiši besedo: ')
xs = []
for i in range(len(s) + 1):
xs.append((s[:i], s[i:]))
-print(x)
+print(xs)
'''
hint_type = {
@@ -24,12 +24,30 @@ hint_type = {
}
def test(python, code):
- test_in = [1]
+ in_out = [
+ ('a', [('', 'a'), ('a', '')]),
+ ('ab', [('', 'ab'), ('a', 'b'), ('ab', '')]),
+ ('abc', [('', 'abc'), ('a', 'bc'), ('ab', 'c'), ('abc', '')]),
+ ('gozd', [('', 'gozd'), ('g', 'ozd'), ('go', 'zd'), ('goz', 'd'), ('gozd', '')]),
+ ]
+
+ 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)
+ outputs = [ans[1] for ans in answers]
+
n_correct = 0
+ tin = None
+ for i, (output, correct) in enumerate(zip(outputs, test_out)):
+ if correct in output:
+ n_correct += 1
+ else:
+ tin = test_in[i][1]
+ tout = correct
passed = n_correct == len(test_in)
- tin = None
- tout = None
+
hints = [{'id': 'test_results', 'args': {'passed': n_correct, 'total': len(test_in)}}]
if tin:
hints.append({'id': 'problematic_test_case', 'args': {'testin': str(tin), 'testout': str(tout)}})
diff --git a/python/problems/lists_and_for/substrings/common.py b/python/problems/lists_and_for/substrings/common.py
index 32a3d4c..bdc356a 100644
--- a/python/problems/lists_and_for/substrings/common.py
+++ b/python/problems/lists_and_for/substrings/common.py
@@ -27,12 +27,30 @@ hint_type = {
}
def test(python, code):
- test_in = [1]
+ in_out = [
+ ('a', ['', 'a']),
+ ('ab', ['', 'a', 'b', 'ab']),
+ ('abc', ['', 'a', 'b', 'c', 'ab', 'bc', 'abc']),
+ ('tema', ['', 't', 'e', 'm', 'a', 'te', 'em', 'ma', 'tem', 'ema', 'tema']),
+ ]
+
+ 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)
+ outputs = [ans[1] for ans in answers]
+
n_correct = 0
+ tin = None
+ for i, (output, correct) in enumerate(zip(outputs, test_out)):
+ if correct in output:
+ n_correct += 1
+ else:
+ tin = test_in[i][1]
+ tout = correct
passed = n_correct == len(test_in)
- tin = None
- tout = None
+
hints = [{'id': 'test_results', 'args': {'passed': n_correct, 'total': len(test_in)}}]
if tin:
hints.append({'id': 'problematic_test_case', 'args': {'testin': str(tin), 'testout': str(tout)}})
diff --git a/python/problems/while_and_if/common.py b/python/problems/while_and_if/common.py
index 3ca8844..c4071df 100644
--- a/python/problems/while_and_if/common.py
+++ b/python/problems/while_and_if/common.py
@@ -1 +1,2 @@
id = 14
+number = 2
\ No newline at end of file
diff --git a/python/sl.py b/python/sl.py
index af06db9..0f30a8f 100644
--- a/python/sl.py
+++ b/python/sl.py
@@ -57,7 +57,7 @@ pravilen rezultat: [%=testout%]
'''],
'no_func_name': ['''\
-Funkcija z imenom [%=func_name%] ni definirana.
+Funkcija z imenom [%=func_name%]
ni definirana.
'''],
'syntax_error': ['''\
--
cgit v1.2.1