Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add tests for issue #3736 #3737

Merged
merged 5 commits into from
Apr 25, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading