summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTimotej Lazar <timotej.lazar@araneo.org>2015-09-02 11:27:32 +0200
committerTimotej Lazar <timotej.lazar@araneo.org>2015-09-02 11:27:32 +0200
commit72b50c8bdde8a6624f07aa14b7cee8712955d54d (patch)
tree31a61af25c4dbf7a493630f58e9f33dee292471a
parentaaee96e6545380935e01e27b1150638fa9260657 (diff)
Accept test function as a parameter to monkey.fix
-rwxr-xr-xmonkey/monkey.py21
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