summaryrefslogtreecommitdiff
path: root/python/problems/lists_and_for/calculator_polish/common.py
diff options
context:
space:
mode:
authorMartin <martin@leo.fri1.uni-lj.si>2015-10-09 16:35:23 +0200
committerMartin <martin@leo.fri1.uni-lj.si>2015-10-09 16:35:23 +0200
commit95e107bf9e6a288969e4a83aee1a7062990f3b67 (patch)
treef69b15164a30d464f6f7b340634095716344b1ec /python/problems/lists_and_for/calculator_polish/common.py
parentfd31d7d74e58796f3a5a7c84b4b19cb4af59ef4c (diff)
Fixed testing for most problems.
Diffstat (limited to 'python/problems/lists_and_for/calculator_polish/common.py')
-rw-r--r--python/problems/lists_and_for/calculator_polish/common.py33
1 files changed, 30 insertions, 3 deletions
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)}})