From 84f3426c937d1bb9d44ba25a71706416fbb8b85d Mon Sep 17 00:00:00 2001 From: Martin Date: Fri, 9 Oct 2015 11:17:49 +0200 Subject: Added several new problems. They have no tests nor hints implemented. --- .../problems/functions_and_modules/all/common.py | 47 +++++++++++++++++++ python/problems/functions_and_modules/all/en.py | 16 +++++++ python/problems/functions_and_modules/all/sl.py | 40 ++++++++++++++++ .../problems/functions_and_modules/any/common.py | 47 +++++++++++++++++++ python/problems/functions_and_modules/any/en.py | 16 +++++++ python/problems/functions_and_modules/any/sl.py | 34 ++++++++++++++ .../functions_and_modules/caesar_cipher/common.py | 52 +++++++++++++++++++++ .../functions_and_modules/caesar_cipher/en.py | 16 +++++++ .../functions_and_modules/caesar_cipher/sl.py | 35 ++++++++++++++ .../functions_and_modules/dominoes/common.py | 47 +++++++++++++++++++ .../problems/functions_and_modules/dominoes/en.py | 16 +++++++ .../problems/functions_and_modules/dominoes/sl.py | 29 ++++++++++++ python/problems/functions_and_modules/en.py | 3 ++ .../largest_sublist/common.py | 53 ++++++++++++++++++++++ .../functions_and_modules/largest_sublist/en.py | 16 +++++++ .../functions_and_modules/largest_sublist/sl.py | 33 ++++++++++++++ .../functions_and_modules/lists_sum/common.py | 50 ++++++++++++++++++++ .../problems/functions_and_modules/lists_sum/en.py | 16 +++++++ .../problems/functions_and_modules/lists_sum/sl.py | 35 ++++++++++++++ .../functions_and_modules/longest_word/common.py | 48 ++++++++++++++++++++ .../functions_and_modules/longest_word/en.py | 16 +++++++ .../functions_and_modules/longest_word/sl.py | 30 ++++++++++++ .../problems/functions_and_modules/map/common.py | 47 +++++++++++++++++++ python/problems/functions_and_modules/map/en.py | 16 +++++++ python/problems/functions_and_modules/map/sl.py | 34 ++++++++++++++ .../multiplicative_range/common.py | 48 ++++++++++++++++++++ .../multiplicative_range/en.py | 16 +++++++ .../multiplicative_range/sl.py | 32 +++++++++++++ .../functions_and_modules/similarity/common.py | 48 ++++++++++++++++++++ .../functions_and_modules/similarity/en.py | 16 +++++++ .../functions_and_modules/similarity/sl.py | 39 ++++++++++++++++ python/problems/functions_and_modules/sl.py | 3 ++ .../suspicious_words/common.py | 48 ++++++++++++++++++++ .../functions_and_modules/suspicious_words/en.py | 16 +++++++ .../functions_and_modules/suspicious_words/sl.py | 32 +++++++++++++ 35 files changed, 1090 insertions(+) create mode 100644 python/problems/functions_and_modules/all/common.py create mode 100644 python/problems/functions_and_modules/all/en.py create mode 100644 python/problems/functions_and_modules/all/sl.py create mode 100644 python/problems/functions_and_modules/any/common.py create mode 100644 python/problems/functions_and_modules/any/en.py create mode 100644 python/problems/functions_and_modules/any/sl.py create mode 100644 python/problems/functions_and_modules/caesar_cipher/common.py create mode 100644 python/problems/functions_and_modules/caesar_cipher/en.py create mode 100644 python/problems/functions_and_modules/caesar_cipher/sl.py create mode 100644 python/problems/functions_and_modules/dominoes/common.py create mode 100644 python/problems/functions_and_modules/dominoes/en.py create mode 100644 python/problems/functions_and_modules/dominoes/sl.py create mode 100644 python/problems/functions_and_modules/en.py create mode 100644 python/problems/functions_and_modules/largest_sublist/common.py create mode 100644 python/problems/functions_and_modules/largest_sublist/en.py create mode 100644 python/problems/functions_and_modules/largest_sublist/sl.py create mode 100644 python/problems/functions_and_modules/lists_sum/common.py create mode 100644 python/problems/functions_and_modules/lists_sum/en.py create mode 100644 python/problems/functions_and_modules/lists_sum/sl.py create mode 100644 python/problems/functions_and_modules/longest_word/common.py create mode 100644 python/problems/functions_and_modules/longest_word/en.py create mode 100644 python/problems/functions_and_modules/longest_word/sl.py create mode 100644 python/problems/functions_and_modules/map/common.py create mode 100644 python/problems/functions_and_modules/map/en.py create mode 100644 python/problems/functions_and_modules/map/sl.py create mode 100644 python/problems/functions_and_modules/multiplicative_range/common.py create mode 100644 python/problems/functions_and_modules/multiplicative_range/en.py create mode 100644 python/problems/functions_and_modules/multiplicative_range/sl.py create mode 100644 python/problems/functions_and_modules/similarity/common.py create mode 100644 python/problems/functions_and_modules/similarity/en.py create mode 100644 python/problems/functions_and_modules/similarity/sl.py create mode 100644 python/problems/functions_and_modules/sl.py create mode 100644 python/problems/functions_and_modules/suspicious_words/common.py create mode 100644 python/problems/functions_and_modules/suspicious_words/en.py create mode 100644 python/problems/functions_and_modules/suspicious_words/sl.py (limited to 'python/problems/functions_and_modules') diff --git a/python/problems/functions_and_modules/all/common.py b/python/problems/functions_and_modules/all/common.py new file mode 100644 index 0000000..7fb60f5 --- /dev/null +++ b/python/problems/functions_and_modules/all/common.py @@ -0,0 +1,47 @@ +# coding=utf-8 + +import re +from python.util import has_token_sequence, string_almost_equal, \ + string_contains_number, get_tokens, get_numbers, get_exception_desc +from server.hints import Hint + +id = 238 +group = 'functions_and_modules' +number = 4 +visible = True + +solution = '''\ +def all(xs): + for x in xs: + if not x: + return False + return True +''' + +hint_type = { + 'final_hint': Hint('final_hint') +} + +def test(python, code): + test_in = [1] + n_correct = 0 + + 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)}}) + if passed: + hints.append({'id': 'final_hint'}) + return passed, hints + +def hint(python, 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) + exc = get_exception_desc(answer[0][3]) + if exc: return exc + + return None diff --git a/python/problems/functions_and_modules/all/en.py b/python/problems/functions_and_modules/all/en.py new file mode 100644 index 0000000..3028ad4 --- /dev/null +++ b/python/problems/functions_and_modules/all/en.py @@ -0,0 +1,16 @@ +# coding=utf-8 + +id = 238 +name = 'All' +slug = 'All' + +description = '''\ +

