Skip to content

Commit 657ea54

Browse files
authored
Improve test coverage (#90)
1 parent 47840c7 commit 657ea54

File tree

6 files changed

+55
-4
lines changed

6 files changed

+55
-4
lines changed

src/algorithms/Chalmet.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ Research. 25(2), 292-300
1717
* `MOI.TimeLimitSec()`: terminate if the time limit is exceeded and return the
1818
list of current solutions.
1919
"""
20-
mutable struct Chalmet <: AbstractAlgorithm end
20+
struct Chalmet <: AbstractAlgorithm end
2121

2222
function _solve_constrained_model(
2323
model::Optimizer,

src/algorithms/DominguezRios.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ Sciences, 565(7), 210-228.
1717
* `MOI.TimeLimitSec()`: terminate if the time limit is exceeded and return the
1818
list of current solutions.
1919
"""
20-
mutable struct DominguezRios <: AbstractAlgorithm end
20+
struct DominguezRios <: AbstractAlgorithm end
2121

2222
mutable struct _DominguezRiosBox
2323
l::Vector{Float64}

src/algorithms/KirlikSayin.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ is solved for each rectangle.
2222
* `MOI.TimeLimitSec()`: terminate if the time limit is exceeded and return the
2323
list of current solutions.
2424
"""
25-
mutable struct KirlikSayin <: AbstractAlgorithm end
25+
struct KirlikSayin <: AbstractAlgorithm end
2626

2727
struct _Rectangle
2828
l::Vector{Float64}

src/algorithms/TambyVanderpooten.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ reformulation is solved using one of the defining points as a starting solution.
2323
* `MOI.TimeLimitSec()`: terminate if the time limit is exceeded and return the
2424
list of current solutions.
2525
"""
26-
mutable struct TambyVanderpooten <: AbstractAlgorithm end
26+
struct TambyVanderpooten <: AbstractAlgorithm end
2727

2828
function _update_search_region(
2929
U_N::Dict{Vector{Float64},Vector{Vector{Vector{Float64}}}},

test/algorithms/EpsilonConstraint.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,7 @@ function test_deprecated()
285285
model = MOA.Optimizer(HiGHS.Optimizer)
286286
MOI.set(model, MOA.Algorithm(), MOA.EpsilonConstraint())
287287
@test MOI.supports(model, MOA.ObjectiveAbsoluteTolerance(1))
288+
@test MOA.default(MOA.ObjectiveAbsoluteTolerance(1)) == 0.0
288289
@test_logs (:warn,) MOI.set(model, MOA.ObjectiveAbsoluteTolerance(1), 1.0)
289290
@test_logs (:warn,) MOI.get(model, MOA.ObjectiveAbsoluteTolerance(1))
290291
return

test/test_model.jl

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,56 @@ function test_unnsupported_attributes()
123123
return
124124
end
125125

126+
function test_invalid_model()
127+
model = MOA.Optimizer(HiGHS.Optimizer)
128+
MOI.optimize!(model)
129+
@test MOI.get(model, MOI.TerminationStatus()) == MOI.INVALID_MODEL
130+
return
131+
end
132+
133+
function test_raw_optimizer_attribuute()
134+
model = MOA.Optimizer(HiGHS.Optimizer)
135+
attr = MOI.RawOptimizerAttribute("presolve")
136+
@test MOI.supports(model, attr)
137+
@test MOI.get(model, attr) == "choose"
138+
MOI.set(model, attr, "off")
139+
@test MOI.get(model, attr) == "off"
140+
return
141+
end
142+
143+
function test_algorithm()
144+
model = MOA.Optimizer(HiGHS.Optimizer)
145+
@test MOI.supports(model, MOA.Algorithm())
146+
@test MOI.get(model, MOA.Algorithm()) == nothing
147+
MOI.set(model, MOA.Algorithm(), MOA.Chalmet())
148+
@test MOI.get(model, MOA.Algorithm()) == MOA.Chalmet()
149+
return
150+
end
151+
152+
function test_copy_to()
153+
src = MOI.Utilities.UniversalFallback(MOI.Utilities.Model{Float64}())
154+
MOI.set(src, MOA.Algorithm(), MOA.Chalmet())
155+
x = MOI.add_variables(src, 2)
156+
MOI.add_constraint.(src, x, MOI.GreaterThan(0.0))
157+
f = MOI.Utilities.operate(vcat, Float64, 1.0 .* x...)
158+
MOI.set(src, MOI.ObjectiveFunction{typeof(f)}(), f)
159+
MOI.set(src, MOI.ObjectiveSense(), MOI.MAX_SENSE)
160+
dest = MOA.Optimizer(HiGHS.Optimizer)
161+
index_map = MOI.copy_to(dest, src)
162+
MOI.set(dest, MOI.Silent(), true)
163+
MOI.optimize!(dest)
164+
@test MOI.get(dest, MOI.NumberOfVariables()) == 2
165+
return
166+
end
167+
168+
function test_scalarise()
169+
x = MOI.VariableIndex.(1:2)
170+
f = MOI.VectorOfVariables(x)
171+
g = MOA._scalarise(f, [0.2, 0.8])
172+
@test isapprox(g, 0.2 * x[1] + 0.8 * x[2])
173+
return
174+
end
175+
126176
end
127177

128178
TestModel.run_tests()

0 commit comments

Comments
 (0)