summaryrefslogtreecommitdiff
path: root/prolog/engine.py
diff options
context:
space:
mode:
authorTimotej Lazar <timotej.lazar@araneo.org>2015-03-15 16:48:46 +0100
committerAleš Smodiš <aless@guru.si>2015-08-11 14:26:02 +0200
commit5d00e713bd3a6414c33770f05b1a56af1f681d9d (patch)
tree16f95b4d93b232d480f44d87926ed9fc051d617f /prolog/engine.py
parent693af6ca3ebac55aa1afb07d411145b7334b628a (diff)
Print a random failing test for incorrect solution
Diffstat (limited to 'prolog/engine.py')
-rw-r--r--prolog/engine.py17
1 files changed, 17 insertions, 0 deletions
diff --git a/prolog/engine.py b/prolog/engine.py
index e64f728..be19fec 100644
--- a/prolog/engine.py
+++ b/prolog/engine.py
@@ -127,6 +127,23 @@ def test(name, code):
except Exception as ex:
return False
+# Try to generate a random test case for problem [name] with [solution] that
+# fails for [code]. Give up after [tries] attempts.
+def create_failing_test(name, solution, code, tries=20):
+ try:
+ for i in range(tries):
+ reply = create_and_ask(code=solution,
+ query='create_test({}, Test)'.format(name))
+ testcase = reply['data'][0]['Test']
+ reply = create_and_ask(code=code,
+ query='run_test({}, Result)'.format(testcase))
+ result = reply['data'][0]['Result']
+ if not result.startswith('success'):
+ return testcase
+ except Exception as ex:
+ pass
+ return None
+
# Basic sanity check.
if __name__ == '__main__':
engine = create(code='dup([],[]). dup([H|T],[H,H|TT]) :- dup(T,TT).')