summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--monkey/edits.py10
-rwxr-xr-xmonkey/test.py13
-rw-r--r--server/problems.py8
-rw-r--r--server/prolog_session.py11
4 files changed, 26 insertions, 16 deletions
diff --git a/monkey/edits.py b/monkey/edits.py
index 7ebb034..0bbedef 100644
--- a/monkey/edits.py
+++ b/monkey/edits.py
@@ -215,12 +215,14 @@ if __name__ == '__main__':
continue
# Testing function.
- solved_problems = [p for p in CodeqUser.solved_problems(1, problem.language)
- if p != (problem.group, problem.identifier)]
- other_solutions = server.problems.solutions_for_problems(problem.language, solved_problems)
+ group_module = server.problems.load_group(problem.language, problem.group, 'common')
problem_module = server.problems.load_problem(problem.language, problem.group, problem.identifier, 'common')
+ solved_problems = [p for p in CodeqUser.solved_problems(1, problem.language)
+ if p[0] in group_module.allowed_groups and p != (problem.group, problem.identifier)]
+ aux_code = ('\n' + server.problems.solutions_for_problems('prolog', solved_problems) +
+ '\n' + server.problems.get_facts('prolog', problem_module))
def test(code):
- correct, hints = problem_module.test(code, solved_problems)
+ correct, hints = problem_module.test(code, aux_code)
return correct
print('Analyzing traces for {}… '.format(problem.identifier), end='', flush=True)
diff --git a/monkey/test.py b/monkey/test.py
index 71d8aa5..f46d738 100755
--- a/monkey/test.py
+++ b/monkey/test.py
@@ -33,16 +33,19 @@ if len(sys.argv) < 2:
sys.exit(1)
problem = Problem.get(id=sys.argv[1])
+name = server.problems.load_problem(problem.language, problem.group, problem.identifier, 'en').name
-solved_problems = [p for p in CodeqUser.solved_problems(1, problem.language)
- if p != (problem.group, problem.identifier)]
-other_solutions = server.problems.solutions_for_problems(problem.language, solved_problems)
+group_module = server.problems.load_group(problem.language, problem.group, 'common')
problem_module = server.problems.load_problem(problem.language, problem.group, problem.identifier, 'common')
-name = server.problems.load_problem(problem.language, problem.group, problem.identifier, 'en').name
+
+solved_problems = [p for p in CodeqUser.solved_problems(1, problem.language)
+ if p[0] in group_module.allowed_groups and p != (problem.group, problem.identifier)]
+aux_code = ('\n' + server.problems.solutions_for_problems('prolog', solved_problems) +
+ '\n' + server.problems.get_facts('prolog', problem_module))
# Testing function.
def test(code):
- correct, hints = problem_module.test(code, solved_problems)
+ correct, hints = problem_module.test(code, aux_code)
return correct
traces = [s.trace for s in Solution.filter(problem_id=problem.id)]
diff --git a/server/problems.py b/server/problems.py
index 40c8eab..10dec0d 100644
--- a/server/problems.py
+++ b/server/problems.py
@@ -76,16 +76,16 @@ def get_facts(language, problem_module):
try:
facts = problem_module.facts
except AttributeError as e:
- return None
+ return ''
if facts is None:
- return None
+ return ''
module = load_facts(language, facts)
if module:
try:
return module.facts
except AttributeError as e:
- return None
- return None
+ return ''
+ return ''
def solutions_for_problems(language, tuples):
if not tuples:
diff --git a/server/prolog_session.py b/server/prolog_session.py
index c6e5b69..cb9fd19 100644
--- a/server/prolog_session.py
+++ b/server/prolog_session.py
@@ -149,13 +149,18 @@ class PrologSession(server.LanguageSession):
def test(self, sid, problem_id, program):
session = server.user_session.get_session_by_id(sid)
p = Problem.get(id=problem_id)
+
language_module = problems.load_language(p.language, 'common')
+ group_module = problems.load_group(p.language, p.group, 'common')
problem_module = problems.load_problem(p.language, p.group, p.identifier, 'common')
solved_problems = [pp for pp in CodeqUser.solved_problems(session.get_uid(), p.language)
- if pp != (p.group, p.identifier)]
+ if pp[0] in group_module.allowed_groups and pp != (p.group, p.identifier)]
+ aux_code = ('\n' + problems.solutions_for_problems('prolog', solved_problems) +
+ '\n' + problems.get_facts('prolog', problem_module))
+
try:
- passed, hints = problem_module.test(program, solved_problems)
+ passed, hints = problem_module.test(program, aux_code)
if passed:
session.update_solution(problem_id, done=True)
except AttributeError as ex:
@@ -187,7 +192,7 @@ class PrologSession(server.LanguageSession):
solved_problems = [pp for pp in CodeqUser.solved_problems(user_id, p.language)
if pp != (p.group, p.identifier)]
other_solutions = problems.solutions_for_problems(p.language, solved_problems)
- problem_facts = problems.get_facts(p.language, problem_module) or ''
+ problem_facts = problems.get_facts(p.language, problem_module)
code = program + '\n' + other_solutions + '\n' + problem_facts
messages, status, have_more = self.run(code)