diff options
-rw-r--r-- | prolog/problems/clp_fd/tobase_3/common.py | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/prolog/problems/clp_fd/tobase_3/common.py b/prolog/problems/clp_fd/tobase_3/common.py index 5d160d7..5e3a783 100644 --- a/prolog/problems/clp_fd/tobase_3/common.py +++ b/prolog/problems/clp_fd/tobase_3/common.py @@ -1,5 +1,9 @@ # coding=utf-8 +from operator import itemgetter +import prolog.engine +import server.problems + id = 150 number = 62 visible = True @@ -14,3 +18,45 @@ tobase(N, B, Nb) :- Rem #>= 0, Rem #< B, Nb #= Nb1 * 10 + Rem, tobase(N1, B, Nb1).''' + +test_cases = [ + ('tobase(214, 2, X)', + [{'X': '11010110'}]), + ('tobase(321, 7, X)', + [{'X': '636'}]), + ('tobase(X, 8, 777)', + [{'X': '511'}]), + ('tobase(X, 8, 132)', + [{'X': '90'}]), + ('tobase(653, X, 10103)', + [{'X': '5'}]), + ('tobase(123, X, 146)', + [{'X': '9'}]), + ('setof(B/N, tobase(123, B, N), X)', + [{'X': '[2/1111011, 3/11120, 4/1323, 5/443, 6/323, 7/234, 8/173, 9/146, 10/123]'}]), +] + +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 [] |