summaryrefslogtreecommitdiff
path: root/monkey
diff options
context:
space:
mode:
authorTimotej Lazar <timotej.lazar@fri.uni-lj.si>2016-01-06 13:04:34 +0100
committerTimotej Lazar <timotej.lazar@fri.uni-lj.si>2016-01-06 13:04:34 +0100
commitbedda51c8d4acb81ff4af2f8d79c1c4b3ba0ebf1 (patch)
tree455f2c6e29f648695040ebebfac29d77c6ec346e /monkey
parentd4fdb8ce1a14f5633dfff21ed2333379615a1e1a (diff)
Update and fix monkey.test
Diffstat (limited to 'monkey')
-rwxr-xr-xmonkey/test.py28
1 files changed, 15 insertions, 13 deletions
diff --git a/monkey/test.py b/monkey/test.py
index f46d738..1d82c33 100755
--- a/monkey/test.py
+++ b/monkey/test.py
@@ -20,11 +20,11 @@ import sys
from termcolor import colored
-from db.models import CodeqUser, Problem, Solution
-from .graph import graphviz
+from db.util import make_identifier
+from db.models import Problem, Solution
from . import fix, fix_hints
-from prolog.util import parse, tokenize, stringify
-import server.problems
+from prolog.util import parse, stringify, used_predicates
+from server.problems import get_facts, load_group, load_problem, solutions_for_problems
from .util import indent
# Get problem id from commandline.
@@ -33,18 +33,20 @@ 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
+problem_name = load_problem(problem.language, problem.group, problem.identifier, 'en').name
-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))
+problem_module = load_problem(problem.language, problem.group, problem.identifier, 'common')
+other_problems = [p for p in Problem.filter_language(problem.language)
+ if p.identifier != problem.identifier]
+facts = get_facts(problem.language, problem_module)
# Testing function.
def test(code):
+ # Find solutions to other problems that are used by this program.
+ used_predicate_identifiers = {make_identifier(name) for name in used_predicates(code)}
+ dependencies = sorted([p[2:] for p in other_problems
+ if p.identifier in used_predicate_identifiers])
+ aux_code = '\n' + solutions_for_problems('prolog', dependencies) + '\n' + facts
correct, hints = problem_module.test(code, aux_code)
return correct
@@ -135,7 +137,7 @@ elif sys.argv[2] == 'info':
# With no additional arguments, print some stats.
if len(sys.argv) == 3:
print('Problem {} ({}): {} edits and {} different submissions in {} traces'.format(
- problem.id, colored(name, 'yellow'),
+ problem.id, colored(problem_name, 'yellow'),
colored(str(len(edits)), 'yellow'),
colored(str(len(submissions)), 'yellow'),
colored(str(len(traces)), 'yellow')))