summaryrefslogtreecommitdiff
path: root/prolog/problems/trees/membert_2
diff options
context:
space:
mode:
authorTimotej Lazar <timotej.lazar@fri.uni-lj.si>2016-04-11 00:10:57 +0200
committerTimotej Lazar <timotej.lazar@fri.uni-lj.si>2016-04-11 00:10:57 +0200
commitacce0e01cdb2a57cda35e040035dbf1da6b96031 (patch)
treee5a08e4a45893463e7bacfd82454a1a07fecba69 /prolog/problems/trees/membert_2
parent169c995732f3840aae6750479b49a4d0bcd4b198 (diff)
Prolog: add test cases for the trees group
Diffstat (limited to 'prolog/problems/trees/membert_2')
-rw-r--r--prolog/problems/trees/membert_2/common.py44
-rw-r--r--prolog/problems/trees/membert_2/en.py2
-rw-r--r--prolog/problems/trees/membert_2/sl.py13
3 files changed, 54 insertions, 5 deletions
diff --git a/prolog/problems/trees/membert_2/common.py b/prolog/problems/trees/membert_2/common.py
index 7d8f207..205487d 100644
--- a/prolog/problems/trees/membert_2/common.py
+++ b/prolog/problems/trees/membert_2/common.py
@@ -1,8 +1,13 @@
-# coding=utf-8
+from operator import itemgetter
+import socket
+
+import prolog.engine
+import prolog.util
+from server.hints import Hint, HintPopup
id = 142
-number = 49
-visible = False
+number = 80
+visible = True
facts = None
solution = '''\
@@ -17,3 +22,36 @@ memberT(X, Tree) :-
memb142(SubTree, SubTrees),
memberT(X, SubTree).
'''
+
+test_cases = [
+ ('setof(M, memberT(M, t(r)), X), X == [r]',
+ [{}]),
+ ('setof(M, memberT(M, t(3,t(2,t(3),t(6)),t(-1,t(0,t(8)),t(1)))), X), X == [-1,0,1,2,3,6,8]',
+ [{}]),
+ ('setof(M, memberT(M, t(r,t(a,t(c),t(d)),t(b,t(e),t(f)))), X), X == [a,b,c,d,e,f,r]',
+ [{}]),
+
+]
+
+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
+
+def hint(code, aux_code):
+ # TODO
+ return []
diff --git a/prolog/problems/trees/membert_2/en.py b/prolog/problems/trees/membert_2/en.py
index ef48931..11b74c1 100644
--- a/prolog/problems/trees/membert_2/en.py
+++ b/prolog/problems/trees/membert_2/en.py
@@ -1,5 +1,3 @@
-# coding=utf-8
-
name = 'memberT/2'
slug = 'find elements in a tree'
diff --git a/prolog/problems/trees/membert_2/sl.py b/prolog/problems/trees/membert_2/sl.py
new file mode 100644
index 0000000..5fee91e
--- /dev/null
+++ b/prolog/problems/trees/membert_2/sl.py
@@ -0,0 +1,13 @@
+name = 'memberT/2'
+slug = 'poišči element v drevesu'
+
+description = '''\
+<p><code>memberT(X, T)</code>: <code>X</code> je element drevesa <code>T</code>. Vozlišče drevesa je predstavljeno s strukturo <code>t(E, T1, T2, …)</code>, kjer je <code>E</code> vrednost v vozlišču, kateri sledi poljubno mnogo poddreves. Prazno drevo predstavlja atom <code>nil</code>.</p>
+<pre>
+?- memberT(X, t(3, t(1), t(2))).
+ X = 3 ;
+ X = 1 ;
+ X = 2.
+</pre>'''
+
+hint = {}