summaryrefslogtreecommitdiff
path: root/prolog/problems/denotational_semantics/prog_8puzzle_3/common.py
diff options
context:
space:
mode:
authorAleksander Sadikov <aleksander.sadikov@fri.uni-lj.si>2016-05-22 20:37:28 +0200
committerAleksander Sadikov <aleksander.sadikov@fri.uni-lj.si>2016-05-22 20:37:28 +0200
commitde7b441fe4ebd88fc19abbd6542cb8129f735ced (patch)
tree9c409cc281e5a095e468f20d9a33b1acad3ed5e7 /prolog/problems/denotational_semantics/prog_8puzzle_3/common.py
parent52a65d75cd7adc7983d4e6c45709b7571497ca9a (diff)
Denotational semantics, part #1: tests and translations added.
Diffstat (limited to 'prolog/problems/denotational_semantics/prog_8puzzle_3/common.py')
-rw-r--r--prolog/problems/denotational_semantics/prog_8puzzle_3/common.py39
1 files changed, 39 insertions, 0 deletions
diff --git a/prolog/problems/denotational_semantics/prog_8puzzle_3/common.py b/prolog/problems/denotational_semantics/prog_8puzzle_3/common.py
index 0e0d048..b88e544 100644
--- a/prolog/problems/denotational_semantics/prog_8puzzle_3/common.py
+++ b/prolog/problems/denotational_semantics/prog_8puzzle_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 = 173
number = 40
visible = True
@@ -34,3 +41,35 @@ instr173((R0,C0) --> (R,C)) -->
;
C0>6, C=C0, R=R0)}.
'''
+
+test_cases = [
+ ('findall(W, (W = [_], prog_8puzzle(_, W, [])), Words), Words == []',
+ [{}]),
+ ('prog_8puzzle([1,2,3,4,5,6,7,8,0]-->Out, [begin,down,right,left,end], []), Out == [1,2,3,4,5,6,7,0,8]',
+ [{}]),
+ ('prog_8puzzle([1,2,3,4,5,6,7,8,0]-->Out, [begin,up,up,left,left,end], []), Out == [0,1,2,4,5,3,7,8,6]',
+ [{}]),
+ ('prog_8puzzle([1,2,3,4,5,6,7,8,0]-->Out, [begin,left,up,right,up,left,down,down,right,end], []), \
+ Out == [1,6,2,4,5,3,7,8,0]',
+ [{}]),
+]
+
+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
+