(translation missing)

''' + +hint = { + 'plan': '''\ +

(translation missing)

''', + + 'no_input_call': '''\ +

(translation missing)

''', +} diff --git a/python/problems/functions_and_modules/all/sl.py b/python/problems/functions_and_modules/all/sl.py new file mode 100644 index 0000000..f71fa4b --- /dev/null +++ b/python/problems/functions_and_modules/all/sl.py @@ -0,0 +1,40 @@ +# coding=utf-8 +import server +mod = server.problems.load_language('python', 'sl') + + +id = 238 +name = 'Vsi' +slug = 'Vsi' + + +description = '''\ +

+Napišite funkcijo all, ki sprejme seznam xs in vrne True, +če so vse vrednosti v seznamu resnične. Elementi seznama xs so lahko poljubnega tipa, ne le bool. +

+>>> all([True, True, False])
+False
+>>> all([True, True])
+True
+>>> all([1, 2, 3, 0])
+False
+>>> all(['foo', 42, True])
+True
+>>> all([])
+True
+
+

''' + +plan = ['''\ +

+''', + '''\ +

'''] + +hint = { + 'final_hint': ['''\ +

Program je pravilen!
+

+'''], +} diff --git a/python/problems/functions_and_modules/any/common.py b/python/problems/functions_and_modules/any/common.py new file mode 100644 index 0000000..78867c5 --- /dev/null +++ b/python/problems/functions_and_modules/any/common.py @@ -0,0 +1,47 @@ +# coding=utf-8 + +import re +from python.util import has_token_sequence, string_almost_equal, \ + string_contains_number, get_tokens, get_numbers, get_exception_desc +from server.hints import Hint + +id = 239 +group = 'functions_and_modules' +number = 4 +visible = True + +solution = '''\ +def any(xs): + for x in xs: + if x: + return True + return False +''' + +hint_type = { + 'final_hint': Hint('final_hint') +} + +def test(python, code): + test_in = [1] + n_correct = 0 + + 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)}}) + if passed: + hints.append({'id': 'final_hint'}) + return passed, hints + +def hint(python, 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) + exc = get_exception_desc(answer[0][3]) + if exc: return exc + + return None diff --git a/python/problems/functions_and_modules/any/en.py b/python/problems/functions_and_modules/any/en.py new file mode 100644 index 0000000..f5b94d9 --- /dev/null +++ b/python/problems/functions_and_modules/any/en.py @@ -0,0 +1,16 @@ +# coding=utf-8 + +id = 239 +name = 'Any' +slug = 'Any' + +description = '''\ +

(translation missing)

''' + +hint = { + 'plan': '''\ +

(translation missing)

''', + + 'no_input_call': '''\ +

(translation missing)

''', +} diff --git a/python/problems/functions_and_modules/any/sl.py b/python/problems/functions_and_modules/any/sl.py new file mode 100644 index 0000000..f32e50e --- /dev/null +++ b/python/problems/functions_and_modules/any/sl.py @@ -0,0 +1,34 @@ +# coding=utf-8 +import server +mod = server.problems.load_language('python', 'sl') + + +id = 239 +name = 'Vsaj eden' +slug = 'Vsaj eden' + + +description = '''\ +

+Napišite funkcijo any(xs), ki deluje podobno kot all, le da vrne True, +če je vsaj ena vrednost v seznamu resnična. +

+>>> any([2, 3, 0])
+True
+>>> any([])
+False
+
+

''' + +plan = ['''\ +

+''', + '''\ +

'''] + +hint = { + 'final_hint': ['''\ +

Program je pravilen!
+

