diff --git a/src/functions.jl b/src/functions.jl index a74121a2ab..383a8d195e 100644 --- a/src/functions.jl +++ b/src/functions.jl @@ -303,7 +303,8 @@ end # For affine and quadratic functions, terms are compressed in a dictionary using `_dicts` and then the dictionaries are compared with `dict_compare` function dict_compare(d1::Dict, d2::Dict{<:Any,T}, compare::Function) where {T} - return all(kv -> compare(kv.second, Base.get(d2, kv.first, zero(T))), d1) + return all(kv -> compare(kv.second, Base.get(d2, kv.first, zero(T))), d1) && + all(kv -> compare(kv.second, Base.get(d1, kv.first, zero(T))), d2) end # Build a dictionary where the duplicate keys are summed diff --git a/test/Bridges/Variable/zeros.jl b/test/Bridges/Variable/zeros.jl index 66f1ae26f5..1d111cbba5 100644 --- a/test/Bridges/Variable/zeros.jl +++ b/test/Bridges/Variable/zeros.jl @@ -149,7 +149,7 @@ end s = """ variables: x x >= 0.0 - con1: x + 0.0 == 0.0 + con1: 0.0 == 0.0 con2: x + 0.0 >= 1.0 minobjective: x """ diff --git a/test/functions.jl b/test/functions.jl index fbe5c46ccd..2bf2d73af5 100644 --- a/test/functions.jl +++ b/test/functions.jl @@ -139,6 +139,9 @@ function test_isapprox_ScalarAffineFunction() @test g ≈ f f.terms[2] = MOI.ScalarAffineTerm(3, y) @test !(g ≈ f) + pop!(f.terms) + @test !(g ≈ f) + @test !(f ≈ g) end function test_isapprox_VectorAffineFunction() @@ -157,6 +160,9 @@ function test_isapprox_VectorAffineFunction() @test !(f ≈ g) push!(f.terms, MOI.VectorAffineTerm(2, MOI.ScalarAffineTerm(-6, y))) @test f ≈ g + pop!(g.terms) + @test !(g ≈ f) + @test !(f ≈ g) end function test_isapprox_ScalarQuadraticFunction() @@ -177,6 +183,9 @@ function test_isapprox_ScalarQuadraticFunction() @test !(f ≈ g) push!(f.quadratic_terms, MOI.ScalarQuadraticTerm(-2, y, x)) @test f ≈ g + pop!(g.quadratic_terms) + @test !(g ≈ f) + @test !(f ≈ g) end function test_isapprox_VectorQuadraticFunction() @@ -204,6 +213,11 @@ function test_isapprox_VectorQuadraticFunction() f.quadratic_terms[1] = MOI.VectorQuadraticTerm(3, MOI.ScalarQuadraticTerm(1, x, x)) @test !(f ≈ g) + f.quadratic_terms[1] = + MOI.VectorQuadraticTerm(1, MOI.ScalarQuadraticTerm(1, x, x)) + pop!(f.quadratic_terms) + @test !(g ≈ f) + @test !(f ≈ g) end function runtests()