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

Promote bound of Interval if they have different types #2577

Merged
merged 5 commits into from
Nov 3, 2024
Merged
Show file tree
Hide file tree
Changes from 4 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
12 changes: 12 additions & 0 deletions src/sets.jl
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,10 @@ struct Interval{T<:Real} <: AbstractScalarSet
upper::T
end

function Interval(lower::Real, upper::Real)
return Interval(promote(lower, upper)...)
end

function Base.:(==)(a::Interval{T}, b::Interval{T}) where {T}
return a.lower == b.lower && a.upper == b.upper
end
Expand Down Expand Up @@ -390,6 +394,10 @@ struct Semicontinuous{T<:Real} <: AbstractScalarSet
upper::T
end

function Semicontinuous(lower::Real, upper::Real)
return Semicontinuous(promote(lower, upper)...)
end

function Base.:(==)(a::Semicontinuous{T}, b::Semicontinuous{T}) where {T}
return a.lower == b.lower && a.upper == b.upper
end
Expand Down Expand Up @@ -422,6 +430,10 @@ struct Semiinteger{T<:Real} <: AbstractScalarSet
upper::T
end

function Semiinteger(lower::Real, upper::Real)
return Semiinteger(promote(lower, upper)...)
end

function Base.:(==)(a::Semiinteger{T}, b::Semiinteger{T}) where {T}
return a.lower == b.lower && a.upper == b.upper
end
Expand Down
13 changes: 13 additions & 0 deletions test/sets.jl
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,19 @@ function runtests()
end
end

function test_interval_promote()
for S in [MOI.Interval, MOI.Semiinteger, MOI.Semicontinuous]
odow marked this conversation as resolved.
Show resolved Hide resolved
set = S(1.0, π)
@test set isa S{Float64}
@test set.lower == 1.0
@test set.upper ≈ π
set = S(big(1), 2)
@test set isa S{BigInt}
@test set.lower == 1
@test set.upper == 2
end
odow marked this conversation as resolved.
Show resolved Hide resolved
end

end

TestSets.runtests()
Loading