Skip to content

Commit

Permalink
add unit test for maximization
Browse files Browse the repository at this point in the history
  • Loading branch information
hitonanode committed Apr 24, 2024
1 parent 6d7d3e7 commit 3d0048b
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions test/test_maximize.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import pytest

from modeler import LPModel, LPSense, LPStatus, LPVar


def test_maximize() -> None:
x = LPVar("x", lower_bound=1, upper_bound=2)

model = LPModel(sense=LPSense.MAXIMIZE)

model.set_objective(x + 1.0)

model.solve()

assert model.status == LPStatus.OPTIMAL

assert x.value() == pytest.approx(2.0)
assert model.objective.value() == pytest.approx(3.0)


def test_maximize_const_no_variable() -> None:
model = LPModel(sense=LPSense.MAXIMIZE)

model.set_objective(-2.0)

model.solve()

assert model.status == LPStatus.OPTIMAL

assert model.objective.value() == pytest.approx(-2.0)

0 comments on commit 3d0048b

Please sign in to comment.