diff options
Diffstat (limited to 'monkey')
-rw-r--r-- | monkey/prolog/engine.py | 12 |
1 files changed, 12 insertions, 0 deletions
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).') |