From 72b50c8bdde8a6624f07aa14b7cee8712955d54d Mon Sep 17 00:00:00 2001 From: Timotej Lazar Date: Wed, 2 Sep 2015 11:27:32 +0200 Subject: Accept test function as a parameter to monkey.fix --- monkey/monkey.py | 21 +++++---------------- 1 file changed, 5 insertions(+), 16 deletions(-) (limited to 'monkey') diff --git a/monkey/monkey.py b/monkey/monkey.py index 0939448..6577450 100755 --- a/monkey/monkey.py +++ b/monkey/monkey.py @@ -8,23 +8,12 @@ from .edits import classify_edits from prolog.util import Token, annotate, compose, map_vars, normalized, rename_vars, stringify from .util import damerau_levenshtein, PQueue -# Check whether all tests for problem [name] succeed. -def test(name, code): - return False - # XXX currently broken - #try: - # reply, output = prolog.engine.create( - # code=code, query='run_tests({})'.format(name)) - # return reply.get('event') == 'success' - #except Exception as ex: - # return False - # Starting from [code], find a sequence of edits that transforms it into a -# correct predicate for [name]. Append [aux_code] when testing (available facts -# and predicates). +# correct predicate for [name]. The [test] function is used to test generated +# programs. # Return (solution, edits, time spent, #programs checked). If no solution is -# found within [timeout] seconds, solution='' and edits=[]. -def fix(name, code, edits, aux_code='', timeout=30, debug=False): +# found within [timeout] seconds, return solution='' and edits=[]. +def fix(name, code, edits, test, timeout=30, debug=False): # A dictionary of edits with costs for each edit type (insert, remove or # change a line). Edits are tuples (before, after), where before and after # are sequences of tokens. Variable names are normalized to A0, A1, A2,…. @@ -254,7 +243,7 @@ def fix(name, code, edits, aux_code='', timeout=30, debug=False): print('index {}: {} {} → {}'.format(idx, step_type, stringify(a), stringify(b))) # If the code is correct, we are done. - if test(name, code + '\n' + aux_code): + if test(code): path = postprocess(path) return code, path, total_time, n_tested n_tested += 1 -- cgit v1.2.1