diff options
Diffstat (limited to 'monkey')
-rwxr-xr-x | monkey/monkey.py | 21 |
1 files changed, 5 insertions, 16 deletions
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 |