+'''], +} diff --git a/python/problems/functions_and_modules/caesar_cipher/common.py b/python/problems/functions_and_modules/caesar_cipher/common.py new file mode 100644 index 0000000..494a7f9 --- /dev/null +++ b/python/problems/functions_and_modules/caesar_cipher/common.py @@ -0,0 +1,52 @@ +# coding=utf-8 + +import re +from python.util import has_token_sequence, string_almost_equal, \ + string_contains_number, get_tokens, get_numbers, get_exception_desc +from server.hints import Hint + +id = 243 +group = 'functions_and_modules' +number = 9 +visible = True + +solution = '''\ +def caesar(s): + cipher = '' + for c in s: + if 'a' <= c <= 'w': + cipher += chr(ord(c) + 3) + elif 'x' <= c <= 'z': + cipher += chr(ord(c) - 23) + else: + cipher += c + return cipher) +''' + +hint_type = { + 'final_hint': Hint('final_hint') +} + +def test(python, code): + test_in = [1] + n_correct = 0 + + 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)}}) + if passed: + hints.append({'id': 'final_hint'}) + return passed, hints + +def hint(python, 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) + exc = get_exception_desc(answer[0][3]) + if exc: return exc + + return None diff --git a/python/problems/functions_and_modules/caesar_cipher/en.py b/python/problems/functions_and_modules/caesar_cipher/en.py new file mode 100644 index 0000000..bcfedee --- /dev/null +++ b/python/problems/functions_and_modules/caesar_cipher/en.py @@ -0,0 +1,16 @@ +# coding=utf-8 + +id = 243 +name = 'Caesar cipher' +slug = 'Caesar cipher' + +description = '''\ +

(translation missing)

''' + +hint = { + 'plan': '''\ +

(translation missing)

''', + + 'no_input_call': '''\ +

(translation missing)

''', +} diff --git a/python/problems/functions_and_modules/caesar_cipher/sl.py b/python/problems/functions_and_modules/caesar_cipher/sl.py new file mode 100644 index 0000000..ea4d9c8 --- /dev/null +++ b/python/problems/functions_and_modules/caesar_cipher/sl.py @@ -0,0 +1,35 @@ +# coding=utf-8 +import server +mod = server.problems.load_language('python', 'sl') + + +id = 243 +name = 'Cezarjeva šifra' +slug = 'Cezarjeva šifra' + + +description = '''\ +

+Napišite funkcijo caesar(s), ki podan niz zašifrira z uporabo cezarjeve šifre. +Preden se lotite naloge, se je morda vredno pozanimati kaj počneta funkciji +ord in +chr. +Predpostavite lahko, da niz s vsebuje le male črke angleške besede in presledke. +

+>>> caesar('the quick brown fox jumps over the lazy dog')
+'wkh txlfn eurzq ira mxpsv ryhu wkh odcb grj'
+
+

''' + +plan = ['''\ +

+''', + '''\ +

'''] + +hint = { + 'final_hint': ['''\ +

Program je pravilen!
+

+'''], +} diff --git a/python/problems/functions_and_modules/dominoes/common.py b/python/problems/functions_and_modules/dominoes/common.py new file mode 100644 index 0000000..5e73d8e --- /dev/null +++ b/python/problems/functions_and_modules/dominoes/common.py @@ -0,0 +1,47 @@ +# coding=utf-8 + +import re +from python.util import has_token_sequence, string_almost_equal, \ + string_contains_number, get_tokens, get_numbers, get_exception_desc +from server.hints import Hint + +id = 240 +group = 'functions_and_modules' +number = 6 +visible = True + +solution = '''\ +def dominoes(domine): + for i in range(len(domine) - 1): + if domine[i][1] != domine[i + 1][0]: + return False + return True +''' + +hint_type = { + 'final_hint': Hint('final_hint') +} + +def test(python, code): + test_in = [1] + n_correct = 0 + + 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)}}) + if passed: + hints.append({'id': 'final_hint'}) + return passed, hints + +def hint(python, 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) + exc = get_exception_desc(answer[0][3]) + if exc: return exc + + return None diff --git a/python/problems/functions_and_modules/dominoes/en.py b/python/problems/functions_and_modules/dominoes/en.py new file mode 100644 index 0000000..4d0d31b --- /dev/null +++ b/python/problems/functions_and_modules/dominoes/en.py @@ -0,0 +1,16 @@ +# coding=utf-8 + +id = 240 +name = 'Dominoes' +slug = 'Dominoes' + +description = '''\ +

(translation missing)

''' + +hint = { + 'plan': '''\ +

(translation missing)

''', + + 'no_input_call': '''\ +

(translation missing)

''', +} diff --git a/python/problems/functions_and_modules/dominoes/sl.py b/python/problems/functions_and_modules/dominoes/sl.py new file mode 100644 index 0000000..41cb860 --- /dev/null +++ b/python/problems/functions_and_modules/dominoes/sl.py @@ -0,0 +1,29 @@ +# coding=utf-8 +import server +mod = server.problems.load_language('python', 'sl') + + +id = 240 +name = 'Domine' +slug = 'Domine' + + +description = '''\ +

+Vrsta domin je podana s seznamom parov (terk), na primer +[(3, 6), (6, 6), (6, 1), (1, 0)] ali [(3, 6), (6, 6), (2, 3)]. Napišite funkcijo dominoes(xs), +ki prejme takšen seznam in pove, ali so domine pravilno zložene. Za prvi seznam mora vrniti True in za drugega False. +

''' + +plan = ['''\ +

+''', + '''\ +

