From bacad47b87c5c2f9a90734ef13ca98a0961a08bb Mon Sep 17 00:00:00 2001 From: Timotej Lazar Date: Fri, 16 Jan 2015 15:05:53 +0100 Subject: Add prolog.engine.test Runs tests for the specified predicate on the given code and returns True if all tests succeed. Stop at first failure. --- monkey/prolog/engine.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'monkey') diff --git a/monkey/prolog/engine.py b/monkey/prolog/engine.py index 2ed59a5..432ff79 100644 --- a/monkey/prolog/engine.py +++ b/monkey/prolog/engine.py @@ -128,6 +128,18 @@ def test_all(name, code): n_passed = len([r for r in results if r.startswith('success')]) return (n_passed, n_total) +# Test whether [code] is a correct solution for problem [name]. Returns a bool +# and stops on first failure. +def test(name, code): + ret = False + try: + engine = PrologEngine(code=code) + ret = engine.ask("run_tests({}, '{}')".format(name, engine.id))['event'] == 'success' + engine.destroy() + except Exception as ex: + pass + return ret + # Basic sanity check. if __name__ == '__main__': engine = PrologEngine(code='dup([],[]). dup([H|T],[H,H|TT]) :- dup(T,TT).') -- cgit v1.2.1