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

[Test] improve test_attribute_TimeLimitSec #2256

Merged
merged 1 commit into from
Sep 28, 2023
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
15 changes: 12 additions & 3 deletions src/Test/test_attribute.jl
Original file line number Diff line number Diff line change
Expand Up @@ -168,15 +168,24 @@ Test that the [`MOI.TimeLimitSec`](@ref) attribute is implemented for `model`.
"""
function test_attribute_TimeLimitSec(model::MOI.AbstractOptimizer, ::Config)
@requires MOI.supports(model, MOI.TimeLimitSec())
function _get_default(model)
try
return MOI.get(model, MOI.TimeLimitSec())
catch err
@assert err isa MOI.GetAttributeNotAllowed(MOI.TimeLimitSec())
end
return
end
# Get the current value to restore it at the end of the test
value = MOI.get(model, MOI.TimeLimitSec())
value = _get_default(model)
MOI.set(model, MOI.TimeLimitSec(), 0.0)
@test MOI.get(model, MOI.TimeLimitSec()) == 0.0
_test_attribute_value_type(model, MOI.TimeLimitSec())
MOI.set(model, MOI.TimeLimitSec(), 1.0)
@test MOI.get(model, MOI.TimeLimitSec()) == 1.0
MOI.set(model, MOI.TimeLimitSec(), nothing)
@test _get_default(model) === nothing
MOI.set(model, MOI.TimeLimitSec(), value)
@test value == MOI.get(model, MOI.TimeLimitSec()) # Equality should hold
_test_attribute_value_type(model, MOI.TimeLimitSec())
return
end
test_attribute_TimeLimitSec(::MOI.ModelLike, ::Config) = nothing
Expand Down