summaryrefslogtreecommitdiff
path: root/prolog/problems/lists/last_elem_2/common.py
diff options
context:
space:
mode:
Diffstat (limited to 'prolog/problems/lists/last_elem_2/common.py')
-rw-r--r--prolog/problems/lists/last_elem_2/common.py46
1 files changed, 46 insertions, 0 deletions
diff --git a/prolog/problems/lists/last_elem_2/common.py b/prolog/problems/lists/last_elem_2/common.py
new file mode 100644
index 0000000..b18243d
--- /dev/null
+++ b/prolog/problems/lists/last_elem_2/common.py
@@ -0,0 +1,46 @@
+from operator import itemgetter
+import prolog.engine
+import prolog.util
+import socket
+from server.hints import Hint, HintPopup
+import server.problems
+
+id = 10000
+number = 2
+visible = True
+facts = None
+
+solution = '''\
+'''
+
+hint_type = {
+}
+
+test_cases = [
+ ('last_elem([X], c)',
+ [{'X': 'c'}]),
+ ('last_elem([y, l, r, g, a], X)',
+ [{'X': 'a'}]),
+]
+
+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):
+ return []