'''] + +hint = { + 'final_hint': ['''\ +

Program je pravilen!
+

+'''], +} diff --git a/python/problems/functions_and_modules/en.py b/python/problems/functions_and_modules/en.py new file mode 100644 index 0000000..1218e73 --- /dev/null +++ b/python/problems/functions_and_modules/en.py @@ -0,0 +1,3 @@ +name = 'Functions and Modules' +description = 'Advanced functions and modules' + diff --git a/python/problems/functions_and_modules/largest_sublist/common.py b/python/problems/functions_and_modules/largest_sublist/common.py new file mode 100644 index 0000000..372e34f --- /dev/null +++ b/python/problems/functions_and_modules/largest_sublist/common.py @@ -0,0 +1,53 @@ +# coding=utf-8 + +import re +from python.util import has_token_sequence, string_almost_equal, \ + string_contains_number, get_tokens, get_numbers, get_exception_desc +from server.hints import Hint + +id = 242 +group = 'functions_and_modules' +number = 8 +visible = True + +solution = '''\ +def largest_sublist(xss): + najvecji = [] + najvecji_vsota = float('-inf') + for xs in xss: + vsota = 0 + for x in xs: + vsota += x + if vsota > najvecji_vsota: + najvecji = xs + najvecji_vsota = vsota + return najvecji +''' + +hint_type = { + 'final_hint': Hint('final_hint') +} + +def test(python, code): + test_in = [1] + n_correct = 0 + + 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)}}) + if passed: + hints.append({'id': 'final_hint'}) + return passed, hints + +def hint(python, 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) + exc = get_exception_desc(answer[0][3]) + if exc: return exc + + return None diff --git a/python/problems/functions_and_modules/largest_sublist/en.py b/python/problems/functions_and_modules/largest_sublist/en.py new file mode 100644 index 0000000..132eb39 --- /dev/null +++ b/python/problems/functions_and_modules/largest_sublist/en.py @@ -0,0 +1,16 @@ +# coding=utf-8 + +id = 242 +name = 'Largest sublist' +slug = 'Largest sublist' + +description = '''\ +

(translation missing)

''' + +hint = { + 'plan': '''\ +

(translation missing)

''', + + 'no_input_call': '''\ +

(translation missing)

''', +} diff --git a/python/problems/functions_and_modules/largest_sublist/sl.py b/python/problems/functions_and_modules/largest_sublist/sl.py new file mode 100644 index 0000000..b550ce2 --- /dev/null +++ b/python/problems/functions_and_modules/largest_sublist/sl.py @@ -0,0 +1,33 @@ +# coding=utf-8 +import server +mod = server.problems.load_language('python', 'sl') + + +id = 242 +name = 'Največji podseznam' +slug = 'Največji podseznam' + + +description = '''\ +

+Napiši funkcijo largest_sublist, ki vrne podseznam z največjo vsoto elementov. +

+>>> largest_sublist([[1, 1, 1], [1, 1]])
+[1, 1, 1]
+>>> largest_sublist([[2, 4, 1], [3, 1], [], [8, 2], [1, 1, 1, 1]])
+[8, 2]
+
+

''' + +plan = ['''\ +

+''', + '''\ +

'''] + +hint = { + 'final_hint': ['''\ +

Program je pravilen!
+

+'''], +} diff --git a/python/problems/functions_and_modules/lists_sum/common.py b/python/problems/functions_and_modules/lists_sum/common.py new file mode 100644 index 0000000..d3afef4 --- /dev/null +++ b/python/problems/functions_and_modules/lists_sum/common.py @@ -0,0 +1,50 @@ +# coding=utf-8 + +import re +from python.util import has_token_sequence, string_almost_equal, \ + string_contains_number, get_tokens, get_numbers, get_exception_desc +from server.hints import Hint + +id = 241 +group = 'functions_and_modules' +number = 7 +visible = True + +solution = '''\ +def lists_sum(xss): + vsote = [] + for xs in xss: + vsota = 0 + for x in xs: + vsota += x + vsote.append(vsota) + return vsote +''' + +hint_type = { + 'final_hint': Hint('final_hint') +} + +def test(python, code): + test_in = [1] + n_correct = 0 + + 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)}}) + if passed: + hints.append({'id': 'final_hint'}) + return passed, hints + +def hint(python, 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) + exc = get_exception_desc(answer[0][3]) + if exc: return exc + + return None diff --git a/python/problems/functions_and_modules/lists_sum/en.py b/python/problems/functions_and_modules/lists_sum/en.py new file mode 100644 index 0000000..12eaf0b --- /dev/null +++ b/python/problems/functions_and_modules/lists_sum/en.py @@ -0,0 +1,16 @@ +# coding=utf-8 + +id = 241 +name = 'Lists sum' +slug = 'Lists sum' + +description = '''\ +

(translation missing)

''' + +hint = { + 'plan': '''\ +

(translation missing)

''', + + 'no_input_call': '''\ +

(translation missing)

''', +} diff --git a/python/problems/functions_and_modules/lists_sum/sl.py b/python/problems/functions_and_modules/lists_sum/sl.py new file mode 100644 index 0000000..4baa002 --- /dev/null +++ b/python/problems/functions_and_modules/lists_sum/sl.py @@ -0,0 +1,35 @@ +# coding=utf-8 +import server +mod = server.problems.load_language('python', 'sl') + + +id = 241 +name = 'Vsota seznamov' +slug = 'Vsota seznamov' + + +description = '''\ +

