From 4adc255e741171646d9f2ae6d3c058fc4e1456c3 Mon Sep 17 00:00:00 2001 From: Martin Date: Thu, 24 Sep 2015 14:09:09 +0200 Subject: Added to test function so that problematic test cases are returned. --- python/problems/lists_and_for/contains_42/common.py | 14 ++++++++++---- python/problems/lists_and_for/contains_42/sl.py | 6 +++--- .../lists_and_for/contains_string/common.py | 21 +++++++++++++-------- python/problems/lists_and_for/contains_string/sl.py | 6 +++--- python/problems/while_and_if/buy_five/common.py | 13 +++++++++---- python/problems/while_and_if/buy_five/sl.py | 3 +-- python/problems/while_and_if/competition/common.py | 10 ++++++++-- 7 files changed, 47 insertions(+), 26 deletions(-) (limited to 'python/problems') diff --git a/python/problems/lists_and_for/contains_42/common.py b/python/problems/lists_and_for/contains_42/common.py index 3ebe546..915938e 100644 --- a/python/problems/lists_and_for/contains_42/common.py +++ b/python/problems/lists_and_for/contains_42/common.py @@ -48,6 +48,7 @@ def test(python, code): ] n_correct = 0 + tin = None for xs_i, xs in enumerate(test_xs): # change code to contain new xs instead of the one # given by user @@ -63,15 +64,20 @@ def test(python, code): if str(test_out[xs_i]) in output and \ str(not test_out[xs_i]) not in output: n_correct += 1 - - passed = n_correct == len(test_in) - hints = [{'id': 'test_results', 'args': {'passed': n_correct, 'total': len(test_in)}}] + else: + tin = test_xs[xs_i] + tout = test_out[xs_i] + + passed = n_correct == len(test_xs) + hints = [{'id': 'test_results', 'args': {'passed': n_correct, 'total': len(test_xs)}}] + if tin: + hints.append({'id': 'problematic_test_case', 'args': {'testin': str(tin), 'testout': str(tout)}}) return passed, hints def hint(python, 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) + exc = get_exception_desc(answer[0][3]) if exc: return exc tokens = get_tokens(code) diff --git a/python/problems/lists_and_for/contains_42/sl.py b/python/problems/lists_and_for/contains_42/sl.py index eaf9609..9477e29 100644 --- a/python/problems/lists_and_for/contains_42/sl.py +++ b/python/problems/lists_and_for/contains_42/sl.py @@ -51,7 +51,7 @@ videl42 = False

in jo tekom zanke ustrezno spremenimo.'''] plan = ['''\ -

Plan. Če bi morali nekomu povedati, kako naj se loti te naloge, bi mu lahko rekli:

+

Plan. Kako bi se tega lotil ročno? Nekako takole:

 Za vsak element v seznamu
     Poglej, ali je 42?
@@ -73,9 +73,9 @@ hint = {
     'if_clause': if_clause,
 
     'printing': ['''\
-

Izpišite rezultat.

'''], +

Izpiši rezultat.

'''], 'print_out_for': ['''\ -

Pazite, da izpišete rezultat izven zanke!

'''] +

Pazi, da izpišeš rezultat izven zanke!

'''] } diff --git a/python/problems/lists_and_for/contains_string/common.py b/python/problems/lists_and_for/contains_string/common.py index 5e0a46b..0fe7c00 100644 --- a/python/problems/lists_and_for/contains_string/common.py +++ b/python/problems/lists_and_for/contains_string/common.py @@ -30,12 +30,12 @@ hint_type = { } def test(python, code): - test_xs = [['foo', 'bar', 'baz', 'Waldo', 'foobar'], + test_xs = [['waldo', 'foo', 'bar', 'baz'], + ['foo', 'bar', 'baz', 'Waldo', 'foobar'], ['foo', 'bar', 'baz', 'Waldo'], ['Waldo', 'foo', 'bar', 'baz'], [], - ['Waldo'], - ['waldo', 'foo', 'bar', 'baz']] + ['Waldo']] test_out = [ True, True, @@ -46,6 +46,7 @@ def test(python, code): ] n_correct = 0 + tin = None for xs_i, xs in enumerate(test_xs): # change code to contain new xs instead of the one # given by user @@ -61,19 +62,23 @@ def test(python, code): if str(test_out[xs_i]) in output and \ str(not test_out[xs_i]) not in output: n_correct += 1 - - passed = n_correct == len(test_in) - hints = [{'id': 'test_results', 'args': {'passed': n_correct, 'total': len(test_in)}}] + else: + tin = test_xs[xs_i] + tout = test_out[xs_i] + + passed = n_correct == len(test_xs) + hints = [{'id': 'test_results', 'args': {'passed': n_correct, 'total': len(test_xs)}}] + if tin: + hints.append({'id': 'problematic_test_case', 'args': {'testin': str(tin), 'testout': str(tout)}}) return passed, hints def hint(python, 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) + exc = get_exception_desc(answer[0][3]) if exc: return exc tokens = get_tokens(code) - print(tokens) # if has no xs, tell him to ask for values if not has_token_sequence(tokens, ['xs', '=', '[']): diff --git a/python/problems/lists_and_for/contains_string/sl.py b/python/problems/lists_and_for/contains_string/sl.py index 5d42784..2f24458 100644 --- a/python/problems/lists_and_for/contains_string/sl.py +++ b/python/problems/lists_and_for/contains_string/sl.py @@ -40,7 +40,7 @@ if x == 'Waldo':
'''] plan = ['''\ -

