diff options
author | Aleksander Sadikov <aleksander.sadikov@fri.uni-lj.si> | 2016-04-24 19:20:18 +0200 |
---|---|---|
committer | Aleksander Sadikov <aleksander.sadikov@fri.uni-lj.si> | 2016-04-24 19:20:18 +0200 |
commit | dfc05ee597e68abc4a80d4cc2fc1bcf109c4f35d (patch) | |
tree | af851c75b2e5bd1d9d7cd05cfe5cf3458ad2aee6 /prolog/problems/clp_r/linear_opt_3 | |
parent | 30fdf4dde068db5774c8872a919d4500ed0485b4 (diff) |
Tests added for linear_opt exercise.
Diffstat (limited to 'prolog/problems/clp_r/linear_opt_3')
-rw-r--r-- | prolog/problems/clp_r/linear_opt_3/common.py | 28 |
1 files changed, 27 insertions, 1 deletions
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 |