+Podan je seznam seznamov, npr. [[2, 4, 1], [3, 1], [], [8, 2], [1, 1, 1, 1]]. +Napiši funkcijo lists_sum(xxs), ki v seznamu vrne vsote vseh elementov v posameznih podseznamih. +Za gornji seznam naj funkcija vrne seznam [7, 4, 0, 10, 4], saj je, na primer, 2 + 4 + 1 = 7. +

+>>> lists_sum([[1, 1, 1], [1, 1]])
+[3, 2]
+>>> lists_sum([[2, 4, 1], [3, 1], [], [8, 2], [1, 1, 1, 1]])
+[7, 4, 0, 10, 4]
+
+

''' + +plan = ['''\ +

+''', + '''\ +

'''] + +hint = { + 'final_hint': ['''\ +

Program je pravilen!
+

+'''], +} diff --git a/python/problems/functions_and_modules/longest_word/common.py b/python/problems/functions_and_modules/longest_word/common.py new file mode 100644 index 0000000..1201c1d --- /dev/null +++ b/python/problems/functions_and_modules/longest_word/common.py @@ -0,0 +1,48 @@ +# coding=utf-8 + +import re +from python.util import has_token_sequence, string_almost_equal, \ + string_contains_number, get_tokens, get_numbers, get_exception_desc +from server.hints import Hint + +id = 235 +group = 'functions_and_modules' +number = 1 +visible = True + +solution = '''\ +def longest(s): + naj = '' + for beseda in s.split(): + if len(beseda) > len(naj): + naj = beseda + return naj +''' + +hint_type = { + 'final_hint': Hint('final_hint') +} + +def test(python, code): + test_in = [1] + n_correct = 0 + + 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)}}) + if passed: + hints.append({'id': 'final_hint'}) + return passed, hints + +def hint(python, 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) + exc = get_exception_desc(answer[0][3]) + if exc: return exc + + return None diff --git a/python/problems/functions_and_modules/longest_word/en.py b/python/problems/functions_and_modules/longest_word/en.py new file mode 100644 index 0000000..7bd4dc2 --- /dev/null +++ b/python/problems/functions_and_modules/longest_word/en.py @@ -0,0 +1,16 @@ +# coding=utf-8 + +id = 235 +name = 'Longest word' +slug = 'Longest word' + +description = '''\ +

(translation missing)

''' + +hint = { + 'plan': '''\ +

(translation missing)

''', + + 'no_input_call': '''\ +

(translation missing)

''', +} diff --git a/python/problems/functions_and_modules/longest_word/sl.py b/python/problems/functions_and_modules/longest_word/sl.py new file mode 100644 index 0000000..eb85509 --- /dev/null +++ b/python/problems/functions_and_modules/longest_word/sl.py @@ -0,0 +1,30 @@ +# coding=utf-8 +import server +mod = server.problems.load_language('python', 'sl') + + +id = 235 +name = 'Najdaljša beseda' +slug = 'Najdaljša beseda' + + +description = '''\ +

+Napiši funkcijo longest(s), ki vrne najdaljšo besedo v nizu s. +

+>>> longest('an ban pet podgan')
+'podgan'
+

''' + +plan = ['''\ +

+''', + '''\ +

'''] + +hint = { + 'final_hint': ['''\ +

Program je pravilen!
+

+'''], +} diff --git a/python/problems/functions_and_modules/map/common.py b/python/problems/functions_and_modules/map/common.py new file mode 100644 index 0000000..e28f356 --- /dev/null +++ b/python/problems/functions_and_modules/map/common.py @@ -0,0 +1,47 @@ +# coding=utf-8 + +import re +from python.util import has_token_sequence, string_almost_equal, \ + string_contains_number, get_tokens, get_numbers, get_exception_desc +from server.hints import Hint + +id = 245 +group = 'functions_and_modules' +number = 11 +visible = True + +solution = '''\ +def map(f, xs): + ys = [] + for x in xs: + ys.append(f(x)) + return ys +''' + +hint_type = { + 'final_hint': Hint('final_hint') +} + +def test(python, code): + test_in = [1] + n_correct = 0 + + 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)}}) + if passed: + hints.append({'id': 'final_hint'}) + return passed, hints + +def hint(python, 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) + exc = get_exception_desc(answer[0][3]) + if exc: return exc + + return None diff --git a/python/problems/functions_and_modules/map/en.py b/python/problems/functions_and_modules/map/en.py new file mode 100644 index 0000000..dcc1785 --- /dev/null +++ b/python/problems/functions_and_modules/map/en.py @@ -0,0 +1,16 @@ +# coding=utf-8 + +id = 245 +name = 'Map' +slug = 'Map' + +description = '''\ +

(translation missing)

''' + +hint = { + 'plan': '''\ +

(translation missing)

''', + + 'no_input_call': '''\ +

(translation missing)

''', +} diff --git a/python/problems/functions_and_modules/map/sl.py b/python/problems/functions_and_modules/map/sl.py new file mode 100644 index 0000000..18c47fb --- /dev/null +++ b/python/problems/functions_and_modules/map/sl.py @@ -0,0 +1,34 @@ +# coding=utf-8 +import server +mod = server.problems.load_language('python', 'sl') + + +id = 245 +name = 'Slikaj' +slug = 'Slikaj' + + +description = '''\ +

