summaryrefslogtreecommitdiff
path: root/prolog
diff options
context:
space:
mode:
Diffstat (limited to 'prolog')
-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).')