Skip to content

Commit

Permalink
TST: Fixup tests
Browse files Browse the repository at this point in the history
  • Loading branch information
HaoZeke committed Oct 1, 2023
1 parent 8f3d57a commit 68b5bdf
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 22 deletions.
21 changes: 10 additions & 11 deletions scipy/optimize/tests/test_linprog.py
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ def test_highs_status_message():
msg = "Optimization terminated successfully."
assert res.status == 0
assert res.message.startswith(msg)
assert 'HiGHS Status 7' in res.message
assert 'HighsModelStatus.kOptimal' in res.message

A, b, c, numbers, M = magic_square(6)
bounds = [(0, 1)] * len(c)
Expand All @@ -318,35 +318,34 @@ def test_highs_status_message():
msg = "Time limit reached"
assert res.status == 1
assert msg in res.message
assert 'HiGHS Status 13' in res.message
assert 'HighsModelStatus.kTimeLimit' in res.message

options = {"maxiter": 10}
res = linprog(c=c, A_eq=A, b_eq=b, bounds=bounds, method='highs-ds',
options=options)
msg = "Iteration limit reached"
assert res.status == 1
assert res.message.startswith(msg)
assert 'HiGHS Status 14' in res.message
assert 'HighsModelStatus.kIterationLimit' in res.message

res = linprog(1, bounds=(1, -1), method='highs')
msg = "The problem is infeasible"
assert res.status == 2
assert res.message.startswith(msg)
assert 'HiGHS Status 8' in res.message
assert 'HighsModelStatus.kInfeasible' in res.message

# TODO: Fix this
# res = linprog(-1, method='highs')
# msg = "The problem is unbounded."
# assert res.status == 3
# assert res.message.startswith(msg)
# assert 'HiGHS Status 10' in res.message
res = linprog(-1, method='highs')
msg = "The problem is unbounded."
assert res.status == 3
assert res.message.startswith(msg)
assert 'HighsModelStatus.kUnbounded' in res.message

from scipy.optimize._linprog_highs import HighsStatusMapping
highs_mapper = HighsStatusMapping()
status, message = highs_mapper.get_scipy_status(58, "Hello!")
# msg = "The HiGHS status code was not recognized. (HiGHS Status 58:"
assert status == 4
# TODO: Fix this
# msg = "The HiGHS status code was not recognized. (HiGHS Status 58:"
# assert message.startswith(msg)
assert "HiGHS Status 58" in message

Expand Down
22 changes: 11 additions & 11 deletions scipy/optimize/tests/test_milp.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ def test_result():
assert res.success
msg = "Optimization terminated successfully."
assert res.message.startswith(msg)
assert 'HiGHS Status 7' in res.message
assert 'HighsModelStatus.kOptimal' in res.message
assert isinstance(res.x, np.ndarray)
assert isinstance(res.fun, float)
assert isinstance(res.mip_node_count, int)
Expand All @@ -112,7 +112,7 @@ def test_result():
assert res.status == 1
assert not res.success
msg = "Time limit reached"
assert 'HiGHS Status 13' in res.message
assert 'HighsModelStatus.kTimeLimit' in res.message
assert msg in res.message
assert (res.fun is res.mip_dual_bound is res.mip_gap
is res.mip_node_count is res.x is None)
Expand All @@ -121,19 +121,19 @@ def test_result():
assert res.status == 2
assert not res.success
msg = "The problem is infeasible"
assert 'HiGHS Status 8' in res.message
assert 'HighsModelStatus.kInfeasible' in res.message
assert res.message.startswith(msg)
assert (res.fun is res.mip_dual_bound is res.mip_gap
is res.mip_node_count is res.x is None)

# TODO: Fix this
# res = milp(-1)
# assert res.status == 3
# assert not res.success
# msg = "The problem is unbounded. (HiGHS Status 10:"
# assert res.message.startswith(msg)
# assert (res.fun is res.mip_dual_bound is res.mip_gap
# is res.mip_node_count is res.x is None)
res = milp(-1)
assert res.status == 3
assert not res.success
assert 'HighsModelStatus.kUnbounded' in res.message
msg = "The problem is unbounded."
assert res.message.startswith(msg)
assert (res.fun is res.mip_dual_bound is res.mip_gap
is res.mip_node_count is res.x is None)


def test_milp_optional_args():
Expand Down

0 comments on commit 68b5bdf

Please sign in to comment.