From 5a6237fc92fc57f87fe3f11144e4ade5baa96350 Mon Sep 17 00:00:00 2001 From: Timotej Lazar Date: Tue, 22 Sep 2015 12:03:57 +0200 Subject: Update test functions for existing problems The test function is now expected to return a boolean indicating whether the program is correct and a list of hint objects. --- prolog/common.py | 1 + prolog/problems/family_relations/brother_2/common.py | 4 +++- prolog/problems/family_relations/father_2/common.py | 4 +++- prolog/problems/family_relations/mother_2/common.py | 4 +++- prolog/problems/family_relations/sister_2/common.py | 4 +++- prolog/sl.py | 4 ++++ python/common.py | 1 + python/problems/introduction/average/common.py | 5 ++++- python/problems/introduction/ballistics/common.py | 5 ++++- python/problems/introduction/fahrenheit_to_celsius/common.py | 5 ++++- python/problems/introduction/fast_fingers/common.py | 4 +++- python/problems/introduction/fast_fingers_2/common.py | 4 +++- python/problems/introduction/pythagorean_theorem/common.py | 5 ++++- python/problems/lists_and_for/contains_42/common.py | 5 ++++- python/problems/lists_and_for/contains_string/common.py | 5 ++++- python/problems/while_and_if/buy_five/common.py | 5 ++++- python/problems/while_and_if/competition/common.py | 5 ++++- python/sl.py | 4 ++++ 18 files changed, 60 insertions(+), 14 deletions(-) diff --git a/prolog/common.py b/prolog/common.py index 41377bb..8dca4dd 100644 --- a/prolog/common.py +++ b/prolog/common.py @@ -6,6 +6,7 @@ from server.hints import Hint, HintSequence hint_type = { 'no_hint': HintSequence('no_hint', 4), + 'system_error': Hint('system_error'), 'test_results': Hint('test_results'), 'syntax_error': Hint('syntax_error'), } diff --git a/prolog/problems/family_relations/brother_2/common.py b/prolog/problems/family_relations/brother_2/common.py index 13f7ab5..4241524 100644 --- a/prolog/problems/family_relations/brother_2/common.py +++ b/prolog/problems/family_relations/brother_2/common.py @@ -58,7 +58,9 @@ def test(program, solved_problems): if engine_id: prolog.engine.destroy(engine_id) - return n_correct, len(test_cases) + passed = n_correct == len(test_in) + hints = [{'id': 'test_results', 'args': {'passed': n_correct, 'total': len(test_in)}}] + return passed, hints def hint(program, solved_problems): # tokens = prolog.util.tokenize(program) diff --git a/prolog/problems/family_relations/father_2/common.py b/prolog/problems/family_relations/father_2/common.py index 1342441..6e752c3 100644 --- a/prolog/problems/family_relations/father_2/common.py +++ b/prolog/problems/family_relations/father_2/common.py @@ -53,7 +53,9 @@ def test(program, solved_problems): if engine_id: prolog.engine.destroy(engine_id) - return n_correct, len(test_cases) + passed = n_correct == len(test_in) + hints = [{'id': 'test_results', 'args': {'passed': n_correct, 'total': len(test_in)}}] + return passed, hints def hint(program, solved_problems): tokens = prolog.util.tokenize(program) diff --git a/prolog/problems/family_relations/mother_2/common.py b/prolog/problems/family_relations/mother_2/common.py index 4d198d4..e90671b 100644 --- a/prolog/problems/family_relations/mother_2/common.py +++ b/prolog/problems/family_relations/mother_2/common.py @@ -64,7 +64,9 @@ def test(program, solved_problems): if engine_id: prolog.engine.destroy(engine_id) - return n_correct, len(test_cases) + passed = n_correct == len(test_in) + hints = [{'id': 'test_results', 'args': {'passed': n_correct, 'total': len(test_in)}}] + return passed, hints def hint(program, solved_problems): tokens = prolog.util.tokenize(program) diff --git a/prolog/problems/family_relations/sister_2/common.py b/prolog/problems/family_relations/sister_2/common.py index 1ae652a..780e2bd 100644 --- a/prolog/problems/family_relations/sister_2/common.py +++ b/prolog/problems/family_relations/sister_2/common.py @@ -61,7 +61,9 @@ def test(program, solved_problems): if engine_id: prolog.engine.destroy(engine_id) - return n_correct, len(test_cases) + passed = n_correct == len(test_in) + hints = [{'id': 'test_results', 'args': {'passed': n_correct, 'total': len(test_in)}}] + return passed, hints def hint(program, solved_problems): # how do I know which general hints were already shown? diff --git a/prolog/sl.py b/prolog/sl.py index 731eff3..b341f66 100644 --- a/prolog/sl.py +++ b/prolog/sl.py @@ -9,6 +9,10 @@ hint = {

