From 5d00e713bd3a6414c33770f05b1a56af1f681d9d Mon Sep 17 00:00:00 2001 From: Timotej Lazar Date: Sun, 15 Mar 2015 16:48:46 +0100 Subject: Print a random failing test for incorrect solution --- prolog/engine.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'prolog') 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).') -- cgit v1.2.1