Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/lemke/bimatrix.py
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,7 @@ def runLH(self, droppedlabel):
# tabl.runlemke(verbose=True, lexstats=True, z0=gz0)

result = lemke.runlemke(lcp=lcp)
if result is None:
if not result.success:
raise RuntimeError("runlemke() failed to find a solution unexpectedly.")

equilibrium = result.z[:-2]
Expand Down Expand Up @@ -418,7 +418,7 @@ def runtrace(self, xprior, yprior):
lcp.d = np.hstack((Ay, xB, [1, 1]))

result = lemke.runlemke(lcp=lcp)
if result is None:
if not result.success:
raise RuntimeError("runlemke() failed to find a solution unexpectedly.")

equilibrium = result.z[:-2]
Expand Down
34 changes: 34 additions & 0 deletions tests/test_bimatrix_units.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import re
import textwrap
from fractions import Fraction

Expand All @@ -15,6 +16,7 @@
trace_uniform_cmd,
uniform,
)
from lemke.lemke import LcpResult
from lemke.randomstart import MAX_ACCURACY
from lemke.utils import MAXDECIMALS

Expand Down Expand Up @@ -185,6 +187,38 @@ def test_rejects_non_positive_num_priors(small_game_file, bad_priors):
G.trace_random_priors(bad_priors)


# --- RUNLEMKE FAILURE -------------------------------------------------
@pytest.fixture
def lemke_failure(monkeypatch):
failed_result = LcpResult(
success=False,
num_pivots=0,
basis=frozenset(),
z0=Fraction(-1),
z=(),
w=(),
ray_entering_variable=None,
)
monkeypatch.setattr(
"lemke.lemke.runlemke",
lambda **kwargs: failed_result,
)


def test_runLH_throws_on_lemke_failure(lemke_failure, small_game_file):
G = bimatrix.from_file(small_game_file)

with pytest.raises(RuntimeError, match=re.escape("runlemke() failed")):
G.runLH(1)


def test_runtrace_throws_on_lemke_failure(lemke_failure, small_game_file):
G = bimatrix.from_file(small_game_file)

with pytest.raises(RuntimeError, match=re.escape("runlemke() failed")):
G.runtrace([0.5, 0.5], [0.4, 0.6])


# --- HELPER FUNCTIONS --------------------------------------------------------
@pytest.mark.parametrize(
"input, expected",
Expand Down
Loading