summaryrefslogtreecommitdiff
path: root/prolog
diff options
context:
space:
mode:
authorTimotej Lazar <timotej.lazar@araneo.org>2015-01-13 13:33:06 +0100
committerAleš Smodiš <aless@guru.si>2015-08-11 14:26:01 +0200
commitd86793039957aa408a98806aecfb5964bda5fb87 (patch)
tree3478ea3b578a0da40060bdeceb3e729c4e36fbca /prolog
parent31237ac54a3dd7828483d1f703dfd39e34d4408b (diff)
Add prolog.engine.test
Depends on run_tests/3.
Diffstat (limited to 'prolog')
-rw-r--r--prolog/engine.py13
1 files changed, 13 insertions, 0 deletions
diff --git a/prolog/engine.py b/prolog/engine.py
index a25a07d..dff577c 100644
--- a/prolog/engine.py
+++ b/prolog/engine.py
@@ -114,6 +114,19 @@ class PrologEngine(object):
message = re.sub(r'_G[0-9]*', '_', message)
return message
+def test(name, code):
+ engine = PrologEngine(code=code)
+ reply = engine.ask("run_tests({}, '{}', Results)".format(name, engine.id))
+ engine.destroy()
+
+ if reply['event'] != 'success':
+ raise Exception('testing procedure failed')
+
+ results = re.findall(r'(?:success|failure)\([^)]*\)', reply['data'][0]['Results'])
+ n_total = len(results)
+ n_passed = len([r for r in results if r.startswith('success')])
+ return (n_passed, n_total)
+
# Basic sanity check.
if __name__ == '__main__':
engine = PrologEngine(code='dup([],[]). dup([H|T],[H,H|TT]) :- dup(T,TT).')