Skip to content

Commit 3f21373

Browse files
odowblegat
andauthored
Fix comparison of ScalarFunctionConstantNotZero (#2190)
Co-authored-by: Benoît Legat <[email protected]>
1 parent a93d14d commit 3f21373

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

src/constraints.jl

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,13 @@ struct ScalarFunctionConstantNotZero{T,F,S} <: Exception
7373
constant::T
7474
end
7575

76+
function Base.:(==)(
77+
x::ScalarFunctionConstantNotZero{T,F,S},
78+
y::ScalarFunctionConstantNotZero{T,F,S},
79+
) where {T,F,S}
80+
return x.constant == y.constant
81+
end
82+
7683
function Base.showerror(
7784
io::IO,
7885
err::ScalarFunctionConstantNotZero{T,F,S},

test/errors.jl

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -352,6 +352,20 @@ function test_unsupported_nonlinear_operator()
352352
return
353353
end
354354

355+
function test_ScalarFunctionConstantNotZero_equality()
356+
for T in (Int, Float64, BigFloat)
357+
F, S = MOI.ScalarAffineFunction{T}, MOI.EqualTo{T}
358+
w = MOI.ScalarFunctionConstantNotZero{T,F,MOI.LessThan{T}}(zero(T))
359+
x = MOI.ScalarFunctionConstantNotZero{T,F,S}(zero(T))
360+
y = MOI.ScalarFunctionConstantNotZero{T,F,S}(zero(T))
361+
z = MOI.ScalarFunctionConstantNotZero{T,F,S}(one(T))
362+
@test x == y
363+
@test x != z
364+
@test w != x
365+
end
366+
return
367+
end
368+
355369
function runtests()
356370
for name in names(@__MODULE__; all = true)
357371
if startswith("$name", "test_")

0 commit comments

Comments
 (0)