summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTimotej Lazar <timotej.lazar@araneo.org>2015-01-16 15:05:53 +0100
committerAleš Smodiš <aless@guru.si>2015-08-11 14:26:01 +0200
commitbacad47b87c5c2f9a90734ef13ca98a0961a08bb (patch)
tree9ab64615db239d6b7ca73406e99a032a38aa425b
parent404d1f76bdc99675c6fb526691773aa84d711e55 (diff)
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.
-rw-r--r--monkey/prolog/engine.py12
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).')