Skip to content

Commit 766759b

Browse files
committed
Update expr tests for MatrixExpr and repr
Add MatrixExpr import and adjust unary-expression tests to match symbolic representations and matrix behavior. Replace numeric equality checks with string-based assertions for sqrt/exp/log/sin/cos, add a log([1,x]) repr check, and add isinstance checks for GenExpr and MatrixExpr to verify scalar vs. matrix expression types and nested/matrix shapes.
1 parent cce6c92 commit 766759b

1 file changed

Lines changed: 19 additions & 11 deletions

File tree

tests/test_expr.py

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import numpy as np
44
import pytest
55

6-
from pyscipopt import Model, cos, exp, log, sin, sqrt
6+
from pyscipopt import MatrixExpr, Model, cos, exp, log, sin, sqrt
77
from pyscipopt.scip import CONST, Expr, ExprCons, GenExpr
88

99

@@ -249,16 +249,24 @@ def test_unary(model):
249249
assert str(log([x, y])) == res
250250
assert str(np.log([x, y])) == res
251251

252-
assert sqrt(4) == np.sqrt(4)
253-
assert all(sqrt([4, 4]) == np.sqrt([4, 4]))
254-
assert exp(3) == np.exp(3)
255-
assert all(exp([3, 3]) == np.exp([3, 3]))
256-
assert log(5) == np.log(5)
257-
assert all(log([5, 5]) == np.log([5, 5]))
258-
assert sin(1) == np.sin(1)
259-
assert all(sin([1, 1]) == np.sin([1, 1]))
260-
assert cos(1) == np.cos(1)
261-
assert all(cos([1, 1]) == np.cos([1, 1]))
252+
assert str(log([1, x])) == "[log(1.0) log(sum(0.0,prod(1.0,x)))]"
253+
254+
assert str(sqrt(4)) == "sqrt(4.0)"
255+
assert str(sqrt([4, 4])) == "[sqrt(4.0) sqrt(4.0)]"
256+
assert str(exp(3)) == "exp(3.0)"
257+
assert str(exp([3, 3])) == "[exp(3.0) exp(3.0)]"
258+
assert str(log(5)) == "log(5.0)"
259+
assert str(log([5, 5])) == "[log(5.0) log(5.0)]"
260+
assert str(sin(1)) == "sin(1.0)"
261+
assert str(sin([[1, 1]])) == "[[sin(1.0) sin(1.0)]]"
262+
assert str(cos(1)) == "cos(1.0)"
263+
assert str(cos([[1]])) == "[[cos(1.0)]]"
264+
265+
assert isinstance(sqrt(2), GenExpr)
266+
assert isinstance(sqrt([2, 2]), MatrixExpr)
267+
assert isinstance(sqrt([[2], [2]]), MatrixExpr)
268+
assert isinstance(sqrt([2, x]), MatrixExpr)
269+
assert isinstance(sqrt([[2], [x]]), MatrixExpr)
262270

263271
# test invalid unary operations
264272
with pytest.raises(TypeError):

0 commit comments

Comments
 (0)