Skip to content

Commit

Permalink
Add tests for issue #3736 (#3737)
Browse files Browse the repository at this point in the history
  • Loading branch information
odow authored Apr 25, 2024
1 parent 509ab61 commit 90fcfd0
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions test/test_expr.jl
Original file line number Diff line number Diff line change
Expand Up @@ -519,4 +519,37 @@ function test_aff_expr_complex_HermitianPSDCone()
return
end

function test_multiply_expr_MA_Zero()
model = Model()
@variable(model, x)
for f in (x, x^2, sin(x))
@test @expression(model, f * sum(x for i in 1:0)) == 0.0
@test @expression(model, sum(x for i in 1:0) * f) == 0.0
@test @expression(model, -f * sum(x for i in 1:0)) == 0.0
@test @expression(model, sum(x for i in 1:0) * -f) == 0.0
@test @expression(model, (f + f) * sum(x for i in 1:0)) == 0.0
@test @expression(model, sum(x for i in 1:0) * (f + f)) == 0.0

@test isequal_canonical(@expression(model, f + sum(x for i in 1:0)), f)
@test isequal_canonical(@expression(model, sum(x for i in 1:0) + f), f)
@test isequal_canonical(
@expression(model, -f + sum(x for i in 1:0)),
-1.0 * f, # Needed for f = sin(x)
)
@test isequal_canonical(
@expression(model, sum(x for i in 1:0) + -f),
-1.0 * f, # Needed for f = sin(x)
)
@test isequal_canonical(
@expression(model, (f + f) + sum(x for i in 1:0)),
f + f,
)
@test isequal_canonical(
@expression(model, sum(x for i in 1:0) + (f + f)),
f + f,
)
end
return
end

end # TestExpr

0 comments on commit 90fcfd0

Please sign in to comment.