From bedda51c8d4acb81ff4af2f8d79c1c4b3ba0ebf1 Mon Sep 17 00:00:00 2001 From: Timotej Lazar Date: Wed, 6 Jan 2016 13:04:34 +0100 Subject: Update and fix monkey.test --- monkey/test.py | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) (limited to 'monkey') 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'))) -- cgit v1.2.1