From dfc05ee597e68abc4a80d4cc2fc1bcf109c4f35d Mon Sep 17 00:00:00 2001 From: Aleksander Sadikov Date: Sun, 24 Apr 2016 19:20:18 +0200 Subject: Tests added for linear_opt exercise. --- prolog/problems/clp_r/linear_opt_3/common.py | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/prolog/problems/clp_r/linear_opt_3/common.py b/prolog/problems/clp_r/linear_opt_3/common.py index cf2dd5e..43b3b08 100644 --- a/prolog/problems/clp_r/linear_opt_3/common.py +++ b/prolog/problems/clp_r/linear_opt_3/common.py @@ -2,7 +2,7 @@ id = 159 number = 63 -visible = False +visible = True facts = None solution = '''\ @@ -11,3 +11,29 @@ linear_opt(X, Y, MaxE) :- X+Y =< 7, X+2*Y >= 4, Y =< X+5, MaxE = -0.4*X+3.2*Y }, maximize(MaxE).''' + +test_cases = [ + ('linear_opt(X, Y, MaxE), abs(X - 1.0) =< 1e-8, abs(Y - 6.0) =< 1e-8, abs(MaxE - 18.8) =< 1e-8', + [{}]), + ('setof(X/Y/MaxE, linear_opt(X, Y, MaxE), L), L = [X/Y/MaxE], abs(X - 1.0) =< 1e-8, abs(Y - 6.0) =< 1e-8, abs(MaxE - 18.8) =< 1e-8', + [{}]), +] + +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 -- cgit v1.2.1