summaryrefslogtreecommitdiff
path: root/server/prolog_session.py
diff options
context:
space:
mode:
Diffstat (limited to 'server/prolog_session.py')
-rw-r--r--server/prolog_session.py47
1 files changed, 14 insertions, 33 deletions
diff --git a/server/prolog_session.py b/server/prolog_session.py
index cac379a..c5fc2be 100644
--- a/server/prolog_session.py
+++ b/server/prolog_session.py
@@ -111,7 +111,11 @@ class PrologSession(server.LanguageSession):
prolog.engine.destroy(self._engine_id)
self._engine_id = None
+ # TODO remove this
def hint(self, sid, problem_id, program):
+ return []
+
+ def test(self, sid, problem_id, program):
session = server.user_session.get_session_by_id(sid)
problem = Problem.get(id=problem_id)
@@ -119,13 +123,12 @@ class PrologSession(server.LanguageSession):
problem_module = load_problem(problem.language, problem.group, problem.identifier, 'common')
aux_code = self._aux_code(session.get_uid(), problem, program)
- hints = []
- try:
- # check if the program is already correct
- n_correct, n_all, _ = problem_module.test(program, aux_code=aux_code)
- if n_correct == n_all:
- hints = [{'id': 'program_already_correct'}]
-
+ # check if the program is correct
+ n_correct, n_all, msgs = problem_module.test(program, aux_code=aux_code)
+ if n_correct == n_all:
+ session.update_solution(problem_id, done=True)
+ else:
+ hints = []
if not hints and hasattr(language_module, 'hint'):
hints = language_module.hint(program, aux_code=aux_code)
if not hints and hasattr(problem_module, 'hint'):
@@ -139,33 +142,11 @@ class PrologSession(server.LanguageSession):
program, _edits[problem_id], tester, timeout=3)
if solution and steps:
hints = [{'id': 'monkey_main'}] + monkey.fix_hints(program, steps)
- if not hints:
- hints = [{'id': 'no_hint'}]
- except Exception as ex:
- hints = [{'id': 'system_error', 'args': {'message': str(ex)}}]
-
- self._instantiate_and_save_hints(language_module, problem_module, hints)
- return hints
-
- def test(self, sid, problem_id, program):
- session = server.user_session.get_session_by_id(sid)
- problem = Problem.get(id=problem_id)
-
- language_module = load_language(problem.language, 'common')
- problem_module = load_problem(problem.language, problem.group, problem.identifier, 'common')
- aux_code = self._aux_code(session.get_uid(), problem, program)
+ if hints:
+ msgs.extend(hints)
- try:
- n_correct, n_all, hints = problem_module.test(program, aux_code=aux_code)
- if n_correct == n_all:
- session.update_solution(problem_id, done=True)
- except AttributeError as ex:
- hints = [{'id': 'system_error', 'args': {'message': 'test function does not exist'}}]
- except Exception as ex:
- hints = [{'id': 'system_error', 'args': {'message': str(ex)}}]
-
- self._instantiate_and_save_hints(language_module, problem_module, hints)
- return hints
+ self._instantiate_and_save_hints(language_module, problem_module, msgs)
+ return msgs
# Return a string with definitions of aux. predicates used in [program]
# (but only those that the user has already solved) and any required facts.