… razen ledvic, te so vredne več na črnem trgu.

''', '''\

Definicija norosti: poskušati isto in pričakovati drugačen rezultat.

+'''], + + 'system_error': ['''\ +

Sistemska napaka: [%=message%].

'''], 'test_results': '''\ diff --git a/python/common.py b/python/common.py index 7d4eaab..2b66aff 100644 --- a/python/common.py +++ b/python/common.py @@ -5,6 +5,7 @@ from server.hints import Hint, HintSequence hint_type = { 'no_hint': Hint('no_hint'), + 'system_error': Hint('system_error'), 'test_results': Hint('test_results'), 'syntax_error': Hint('syntax_error'), 'name_error': Hint('name_error'), diff --git a/python/problems/introduction/average/common.py b/python/problems/introduction/average/common.py index 37d5315..0a2b689 100644 --- a/python/problems/introduction/average/common.py +++ b/python/problems/introduction/average/common.py @@ -55,7 +55,10 @@ def test(python, code): if string_almost_equal(output, c[0]) and \ string_almost_equal(output, c[1]): n_correct += 1 - return n_correct, len(test_in) + + passed = n_correct == len(test_in) + hints = [{'id': 'test_results', 'args': {'passed': n_correct, 'total': len(test_in)}}] + return passed, hints def hint(python, code): # run one test first to see if there are any exceptions diff --git a/python/problems/introduction/ballistics/common.py b/python/problems/introduction/ballistics/common.py index 1a75493..f7f271e 100644 --- a/python/problems/introduction/ballistics/common.py +++ b/python/problems/introduction/ballistics/common.py @@ -92,7 +92,10 @@ def test(python, code): for output, correct in zip(outputs, test_out): if string_almost_equal(output, float(correct)): n_correct += 1 - return n_correct, len(test_in) + + passed = n_correct == len(test_in) + hints = [{'id': 'test_results', 'args': {'passed': n_correct, 'total': len(test_in)}}] + return passed, hints def hint(python, code): # run one test first to see if there are any exceptions diff --git a/python/problems/introduction/fahrenheit_to_celsius/common.py b/python/problems/introduction/fahrenheit_to_celsius/common.py index 1ba0e15..2e6c9b7 100644 --- a/python/problems/introduction/fahrenheit_to_celsius/common.py +++ b/python/problems/introduction/fahrenheit_to_celsius/common.py @@ -49,7 +49,10 @@ def test(python, code): for output, correct in zip(outputs, test_out): if correct in output: n_correct += 1 - return n_correct, len(test_in) + + passed = n_correct == len(test_in) + hints = [{'id': 'test_results', 'args': {'passed': n_correct, 'total': len(test_in)}}] + return passed, hints def hint(python, code): # run one test first to see if there are any exceptions diff --git a/python/problems/introduction/fast_fingers/common.py b/python/problems/introduction/fast_fingers/common.py index 3c1b138..8ab51ab 100644 --- a/python/problems/introduction/fast_fingers/common.py +++ b/python/problems/introduction/fast_fingers/common.py @@ -27,7 +27,9 @@ hint_type = { } def test(python, code): - return 0, 0 + passed = True + hints = [{'id': 'test_results', 'args': {'passed': 0, 'total': 0}}] + return passed, hints def hint(python, code): # run one test first to see if there are any exceptions diff --git a/python/problems/introduction/fast_fingers_2/common.py b/python/problems/introduction/fast_fingers_2/common.py index 9c8772f..d562f7b 100644 --- a/python/problems/introduction/fast_fingers_2/common.py +++ b/python/problems/introduction/fast_fingers_2/common.py @@ -33,7 +33,9 @@ hint_type = { } def test(python, code): - return 0,0 + passed = True + hints = [{'id': 'test_results', 'args': {'passed': 0, 'total': 0}}] + return passed, hints def hint(python, code): # run one test first to see if there are any exceptions diff --git a/python/problems/introduction/pythagorean_theorem/common.py b/python/problems/introduction/pythagorean_theorem/common.py index 7a232c1..405a39c 100644 --- a/python/problems/introduction/pythagorean_theorem/common.py +++ b/python/problems/introduction/pythagorean_theorem/common.py @@ -55,7 +55,10 @@ def test(python, code): for output, correct in zip(outputs, test_out): if string_almost_equal(output, float(correct)): n_correct += 1 - return n_correct, len(test_in) + + passed = n_correct == len(test_in) + hints = [{'id': 'test_results', 'args': {'passed': n_correct, 'total': len(test_in)}}] + return passed, hints def hint(python, code): # run one test first to see if there are any exceptions diff --git a/python/problems/lists_and_for/contains_42/common.py b/python/problems/lists_and_for/contains_42/common.py index 3a5a905..3ebe546 100644 --- a/python/problems/lists_and_for/contains_42/common.py +++ b/python/problems/lists_and_for/contains_42/common.py @@ -63,7 +63,10 @@ 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 - return n_correct, len(test_out) + + passed = n_correct == len(test_in) + hints = [{'id': 'test_results', 'args': {'passed': n_correct, 'total': len(test_in)}}] + return passed, hints def hint(python, code): # run one test first to see if there are any exceptions diff --git a/python/problems/lists_and_for/contains_string/common.py b/python/problems/lists_and_for/contains_string/common.py index b69a4ea..5e0a46b 100644 --- a/python/problems/lists_and_for/contains_string/common.py +++ b/python/problems/lists_and_for/contains_string/common.py @@ -61,7 +61,10 @@ 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 - return n_correct, len(test_out) + + passed = n_correct == len(test_in) + hints = [{'id': 'test_results', 'args': {'passed': n_correct, 'total': len(test_in)}}] + return passed, hints def hint(python, code): # run one test first to see if there are any exceptions diff --git a/python/problems/while_and_if/buy_five/common.py b/python/problems/while_and_if/buy_five/common.py index c7081c2..84be034 100644 --- a/python/problems/while_and_if/buy_five/common.py +++ b/python/problems/while_and_if/buy_five/common.py @@ -53,7 +53,10 @@ def test(python, code): for output, correct in zip(outputs, test_out): if string_almost_equal(output, correct): n_correct += 1 - return n_correct, len(test_in) + + passed = n_correct == len(test_in) + hints = [{'id': 'test_results', 'args': {'passed': n_correct, 'total': len(test_in)}}] + return passed, hints def hint(python, code): # run one test first to see if there are any exceptions diff --git a/python/problems/while_and_if/competition/common.py b/python/problems/while_and_if/competition/common.py index 79f7447..4be8b12 100644 --- a/python/problems/while_and_if/competition/common.py +++ b/python/problems/while_and_if/competition/common.py @@ -48,7 +48,10 @@ def test(python, code): for output, correct in zip(outputs, test_out): if string_almost_equal(output, correct): n_correct += 1 - return n_correct, len(test_in) + + passed = n_correct == len(test_in) + hints = [{'id': 'test_results', 'args': {'passed': n_correct, 'total': len(test_in)}}] + return passed, hints def hint(python, code): # run one test first to see if there are any exceptions diff --git a/python/sl.py b/python/sl.py index a4d4065..e7bbed4 100644 --- a/python/sl.py +++ b/python/sl.py @@ -34,6 +34,10 @@ Npr., sešteti niz in število ali klicati funkcijo, čeprav tisto ni funkcija, hint = { 'no_hint': ['''\

Namig ne obstaja! Poskusi uporabiti misli.

+'''], + + 'system_error': ['''\ +

Sistemska napaka: [%=message%].

'''], 'test_results': ['''\ -- cgit v1.2.1 From 091f27eba8afac015386342ca3b924f0789396eb Mon Sep 17 00:00:00 2001 From: Timotej Lazar Date: Tue, 22 Sep 2015 12:19:20 +0200 Subject: Oops, overzealous copy/paste --- prolog/problems/family_relations/brother_2/common.py | 4 ++-- prolog/problems/family_relations/father_2/common.py | 4 ++-- prolog/problems/family_relations/mother_2/common.py | 4 ++-- prolog/problems/family_relations/sister_2/common.py | 4 ++-- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/prolog/problems/family_relations/brother_2/common.py b/prolog/problems/family_relations/brother_2/common.py index 4241524..0df2d73 100644 --- a/prolog/problems/family_relations/brother_2/common.py +++ b/prolog/problems/family_relations/brother_2/common.py @@ -58,8 +58,8 @@ def test(program, solved_problems): if engine_id: prolog.engine.destroy(engine_id) - passed = n_correct == len(test_in) - hints = [{'id': 'test_results', 'args': {'passed': n_correct, 'total': len(test_in)}}] + passed = n_correct == len(test_cases) + hints = [{'id': 'test_results', 'args': {'passed': n_correct, 'total': len(test_cases)}}] return passed, hints def hint(program, solved_problems): diff --git a/prolog/problems/family_relations/father_2/common.py b/prolog/problems/family_relations/father_2/common.py index 6e752c3..22c9b48 100644 --- a/prolog/problems/family_relations/father_2/common.py +++ b/prolog/problems/family_relations/father_2/common.py @@ -53,8 +53,8 @@ def test(program, solved_problems): if engine_id: prolog.engine.destroy(engine_id) - passed = n_correct == len(test_in) - hints = [{'id': 'test_results', 'args': {'passed': n_correct, 'total': len(test_in)}}] + passed = n_correct == len(test_cases) + hints = [{'id': 'test_results', 'args': {'passed': n_correct, 'total': len(test_cases)}}] return passed, hints def hint(program, solved_problems): diff --git a/prolog/problems/family_relations/mother_2/common.py b/prolog/problems/family_relations/mother_2/common.py index e90671b..be0d19b 100644 --- a/prolog/problems/family_relations/mother_2/common.py +++ b/prolog/problems/family_relations/mother_2/common.py @@ -64,8 +64,8 @@ def test(program, solved_problems): if engine_id: prolog.engine.destroy(engine_id) - passed = n_correct == len(test_in) - hints = [{'id': 'test_results', 'args': {'passed': n_correct, 'total': len(test_in)}}] + passed = n_correct == len(test_cases) + hints = [{'id': 'test_results', 'args': {'passed': n_correct, 'total': len(test_cases)}}] return passed, hints def hint(program, solved_problems): diff --git a/prolog/problems/family_relations/sister_2/common.py b/prolog/problems/family_relations/sister_2/common.py index 780e2bd..b3cbff0 100644 --- a/prolog/problems/family_relations/sister_2/common.py +++ b/prolog/problems/family_relations/sister_2/common.py @@ -61,8 +61,8 @@ def test(program, solved_problems): if engine_id: prolog.engine.destroy(engine_id) - passed = n_correct == len(test_in) - hints = [{'id': 'test_results', 'args': {'passed': n_correct, 'total': len(test_in)}}] + passed = n_correct == len(test_cases) + hints = [{'id': 'test_results', 'args': {'passed': n_correct, 'total': len(test_cases)}}] return passed, hints def hint(program, solved_problems): -- cgit v1.2.1