Skip to content

Commit

Permalink
More operator overloading test
Browse files Browse the repository at this point in the history
  • Loading branch information
metab0t committed Feb 11, 2024
1 parent 8057a96 commit 475f2e4
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions tests/test_basic.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import pyoptinterface as poi
import numpy as np
from pytest import approx

from pyoptinterface._src.core_ext import IntMonotoneIndexer

Expand Down Expand Up @@ -27,6 +28,22 @@ def test_basic():
assert list(saf.variables) == [0, 1, 2, 3]
assert np.allclose(saf.coefficients, [1.0, 2.0, 3.0, -4.0])

saf = 2.0 - 1.0 * saf * -4.0 / 2.0 + 1.0
saf.canonicalize()
assert list(saf.variables) == [0, 1, 2, 3]
assert np.allclose(saf.coefficients, [2.0, 4.0, 6.0, -8.0])
assert saf.constant == approx(3.0)

sqf = v * v + 2.0 * v + 1.0
sqf = 2.0 - 1.0 * sqf * -4.0 / 2.0 + 1.0
sqf.canonicalize()
assert list(sqf.variable_1s) == [0]
assert list(sqf.variable_2s) == [0]
assert np.allclose(sqf.coefficients, [2.0])
assert list(sqf.affine_part.variables) == [0]
assert np.allclose(sqf.affine_part.coefficients, [4.0])
assert sqf.affine_part.constant == approx(5.0)


def test_monotoneindexer():
indexer = IntMonotoneIndexer()
Expand Down

0 comments on commit 475f2e4

Please sign in to comment.