Skip to content

Commit f1433c7

Browse files
committed
Add test for scalar * Expr multiplication
Add an assertion in tests/test_expr.py to verify left-side scalar multiplication works: assert str(2.0 * (x + y)) == "Expr({Term(x): 2.0, Term(y): 2.0})". This ensures that multiplying an Expr by a scalar on the left yields the same result and string representation as Expr * scalar.
1 parent e2612b5 commit f1433c7

2 files changed

Lines changed: 2 additions & 1 deletion

File tree

src/pyscipopt/expr.pxi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,7 @@ cdef class Expr:
296296
while PyDict_Next(self.terms, &pos1, &k1_ptr, &v1_ptr):
297297
res[<Term>k1_ptr] = <double>(<object>v1_ptr) * coef
298298
return Expr(res)
299-
299+
300300
elif isinstance(other, Expr):
301301
while PyDict_Next(self.terms, &pos1, &k1_ptr, &v1_ptr):
302302
pos2 = <Py_ssize_t>0

tests/test_expr.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,7 @@ def test_mul():
226226

227227
# test Expr * number
228228
assert str((x + y) * 2.0) == "Expr({Term(x): 2.0, Term(y): 2.0})"
229+
assert str(2.0 * (x + y)) == "Expr({Term(x): 2.0, Term(y): 2.0})"
229230

230231
# test Expr * Expr
231232
assert str(Expr({CONST: 1.0}) * x) == "Expr({Term(x): 1.0})"

0 commit comments

Comments
 (0)