+Napišite funkcijo map(f, xs), ki sprejme funkcijo f in seznam [x_1, x_2, ..., x_n] +in vrne nov seznam [f(x_1), f(x_2), ..., f(x_n)]. +

+>>> map(abs, [-5, 8, -3, -1, 3])
+[5, 8, 3, 1, 3]
+>>> map(len, "Daydream delusion limousine eyelash".split())
+[8, 8, 9, 7]
+
+

''' + +plan = ['''\ +

+''', + '''\ +

'''] + +hint = { + 'final_hint': ['''\ +

Program je pravilen!
+

+'''], +} diff --git a/python/problems/functions_and_modules/multiplicative_range/common.py b/python/problems/functions_and_modules/multiplicative_range/common.py new file mode 100644 index 0000000..9a52dce --- /dev/null +++ b/python/problems/functions_and_modules/multiplicative_range/common.py @@ -0,0 +1,48 @@ +# coding=utf-8 + +import re +from python.util import has_token_sequence, string_almost_equal, \ + string_contains_number, get_tokens, get_numbers, get_exception_desc +from server.hints import Hint + +id = 244 +group = 'functions_and_modules' +number = 10 +visible = True + +solution = '''\ +def mrange(s, r, l): + xs = [] + for i in range(l): + xs.append(s) + s *= r + return xs +''' + +hint_type = { + 'final_hint': Hint('final_hint') +} + +def test(python, code): + test_in = [1] + n_correct = 0 + + 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)}}) + if passed: + hints.append({'id': 'final_hint'}) + return passed, hints + +def hint(python, 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) + exc = get_exception_desc(answer[0][3]) + if exc: return exc + + return None diff --git a/python/problems/functions_and_modules/multiplicative_range/en.py b/python/problems/functions_and_modules/multiplicative_range/en.py new file mode 100644 index 0000000..566ef5f --- /dev/null +++ b/python/problems/functions_and_modules/multiplicative_range/en.py @@ -0,0 +1,16 @@ +# coding=utf-8 + +id = 244 +name = 'Multiplicative range' +slug = 'Multiplicative range' + +description = '''\ +

(translation missing)

''' + +hint = { + 'plan': '''\ +

(translation missing)

''', + + 'no_input_call': '''\ +

(translation missing)

''', +} diff --git a/python/problems/functions_and_modules/multiplicative_range/sl.py b/python/problems/functions_and_modules/multiplicative_range/sl.py new file mode 100644 index 0000000..8bd4bd0 --- /dev/null +++ b/python/problems/functions_and_modules/multiplicative_range/sl.py @@ -0,0 +1,32 @@ +# coding=utf-8 +import server +mod = server.problems.load_language('python', 'sl') + + +id = 244 +name = 'Multiplikativni range' +slug = 'Multiplikativni range' + + +description = '''\ +

+Napišite funkcijo mrange(start, factor, length), ki vrne seznam, kjer je vsako naslednje število za +factor večje od prejšnjega. Npr., v seznamu [1, 2, 4, 8, 16] je vsako naslednje število 2-krat večje od prejšnjega. +

+>>> print(mrange(7, 4, 7))
+[7, 28, 112, 448, 1792, 7168, 28672]
+
+

''' + +plan = ['''\ +

+''', + '''\ +

'''] + +hint = { + 'final_hint': ['''\ +

Program je pravilen!
+

+'''], +} diff --git a/python/problems/functions_and_modules/similarity/common.py b/python/problems/functions_and_modules/similarity/common.py new file mode 100644 index 0000000..5cb8fe7 --- /dev/null +++ b/python/problems/functions_and_modules/similarity/common.py @@ -0,0 +1,48 @@ +# coding=utf-8 + +import re +from python.util import has_token_sequence, string_almost_equal, \ + string_contains_number, get_tokens, get_numbers, get_exception_desc +from server.hints import Hint + +id = 236 +group = 'functions_and_modules' +number = 2 +visible = True + +solution = '''\ +def similarity(s1, s2): + stevec = 0 + for i in range(min(len(s1), len(s2))): + if s1[i] == s2[i]: + stevec += 1 + return stevec +''' + +hint_type = { + 'final_hint': Hint('final_hint') +} + +def test(python, code): + test_in = [1] + n_correct = 0 + + 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)}}) + if passed: + hints.append({'id': 'final_hint'}) + return passed, hints + +def hint(python, 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) + exc = get_exception_desc(answer[0][3]) + if exc: return exc + + return None diff --git a/python/problems/functions_and_modules/similarity/en.py b/python/problems/functions_and_modules/similarity/en.py new file mode 100644 index 0000000..e1dc014 --- /dev/null +++ b/python/problems/functions_and_modules/similarity/en.py @@ -0,0 +1,16 @@ +# coding=utf-8 + +id = 236 +name = 'Similarity' +slug = 'Similarity' + +description = '''\ +

(translation missing)

''' + +hint = { + 'plan': '''\ +

(translation missing)

''', + + 'no_input_call': '''\ +

(translation missing)

