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/lists_and_for/split_word/common.py | 26 ++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) (limited to 'python/problems/lists_and_for/split_word/common.py') 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)}}) -- cgit v1.2.1