summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xmonkey/test.py106
1 files changed, 53 insertions, 53 deletions
diff --git a/monkey/test.py b/monkey/test.py
index cf67723..ce7df93 100755
--- a/monkey/test.py
+++ b/monkey/test.py
@@ -60,16 +60,36 @@ def print_hint(code, solution, steps, fix_time, n_tested):
for step_type, pos, a, b in steps:
print(' {}: {} {} → {}'.format(pos, step_type, stringify(a), stringify(b)))
print(colored(' Hints', 'blue'))
- for (start, end), msg in fix_hints(code, steps):
- print(' {}-{}: {}'.format(start, end, msg))
+ for loc, msg in fix_hints(code, steps):
+ print(' {}-{}: {}'.format(loc['start'], loc['end'], msg))
print(colored(' Final version', 'blue'))
print(indent(compose(annotate(solution)), 2))
else:
print(colored('Hint not found! Tested {} programs in {:.1f} s.'.format(n_tested, fix_time), 'red'))
+# Run interactive loop.
+if len(sys.argv) == 2:
+ while True:
+ # Read the program from stdin.
+ print('Enter program, end with empty line:')
+ code = ''
+ try:
+ while True:
+ line = input()
+ if not line:
+ break
+ code += line + '\n'
+ except EOFError:
+ break
+
+ # Try finding a fix.
+ print(colored('Analyzing program…', 'yellow'))
+ solution, steps, fix_time, n_tested = fix(problem.name, code, edits, aux_code=aux_code, debug=True)
+ print_hint(code, solution, steps, fix_time, n_tested)
+
# Test fix() on incorrect student submissions.
-if len(sys.argv) >= 3 and sys.argv[2] == 'test':
- timeout = int(sys.argv[3]) if len(sys.argv) >= 4 else 10
+elif sys.argv[2] == 'test':
+ timeout = int(sys.argv[3]) if len(sys.argv) == 4 else 10
print('Fixing {}/{} programs (timeout={})…'.format(
len([p for p in incorrect if p not in done]), len(incorrect), timeout))
@@ -91,7 +111,7 @@ if len(sys.argv) >= 3 and sys.argv[2] == 'test':
print('Found hints for ' + str(len(done)) + ' of ' + str(len(incorrect)) + ' incorrect programs')
# Print info for this problem.
-elif len(sys.argv) >= 3 and sys.argv[2] == 'info':
+elif sys.argv[2] == 'info':
# With no additional arguments, print some stats.
if len(sys.argv) == 3:
print('Problem {} ({}): {} edits in {} traces, fixed {}/{} ({}/{} unique)'.format(
@@ -101,36 +121,36 @@ elif len(sys.argv) >= 3 and sys.argv[2] == 'info':
colored(str(len(incorrect_all)), 'yellow'),
colored(str(len(set(done))), 'yellow'),
colored(str(len(set(incorrect))), 'yellow')))
- else:
- if sys.argv[3] == 'users':
- print(' '.join([str(a.user.pk) for a in attempts]))
- # Print all observed edits and their costs.
- elif sys.argv[3] == 'edits':
- inserts, removes, changes = classify_edits(edits)
- print('Inserts')
- for after, cost in sorted(inserts.items(), key=lambda x: x[1]):
- print(' {:.4f}\t{}'.format(cost, stringify(after)))
- print('Removes')
- for before, cost in sorted(removes.items(), key=lambda x: x[1]):
- print(' {:.4f}\t{}'.format(cost, stringify(before)))
- print('Changes')
- for (before, after), cost in sorted(changes.items(), key=lambda x: x[1]):
- print(' {:.4f}\t{} → {}'.format(cost, stringify(before) if before else 'ε',
- stringify(after) if after else 'ε'))
- # Print all student submissions not (yet) corrected.
- elif sys.argv[3] == 'unsolved':
- for p in sorted(incorrect):
- if p in done:
- continue
- print(indent(compose(annotate(p)), 2))
- print()
- # Print all student queries and their counts.
- elif sys.argv[3] == 'queries':
- for query, count in queries.most_common():
- print(' ' + str(count) + '\t' + query)
+
+ elif sys.argv[3] == 'users':
+ print(' '.join([str(a.user.pk) for a in attempts]))
+ # Print all observed edits and their costs.
+ elif sys.argv[3] == 'edits':
+ inserts, removes, changes = classify_edits(edits)
+ print('Inserts')
+ for after, cost in sorted(inserts.items(), key=lambda x: x[1]):
+ print(' {:.4f}\t{}'.format(cost, stringify(after)))
+ print('Removes')
+ for before, cost in sorted(removes.items(), key=lambda x: x[1]):
+ print(' {:.4f}\t{}'.format(cost, stringify(before)))
+ print('Changes')
+ for (before, after), cost in sorted(changes.items(), key=lambda x: x[1]):
+ print(' {:.4f}\t{} → {}'.format(cost, stringify(before) if before else 'ε',
+ stringify(after) if after else 'ε'))
+ # Print all student submissions not (yet) corrected.
+ elif sys.argv[3] == 'unsolved':
+ for p in sorted(incorrect):
+ if p in done:
+ continue
+ print(indent(compose(annotate(p)), 2))
+ print()
+ # Print all student queries and their counts.
+ elif sys.argv[3] == 'queries':
+ for query, count in queries.most_common():
+ print(' ' + str(count) + '\t' + query)
# Print the edit graph in graphviz dot syntax.
-elif len(sys.argv) == 4 and sys.argv[2] == 'graph':
+elif sys.argv[2] == 'graph' and len(sys.argv) == 4:
uid = int(sys.argv[3])
user = User.objects.get(pk=uid)
attempt = Attempt.objects.get(problem=problem, user=user)
@@ -156,23 +176,3 @@ elif len(sys.argv) == 4 and sys.argv[2] == 'graph':
graphviz_str = graphviz(nodes, pos=position, label=label,
node_attr=node_attr, edge_attr=edge_attr)
print(graphviz_str)
-
-# Run interactive loop.
-else:
- while True:
- # Read the program from stdin.
- print('Enter program, end with empty line:')
- code = ''
- try:
- while True:
- line = input()
- if not line:
- break
- code += line + '\n'
- except EOFError:
- break
-
- # Try finding a fix.
- print(colored('Analyzing program…', 'yellow'))
- solution, steps, fix_time, n_tested = fix(problem.name, code, edits, aux_code=aux_code, debug=True)
- print_hint(code, solution, steps, fix_time, n_tested)