From 7bc5d05a777045dbd5c9feace7c52c074b146794 Mon Sep 17 00:00:00 2001 From: Aleksander Sadikov Date: Sun, 29 May 2016 19:04:26 +0200 Subject: Denotational semantics, part #2 (mini algol): tests and translations added. --- prolog/problems/algol/algol_3/common.py | 36 ++++++++++++++++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) (limited to 'prolog/problems/algol/algol_3/common.py') diff --git a/prolog/problems/algol/algol_3/common.py b/prolog/problems/algol/algol_3/common.py index ff38469..e997bde 100644 --- a/prolog/problems/algol/algol_3/common.py +++ b/prolog/problems/algol/algol_3/common.py @@ -1,3 +1,10 @@ +from operator import itemgetter +import socket + +import prolog.engine +import prolog.util +from server.hints import Hint, HintPopup + id = 176 number = 10 visible = True @@ -163,5 +170,32 @@ eval(E1 * E2, State, Val) :- !, eval(E1 / E2, State, Val) :- !, eval(E1, State, V1), eval(E2, State, V2), - Val is V1 / V2. + Val is V1 / V2. ''' + +test_cases = [ + ('findall(W, (W = [_], algol(_, W, [])), Words), Words == []', + [{}]), + ('algol(F, [begin,a,:=,a+2,end], []), apply([a=3], Out, F), msort(Out, OutSorted), OutSorted == [a=5,printout=[]]', + [{}]), +] + +def test(code, aux_code): + n_correct = 0 + engine_id = None + try: + engine_id, output = prolog.engine.create(code=code+aux_code, timeout=1.0) + if engine_id is not None and 'error' not in map(itemgetter(0), output): + # Engine successfully created, and no syntax error in program. + for query, answers in test_cases: + if prolog.engine.check_answers(engine_id, query=query, answers=answers, timeout=1.0): + n_correct += 1 + except socket.timeout: + pass + finally: + if engine_id: + prolog.engine.destroy(engine_id) + + hints = [{'id': 'test_results', 'args': {'passed': n_correct, 'total': len(test_cases)}}] + return n_correct, len(test_cases), hints + -- cgit v1.2.1