Plan. je enak kot pri prvi nalogi: +

Plan je enak kot pri prvi nalogi:

 Za vsak element v seznamu
     Poglej, ali je element enak 'Waldo'?
@@ -60,9 +60,9 @@ hint = {
     'if_clause': if_clause,
 
     'printing': ['''\
-

Izpišite rezultat!

'''], +

Izpiši rezultat!

'''], 'print_out_for': ['''\ -

Pazite, da izpišete rezultat izven zanke!

'''] +

Pazi, da izpišeš rezultat izven zanke!

'''] } diff --git a/python/problems/while_and_if/buy_five/common.py b/python/problems/while_and_if/buy_five/common.py index 84be034..9f335af 100644 --- a/python/problems/while_and_if/buy_five/common.py +++ b/python/problems/while_and_if/buy_five/common.py @@ -19,7 +19,6 @@ print('Vsota:', vsota) ''' hint_type = { - 'plan': HintSequence('plan', 5), 'printing': Hint('printing'), 'while_clause': Hint('while_clause'), 'reading_while': Hint('reading_while'), @@ -41,7 +40,7 @@ def test(python, code): 5, 15, 5, - 29, + 30, 0, ] @@ -50,19 +49,25 @@ def test(python, code): outputs = [ans[1] for ans in answers] n_correct = 0 - for output, correct in zip(outputs, test_out): + tin = None + for i, (output, correct) in enumerate(zip(outputs, test_out)): if string_almost_equal(output, correct): n_correct += 1 + else: + tin = test_in[i][1] + tout = correct passed = n_correct == len(test_in) 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)}}) return passed, hints def hint(python, code): # run one test first to see if there are any exceptions test_in = [(None, '1\n1\n1\n1\n1\n')] answer = python(code=code, inputs=test_in, timeout=1.0) - exc = get_exception_desc(answer) + exc = get_exception_desc(answer[0][3]) if exc: return exc tokens = get_tokens(code) diff --git a/python/problems/while_and_if/buy_five/sl.py b/python/problems/while_and_if/buy_five/sl.py index ac90f74..0b5479d 100644 --- a/python/problems/while_and_if/buy_five/sl.py +++ b/python/problems/while_and_if/buy_five/sl.py @@ -2,7 +2,6 @@ import server mod = server.problems.load_language('python', 'sl') - id = 185 name = 'Blagajna "vse po pet"' slug = 'Blagajna "vse po pet"' @@ -46,7 +45,7 @@ main_plan = ['''\ 4. Izpiši vsoto.'''] while_clause = ['''\ -

Kako bi prebral 5 cen z uporabo zanke while?

''', +

Kako bi nekaj 5x ponovil?

''', '''\

Zanka while ima naslednjo sintakso:

diff --git a/python/problems/while_and_if/competition/common.py b/python/problems/while_and_if/competition/common.py
index 4be8b12..a7471df 100644
--- a/python/problems/while_and_if/competition/common.py
+++ b/python/problems/while_and_if/competition/common.py
@@ -45,19 +45,25 @@ def test(python, code):
     outputs = [ans[1] for ans in answers]
 
     n_correct = 0
-    for output, correct in zip(outputs, test_out):
+    tin = None
+    for i, (output, correct) in enumerate(zip(outputs, test_out)):
         if string_almost_equal(output, correct):
             n_correct += 1
+        else:
+            tin = test_in[i][1]
+            tout = correct
 
     passed = n_correct == len(test_in)
     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)}})
     return passed, hints
 
 def hint(python, code):
     # run one test first to see if there are any exceptions
     test_in = [(None, '5\n1\n1\n1\n1\n1\n')]
     answer = python(code=code, inputs=test_in, timeout=1.0)
-    exc = get_exception_desc(answer)
+    exc = get_exception_desc(answer[0][3])
     if exc: return exc
 
     tokens = get_tokens(code)
-- 
cgit v1.2.1