From de7b441fe4ebd88fc19abbd6542cb8129f735ced Mon Sep 17 00:00:00 2001 From: Aleksander Sadikov Date: Sun, 22 May 2016 20:37:28 +0200 Subject: Denotational semantics, part #1: tests and translations added. --- .../prog_8puzzle_2/common.py | 39 ++++++++++++++++++++++ .../denotational_semantics/prog_8puzzle_2/sl.py | 16 +++++++++ 2 files changed, 55 insertions(+) create mode 100644 prolog/problems/denotational_semantics/prog_8puzzle_2/sl.py (limited to 'prolog/problems/denotational_semantics/prog_8puzzle_2') diff --git a/prolog/problems/denotational_semantics/prog_8puzzle_2/common.py b/prolog/problems/denotational_semantics/prog_8puzzle_2/common.py index 22429cc..7f78fec 100644 --- a/prolog/problems/denotational_semantics/prog_8puzzle_2/common.py +++ b/prolog/problems/denotational_semantics/prog_8puzzle_2/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 = 172 number = 30 visible = True @@ -14,3 +21,35 @@ instr172 --> [right]. instr172 --> [up]. instr172 --> [down]. ''' + +test_cases = [ + ('findall(W, (W = [_], prog_8puzzle(W, [])), Words), Words == []', + [{}]), + ('setof(W, [A,B,C]^(W = [A,B,C], prog_8puzzle(W, [])), Words), \ + Words == [[begin,down,end],[begin,left,end],[begin,right,end],[begin,up,end]]', + [{}]), + ('setof(W, [A,B,C,D]^(W = [A,B,C,D], prog_8puzzle(W, [])), Words), length(Words, 16)', + [{}]), + ('prog_8puzzle([begin,down,down,up,up,left,left,right,end], [])', + [{}]), +] + +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 + diff --git a/prolog/problems/denotational_semantics/prog_8puzzle_2/sl.py b/prolog/problems/denotational_semantics/prog_8puzzle_2/sl.py new file mode 100644 index 0000000..0e5ad88 --- /dev/null +++ b/prolog/problems/denotational_semantics/prog_8puzzle_2/sl.py @@ -0,0 +1,16 @@ +name = 'prog_8puzzle/2' +slug = 'jezik za reševanje igre Osem' + +description = '''\ +

+Napiši DCG za jezik igre Osem (angl. 8-puzzle). Prvi simbol vsake besede je simbol [begin], temu pa +sledi poljubno zaporedje "ukazov" iz nabora {left, right, up down}, +na koncu pa je simbol [end]. Začetni nekončni simbol naj se imenuje prog_8puzzle. +

+ +

+Primeri veljavnih besed: [begin,left,down,right,end], [begin,down,end]. +

+''' + +hint = {} -- cgit v1.2.1