Skip to content
Closed
Show file tree
Hide file tree
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
3 changes: 2 additions & 1 deletion src/functions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion test/Bridges/Variable/zeros.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
"""
Expand Down
14 changes: 14 additions & 0 deletions test/functions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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()
Expand All @@ -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()
Expand Down Expand Up @@ -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()
Expand Down