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. --- .../lists_and_for/calculator_polish/common.py | 33 ++++++++++++++++++++-- 1 file changed, 30 insertions(+), 3 deletions(-) (limited to 'python/problems/lists_and_for/calculator_polish/common.py') 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)}}) -- cgit v1.2.1