''', +} diff --git a/python/problems/functions_and_modules/similarity/sl.py b/python/problems/functions_and_modules/similarity/sl.py new file mode 100644 index 0000000..8aaf0b0 --- /dev/null +++ b/python/problems/functions_and_modules/similarity/sl.py @@ -0,0 +1,39 @@ +# coding=utf-8 +import server +mod = server.problems.load_language('python', 'sl') + + +id = 236 +name = 'Podobnost' +slug = 'Podobnost' + + +description = '''\ +

+Napišite funkcijo similarity(s1, s2), ki izračuna podobnost med dvema nizoma. +Podobnost definirajmo kot število mest v katerih se niza ujemata. +

+sobota
+robot
+------
+011110 -> 4
+
+>>> podobnost('sobota', 'robot')
+4
+>>> podobnost('robot', 'sobota')
+4
+
+

''' + +plan = ['''\ +

+''', + '''\ +

'''] + +hint = { + 'final_hint': ['''\ +

Program je pravilen!
+

+'''], +} diff --git a/python/problems/functions_and_modules/sl.py b/python/problems/functions_and_modules/sl.py new file mode 100644 index 0000000..fb4f520 --- /dev/null +++ b/python/problems/functions_and_modules/sl.py @@ -0,0 +1,3 @@ +name = 'Funkcije in delo z moduli' +description = 'Uporaba funkcij in delo z moduli (predvsem z nizi)' + diff --git a/python/problems/functions_and_modules/suspicious_words/common.py b/python/problems/functions_and_modules/suspicious_words/common.py new file mode 100644 index 0000000..74868ab --- /dev/null +++ b/python/problems/functions_and_modules/suspicious_words/common.py @@ -0,0 +1,48 @@ +# coding=utf-8 + +import re +from python.util import has_token_sequence, string_almost_equal, \ + string_contains_number, get_tokens, get_numbers, get_exception_desc +from server.hints import Hint + +id = 237 +group = 'functions_and_modules' +number = 3 +visible = True + +solution = '''\ +def suspicious(s): + susp = [] + for word in s.split(): + if 'u' in word and 'a' in word: + susp.append(word) + return susp +''' + +hint_type = { + 'final_hint': Hint('final_hint') +} + +def test(python, code): + test_in = [1] + n_correct = 0 + + 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)}}) + if passed: + hints.append({'id': 'final_hint'}) + return passed, hints + +def hint(python, 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) + exc = get_exception_desc(answer[0][3]) + if exc: return exc + + return None diff --git a/python/problems/functions_and_modules/suspicious_words/en.py b/python/problems/functions_and_modules/suspicious_words/en.py new file mode 100644 index 0000000..9a406bf --- /dev/null +++ b/python/problems/functions_and_modules/suspicious_words/en.py @@ -0,0 +1,16 @@ +# coding=utf-8 + +id = 237 +name = 'Suspicious words' +slug = 'Suspicious words' + +description = '''\ +

(translation missing)

''' + +hint = { + 'plan': '''\ +

(translation missing)

''', + + 'no_input_call': '''\ +

(translation missing)

''', +} diff --git a/python/problems/functions_and_modules/suspicious_words/sl.py b/python/problems/functions_and_modules/suspicious_words/sl.py new file mode 100644 index 0000000..3bf2c7b --- /dev/null +++ b/python/problems/functions_and_modules/suspicious_words/sl.py @@ -0,0 +1,32 @@ +# coding=utf-8 +import server +mod = server.problems.load_language('python', 'sl') + + +id = 237 +name = 'Sumljive besede' +slug = 'Sumljive besede' + + +description = '''\ +

+Napiši funkcijo suspicious(s), ki vrne seznam vseh sumljivih besed v danem nizu. +Beseda je sumljiva, če vsebuje tako črko u kot črko a. +

+>>> susupicious('Muha pa je rekla: "Tale juha se je pa res prilegla, najlepša huala," in odletela.')
+['Muha', 'juha', 'huala,"']
+
+

''' + +plan = ['''\ +

+''', + '''\ +

'''] + +hint = { + 'final_hint': ['''\ +

Program je pravilen!
+

