Skip to content

Commit

Permalink
[Test] improve test_attribute_TimeLimitSec (#2256)
Browse files Browse the repository at this point in the history
  • Loading branch information
odow authored Sep 28, 2023
1 parent 2605000 commit 44018e8
Showing 1 changed file with 12 additions and 3 deletions.
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

0 comments on commit 44018e8

Please sign in to comment.