summaryrefslogtreecommitdiff
path: root/prolog/problems/license_plates
diff options
context:
space:
mode:
Diffstat (limited to 'prolog/problems/license_plates')
-rw-r--r--prolog/problems/license_plates/checklicenseplate_3/common.py44
-rw-r--r--prolog/problems/license_plates/firstminus_2/common.py36
-rw-r--r--prolog/problems/license_plates/genexp_2/common.py45
-rw-r--r--prolog/problems/license_plates/getdigits_2/common.py38
-rw-r--r--prolog/problems/license_plates/joindigits_2/common.py37
5 files changed, 200 insertions, 0 deletions
diff --git a/prolog/problems/license_plates/checklicenseplate_3/common.py b/prolog/problems/license_plates/checklicenseplate_3/common.py
index c37e210..0480258 100644
--- a/prolog/problems/license_plates/checklicenseplate_3/common.py
+++ b/prolog/problems/license_plates/checklicenseplate_3/common.py
@@ -1,5 +1,9 @@
# coding=utf-8
+from operator import itemgetter
+import prolog.engine
+import server.problems
+
id = 148
number = 55
visible = True
@@ -51,3 +55,43 @@ checkLicensePlate(LP, E1, E2) :-
genexp148(MN2, E2),
E1 =:= E2.
'''
+
+test_cases = [
+ ('''checkLicensePlate([l, j, l, 3, '-', 2, 4, 2], E1, E2)''',
+ [{'E1': '-3', 'E2': '(-2-4)/2'}, {'E1': '3', 'E2': '(2+4)/2'},
+ {'E1': '-3*2', 'E2': '-4-2'}, {'E1': '3*2', 'E2': '4+2'},
+ {'E1': '-3*2+4', 'E2': '-2'}, {'E1': '3*2-4', 'E2': '2'}]),
+ ('''checkLicensePlate([k, r, a, 3, '-', 2, 1, 7], E1, E2)''',
+ [{'E1': '-3', 'E2': '-21/7'}, {'E1': '3', 'E2': '21/7'},
+ {'E1': '-3*2', 'E2': '1-7'}, {'E1': '3*2', 'E2': '-1+7'},
+ {'E1': '3*2+1', 'E2': '7'}, {'E1': '-3*2-1', 'E2': '-7'}]),
+ ('''checkLicensePlate([g, o, c, 8, '-', 2, 1, 3], E1, E2)''',
+ [{'E1': '-8', 'E2': '-2*(1+3)'}, {'E1': '8', 'E2': '2*(1+3)'},
+ {'E1': '-8/2+1', 'E2': '-3'}, {'E1': '8/2-1', 'E2': '3'},
+ {'E1': '-8/2', 'E2': '-1-3'}, {'E1': '8/2', 'E2': '1+3'}]),
+]
+
+def test(program, solved_problems):
+ code = (program + '\n' +
+ server.problems.solutions_for_problems('prolog', solved_problems))
+
+ n_correct = 0
+ engine_id = None
+ try:
+ engine_id, output = prolog.engine.create(code=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
+ finally:
+ if engine_id:
+ prolog.engine.destroy(engine_id)
+
+ passed = n_correct == len(test_cases)
+ hints = [{'id': 'test_results', 'args': {'passed': n_correct, 'total': len(test_cases)}}]
+ return passed, hints
+
+def hint(program, solved_problems):
+ # TODO
+ return []
diff --git a/prolog/problems/license_plates/firstminus_2/common.py b/prolog/problems/license_plates/firstminus_2/common.py
index 20376d2..89fe3b0 100644
--- a/prolog/problems/license_plates/firstminus_2/common.py
+++ b/prolog/problems/license_plates/firstminus_2/common.py
@@ -1,5 +1,9 @@
# coding=utf-8
+from operator import itemgetter
+import prolog.engine
+import server.problems
+
id = 147
number = 54
visible = True
@@ -10,3 +14,35 @@ firstMinus(L, L).
firstMinus([X|T], [Y|T]) :-
Y is -X.
'''
+
+test_cases = [
+ ('firstMinus([2, 3, 4], X)',
+ [{'X': '[2, 3, 4]'}, {'X': '[-2, 3, 4]'}]),
+ ('firstMinus([5, 2, 3, 4], X)',
+ [{'X': '[5, 2, 3, 4]'}, {'X': '[-5, 2, 3, 4]'}]),
+]
+
+def test(program, solved_problems):
+ code = (program + '\n' +
+ server.problems.solutions_for_problems('prolog', solved_problems))
+
+ n_correct = 0
+ engine_id = None
+ try:
+ engine_id, output = prolog.engine.create(code=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
+ finally:
+ if engine_id:
+ prolog.engine.destroy(engine_id)
+
+ passed = n_correct == len(test_cases)
+ hints = [{'id': 'test_results', 'args': {'passed': n_correct, 'total': len(test_cases)}}]
+ return passed, hints
+
+def hint(program, solved_problems):
+ # TODO
+ return []
diff --git a/prolog/problems/license_plates/genexp_2/common.py b/prolog/problems/license_plates/genexp_2/common.py
index ecdc772..4b097f2 100644
--- a/prolog/problems/license_plates/genexp_2/common.py
+++ b/prolog/problems/license_plates/genexp_2/common.py
@@ -1,5 +1,9 @@
# coding=utf-8
+from operator import itemgetter
+import prolog.engine
+import server.problems
+
id = 146
number = 53
visible = True
@@ -22,3 +26,44 @@ genexp(L, Exp) :-
conc146(Before, [NExp|After], L1),
genexp(L1, Exp).
'''
+
+test_cases = [
+ ('genexp([1], X)',
+ [{'X': '1'}]),
+ ('genexp([1, 2], X)',
+ [{'X': '1*2'}, {'X': '1+2'}, {'X': '1-2'}, {'X': '1/2'}]),
+ ('genexp([1, 2, 3], X)',
+ [{'X': '1+2+3'}, {'X': '1+2-3'}, {'X': '(1+2)*3'}, {'X': '(1+2)/3'},
+ {'X': '1-2+3'}, {'X': '1-2-3'}, {'X': '(1-2)*3'}, {'X': '(1-2)/3'},
+ {'X': '1*2+3'}, {'X': '1*2-3'}, {'X': '1*2*3'}, {'X': '1*2/3'},
+ {'X': '1/2+3'}, {'X': '1/2-3'}, {'X': '1/2*3'}, {'X': '1/2/3'},
+ {'X': '1+(2+3)'}, {'X': '1-(2+3)'}, {'X': '1*(2+3)'}, {'X': '1/(2+3)'},
+ {'X': '1+(2-3)'}, {'X': '1-(2-3)'}, {'X': '1*(2-3)'}, {'X': '1/(2-3)'},
+ {'X': '1+2*3'}, {'X': '1-2*3'}, {'X': '1*(2*3)'}, {'X': '1/(2*3)'},
+ {'X': '1+2/3'}, {'X': '1-2/3'}, {'X': '1*(2/3)'}, {'X': '1/(2/3)'}]),
+]
+
+def test(program, solved_problems):
+ code = (program + '\n' +
+ server.problems.solutions_for_problems('prolog', solved_problems))
+
+ n_correct = 0
+ engine_id = None
+ try:
+ engine_id, output = prolog.engine.create(code=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
+ finally:
+ if engine_id:
+ prolog.engine.destroy(engine_id)
+
+ passed = n_correct == len(test_cases)
+ hints = [{'id': 'test_results', 'args': {'passed': n_correct, 'total': len(test_cases)}}]
+ return passed, hints
+
+def hint(program, solved_problems):
+ # TODO
+ return []
diff --git a/prolog/problems/license_plates/getdigits_2/common.py b/prolog/problems/license_plates/getdigits_2/common.py
index 82fe033..4ae42ff 100644
--- a/prolog/problems/license_plates/getdigits_2/common.py
+++ b/prolog/problems/license_plates/getdigits_2/common.py
@@ -1,5 +1,9 @@
# coding=utf-8
+from operator import itemgetter
+import prolog.engine
+import server.problems
+
id = 144
number = 51
visible = True
@@ -13,3 +17,37 @@ getdigits([X|T], [X|NT]) :-
getdigits([_|T], NT) :-
getdigits(T, NT).
'''
+
+test_cases = [
+ ('getdigits([], X)',
+ [{'X': '[]'}]),
+ ('''getdigits([1, [], 2, a, b, -3, '+', 4], X)''',
+ [{'X': '[1, 2, -3, 4]'}]),
+ ('''getdigits([l, j, k, 3, '-', 2, 4, 2], X)''',
+ [{'X': '[3, 2, 4, 2]'}]),
+]
+
+def test(program, solved_problems):
+ code = (program + '\n' +
+ server.problems.solutions_for_problems('prolog', solved_problems))
+
+ n_correct = 0
+ engine_id = None
+ try:
+ engine_id, output = prolog.engine.create(code=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
+ finally:
+ if engine_id:
+ prolog.engine.destroy(engine_id)
+
+ passed = n_correct == len(test_cases)
+ hints = [{'id': 'test_results', 'args': {'passed': n_correct, 'total': len(test_cases)}}]
+ return passed, hints
+
+def hint(program, solved_problems):
+ # TODO
+ return []
diff --git a/prolog/problems/license_plates/joindigits_2/common.py b/prolog/problems/license_plates/joindigits_2/common.py
index 9ebc037..189f221 100644
--- a/prolog/problems/license_plates/joindigits_2/common.py
+++ b/prolog/problems/license_plates/joindigits_2/common.py
@@ -1,5 +1,9 @@
# coding=utf-8
+from operator import itemgetter
+import prolog.engine
+import server.problems
+
id = 145
number = 52
visible = True
@@ -13,3 +17,36 @@ joindigits([X,Y|T], NT) :-
joindigits([X,Y|T], [X|NT]) :-
joindigits([Y|T], NT).
'''
+
+test_cases = [
+ ('joindigits([2, 3, 1, 4], X)',
+ [{'X': '[2, 3, 1, 4]'}, {'X': '[2, 3, 14]'}, {'X': '[2, 31, 4]'}, {'X': '[2, 314]'},
+ {'X': '[23, 1, 4]'}, {'X': '[23, 14]'}, {'X': '[231, 4]'}, {'X': '[2314]'}]),
+ ('joindigits([2, 3, 1], X)',
+ [{'X': '[2, 3, 1]'}, {'X': '[2, 31]'}, {'X': '[23, 1]'}, {'X': '[231]'}]),
+]
+
+def test(program, solved_problems):
+ code = (program + '\n' +
+ server.problems.solutions_for_problems('prolog', solved_problems))
+
+ n_correct = 0
+ engine_id = None
+ try:
+ engine_id, output = prolog.engine.create(code=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
+ finally:
+ if engine_id:
+ prolog.engine.destroy(engine_id)
+
+ passed = n_correct == len(test_cases)
+ hints = [{'id': 'test_results', 'args': {'passed': n_correct, 'total': len(test_cases)}}]
+ return passed, hints
+
+def hint(program, solved_problems):
+ # TODO
+ return []