+'''], +} -- cgit v1.2.1 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. --- .../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 +++++++++++++++-- 12 files changed, 294 insertions(+), 34 deletions(-) create mode 100644 python/problems/functions_and_modules/common.py (limited to 'python/problems/functions_and_modules') 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) -- cgit v1.2.1 From 6e281624b9a0ae29f1f1862f9d581b219ba3b95a Mon Sep 17 00:00:00 2001 From: Timotej Lazar Date: Mon, 12 Oct 2015 11:46:08 +0200 Subject: Remove group attribute from problem common.py files --- python/problems/functions_and_modules/all/common.py | 1 - python/problems/functions_and_modules/any/common.py | 1 - python/problems/functions_and_modules/caesar_cipher/common.py | 1 - python/problems/functions_and_modules/dominoes/common.py | 1 - python/problems/functions_and_modules/largest_sublist/common.py | 1 - python/problems/functions_and_modules/lists_sum/common.py | 1 - python/problems/functions_and_modules/longest_word/common.py | 1 - python/problems/functions_and_modules/map/common.py | 1 - python/problems/functions_and_modules/multiplicative_range/common.py | 1 - python/problems/functions_and_modules/similarity/common.py | 1 - python/problems/functions_and_modules/suspicious_words/common.py | 1 - 11 files changed, 11 deletions(-) (limited to 'python/problems/functions_and_modules') diff --git a/python/problems/functions_and_modules/all/common.py b/python/problems/functions_and_modules/all/common.py index e87aa74..a02cb4b 100644 --- a/python/problems/functions_and_modules/all/common.py +++ b/python/problems/functions_and_modules/all/common.py @@ -6,7 +6,6 @@ from python.util import has_token_sequence, string_almost_equal, \ from server.hints import Hint id = 238 -group = 'functions_and_modules' number = 4 visible = True diff --git a/python/problems/functions_and_modules/any/common.py b/python/problems/functions_and_modules/any/common.py index a96ae04..9d0d0d2 100644 --- a/python/problems/functions_and_modules/any/common.py +++ b/python/problems/functions_and_modules/any/common.py @@ -6,7 +6,6 @@ from python.util import has_token_sequence, string_almost_equal, \ from server.hints import Hint id = 239 -group = 'functions_and_modules' number = 4 visible = True diff --git a/python/problems/functions_and_modules/caesar_cipher/common.py b/python/problems/functions_and_modules/caesar_cipher/common.py index 3c53369..497ce34 100644 --- a/python/problems/functions_and_modules/caesar_cipher/common.py +++ b/python/problems/functions_and_modules/caesar_cipher/common.py @@ -6,7 +6,6 @@ from python.util import has_token_sequence, string_almost_equal, \ from server.hints import Hint id = 243 -group = 'functions_and_modules' number = 9 visible = True diff --git a/python/problems/functions_and_modules/dominoes/common.py b/python/problems/functions_and_modules/dominoes/common.py index 4a0f439..9a46a78 100644 --- a/python/problems/functions_and_modules/dominoes/common.py +++ b/python/problems/functions_and_modules/dominoes/common.py @@ -6,7 +6,6 @@ from python.util import has_token_sequence, string_almost_equal, \ from server.hints import Hint id = 240 -group = 'functions_and_modules' number = 6 visible = True diff --git a/python/problems/functions_and_modules/largest_sublist/common.py b/python/problems/functions_and_modules/largest_sublist/common.py index 90e3ae4..237b817 100644 --- a/python/problems/functions_and_modules/largest_sublist/common.py +++ b/python/problems/functions_and_modules/largest_sublist/common.py @@ -6,7 +6,6 @@ from python.util import has_token_sequence, string_almost_equal, \ from server.hints import Hint id = 242 -group = 'functions_and_modules' number = 8 visible = True diff --git a/python/problems/functions_and_modules/lists_sum/common.py b/python/problems/functions_and_modules/lists_sum/common.py index d6ba72f..c62bce1 100644 --- a/python/problems/functions_and_modules/lists_sum/common.py +++ b/python/problems/functions_and_modules/lists_sum/common.py @@ -6,7 +6,6 @@ from python.util import has_token_sequence, string_almost_equal, \ from server.hints import Hint id = 241 -group = 'functions_and_modules' number = 7 visible = True diff --git a/python/problems/functions_and_modules/longest_word/common.py b/python/problems/functions_and_modules/longest_word/common.py index 3ddb269..b4fabc1 100644 --- a/python/problems/functions_and_modules/longest_word/common.py +++ b/python/problems/functions_and_modules/longest_word/common.py @@ -6,7 +6,6 @@ from python.util import has_token_sequence, string_almost_equal, \ from server.hints import Hint id = 235 -group = 'functions_and_modules' number = 1 visible = True diff --git a/python/problems/functions_and_modules/map/common.py b/python/problems/functions_and_modules/map/common.py index ace0a09..93ba8ac 100644 --- a/python/problems/functions_and_modules/map/common.py +++ b/python/problems/functions_and_modules/map/common.py @@ -6,7 +6,6 @@ from python.util import has_token_sequence, string_almost_equal, \ from server.hints import Hint id = 245 -group = 'functions_and_modules' number = 11 visible = True diff --git a/python/problems/functions_and_modules/multiplicative_range/common.py b/python/problems/functions_and_modules/multiplicative_range/common.py index 0cb2fef..9b892e6 100644 --- a/python/problems/functions_and_modules/multiplicative_range/common.py +++ b/python/problems/functions_and_modules/multiplicative_range/common.py @@ -6,7 +6,6 @@ from python.util import has_token_sequence, string_almost_equal, \ from server.hints import Hint id = 244 -group = 'functions_and_modules' number = 10 visible = True diff --git a/python/problems/functions_and_modules/similarity/common.py b/python/problems/functions_and_modules/similarity/common.py index d71137e..3a6df99 100644 --- a/python/problems/functions_and_modules/similarity/common.py +++ b/python/problems/functions_and_modules/similarity/common.py @@ -6,7 +6,6 @@ from python.util import has_token_sequence, string_almost_equal, \ from server.hints import Hint id = 236 -group = 'functions_and_modules' number = 2 visible = True diff --git a/python/problems/functions_and_modules/suspicious_words/common.py b/python/problems/functions_and_modules/suspicious_words/common.py index e6e119a..89c1a88 100644 --- a/python/problems/functions_and_modules/suspicious_words/common.py +++ b/python/problems/functions_and_modules/suspicious_words/common.py @@ -6,7 +6,6 @@ from python.util import has_token_sequence, string_almost_equal, \ from server.hints import Hint id = 237 -group = 'functions_and_modules' number = 3 visible = True -- cgit v1.2.1