summaryrefslogtreecommitdiff
path: root/monkey/test.py
diff options
context:
space:
mode:
authorTimotej Lazar <timotej.lazar@araneo.org>2015-03-02 16:06:36 +0100
committerAleš Smodiš <aless@guru.si>2015-08-11 14:26:02 +0200
commita60b0ef82a3f6c0cc38084200f92ae293d729116 (patch)
tree5beadcbf825551de37fd6484764ef44c87500632 /monkey/test.py
parent720f4aa6426e1463757b3192e13b9f705a354a65 (diff)
Annotate tokens instead of splitting program
Instead of splitting the program by line numbers, do limited parsing (enough to distinguish , in "memb(X,Y)" from , in "a :- b, c."). Each token in the parsed program is annotated with rule and part number. Rewrite monkey.fix.step to take program as a sequence of annotated tokens instead of lists of lines and rules. Improve message passing to website.
Diffstat (limited to 'monkey/test.py')
-rwxr-xr-xmonkey/test.py12
1 files changed, 6 insertions, 6 deletions
diff --git a/monkey/test.py b/monkey/test.py
index 83aa0c2..17c27fe 100755
--- a/monkey/test.py
+++ b/monkey/test.py
@@ -11,7 +11,7 @@ from .edits import classify_edits, trace_graph
from .graph import graphviz
from .monkey import fix
from prolog.engine import test
-from prolog.util import compose, decompose, stringify
+from prolog.util import annotate, compose, stringify
from .util import indent
# Load django models.
@@ -57,10 +57,10 @@ def print_hint(solution, steps, fix_time, n_tested):
if solution:
print(colored('Hint found! Tested {} programs in {:.1f} s.'.format(n_tested, fix_time), 'green'))
print(colored(' Edits', 'blue'))
- for step_type, line, (before, after) in steps:
- print(' {}: {} {} → {}'.format(line, step_type, stringify(before), stringify(after)))
+ for step_type, pos, a, b in steps:
+ print(' {}: {} {} → {}'.format(pos, step_type, stringify(a), stringify(b)))
print(colored(' Final version', 'blue'))
- print(indent(compose(*decompose(solution)), 2))
+ print(indent(compose(annotate(solution)), 2))
else:
print(colored('Hint not found! Tested {} programs in {:.1f} s.'.format(n_tested, fix_time), 'red'))
@@ -75,7 +75,7 @@ if len(sys.argv) >= 3 and sys.argv[2] == 'test':
if program in done:
continue
print(colored('Analyzing program {0}/{1}…'.format(i+1, len(incorrect)), 'yellow'))
- print(indent(compose(*decompose(program)), 2))
+ print(indent(compose(annotate(program)), 2))
solution, steps, fix_time, n_tested = fix(problem.name, program, edits, aux_code=aux_code, timeout=timeout)
if solution:
@@ -119,7 +119,7 @@ elif len(sys.argv) >= 3 and sys.argv[2] == 'info':
for p in sorted(incorrect):
if p in done:
continue
- print(indent(compose(*decompose(p)), 2))
+ print(indent(compose(annotate(p)), 2))
print()
# Print all student queries and their counts.
elif sys.argv[3] == 'queries':