diff options
author | Timotej Lazar <timotej.lazar@araneo.org> | 2015-05-06 16:26:57 +0200 |
---|---|---|
committer | Aleš Smodiš <aless@guru.si> | 2015-08-11 14:26:03 +0200 |
commit | 368bb943b548e9b3f338b4a73379608221388bf8 (patch) | |
tree | c103e887b525a4bbeef25b3f3cf28554b6768902 /prolog | |
parent | daf19282ec7783346104ca65b01e4e5f1e2c7128 (diff) |
Remove app-specific code from prolog.engine
Diffstat (limited to 'prolog')
-rw-r--r-- | prolog/engine.py | 39 |
1 files changed, 0 insertions, 39 deletions
diff --git a/prolog/engine.py b/prolog/engine.py index 048190a..6215bb2 100644 --- a/prolog/engine.py +++ b/prolog/engine.py @@ -105,45 +105,6 @@ def get_message(reply): message = re.sub(r'_G[0-9]*', '_', message) return reply['message'], message -# Test whether [code] is a correct solution for problem [name]. Runs all tests -# and returns a list of results. Raises an exception on error. -def test_all(name, code): - reply = create_and_ask(code=code, query="run_tests({}, Results)".format(name)) - - if reply.get('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 - -# Test whether [code] is a correct solution for problem [name]. Returns a bool -# and stops on first failure. -def test(name, code): - try: - reply = create_and_ask(code=code, query='run_tests({})'.format(name)) - return reply.get('event') == 'success' - 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=10): - 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, 0.1)'.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).') |