Skip to content

Commit 86af31b

Browse files
committed
Fix the solsandbounds unit test
1 parent 8f925fb commit 86af31b

File tree

1 file changed

+25
-17
lines changed

1 file changed

+25
-17
lines changed

test/unit/ColunaBase/solsandbounds.jl

Lines changed: 25 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,17 @@
1-
struct FakeModel <: ClB.AbstractModel
1+
struct FakeModel <: ClB.AbstractModel
22
id::Int
33
end
44
FakeModel() = FakeModel(1)
55

6-
const Solution = ClB.Solution{FakeModel,Int,Float64}
6+
const Solution = ClB.Solution{FakeModel, Int, Float64}
7+
8+
function Base.show(io::IOContext, solution::Solution{FakeModel, Int, Float64})
9+
println(io, "Solution")
10+
for (decision, value) in solution
11+
println(io, "| ", decision, " = ", value)
12+
end
13+
Printf.@printf(io, "└ value = %.2f \n", getvalue(solution))
14+
end
715

816
function constructor()
917
# Make sure that Coluna initializes bounds to infinity.
@@ -16,19 +24,19 @@ function constructor()
1624
pb = ClB.Bound(primal, min)
1725
@test pb == Inf
1826
@test ClB.getvalue(pb) == Inf
19-
27+
2028
pb = ClB.Bound(primal, max)
2129
@test pb == -Inf
2230
@test ClB.getvalue(pb) == -Inf
23-
31+
2432
db = ClB.Bound(dual, min)
2533
@test db == -Inf
2634
@test ClB.getvalue(db) == -Inf
27-
35+
2836
db = ClB.Bound(dual, max)
2937
@test db == Inf
3038
@test ClB.getvalue(db) == Inf
31-
39+
3240
pb = ClB.Bound(primal, min, 100)
3341
@test pb == 100
3442
@test ClB.getvalue(pb) == 100
@@ -118,16 +126,16 @@ function gap()
118126
# In minimisation, gap = (pb - db)/db
119127
pb = ClB.Bound(min, primal, 10.0)
120128
db = ClB.Bound(min, dual, 5.0)
121-
@test ClB.gap(pb, db) == ClB.gap(db, pb) == (10.0-5.0)/5.0
129+
@test ClB.gap(pb, db) == ClB.gap(db, pb) == (10.0 - 5.0) / 5.0
122130

123131
# In maximisation, gap = (db - pb)/pb
124132
pb = ClB.Bound(max, primal, 5.0)
125133
db = ClB.Bound(max, dual, 10.0)
126-
@test ClB.gap(pb, db) == ClB.gap(db, pb) == (10.0-5.0)/5.0
134+
@test ClB.gap(pb, db) == ClB.gap(db, pb) == (10.0 - 5.0) / 5.0
127135

128136
pb = ClB.Bound(min, primal, 10.0)
129137
db = ClB.Bound(min, dual, -5.0)
130-
@test ClB.gap(pb, db) == ClB.gap(db, pb) == (10.0+5.0)/5.0
138+
@test ClB.gap(pb, db) == ClB.gap(db, pb) == (10.0 + 5.0) / 5.0
131139

132140
# Cannot compute the gap between 2 primal bounds
133141
pb1 = ClB.Bound(max, primal, 10)
@@ -174,7 +182,7 @@ function show_test()
174182
pb = ClB.Bound(max, primal, 4)
175183
io = IOBuffer()
176184
show(io, pb)
177-
@test String(take!(io)) == "4.0"
185+
@test String(take!(io)) == "4.0"
178186
end
179187
register!(unit_tests, "bounds", show_test)
180188

@@ -217,7 +225,7 @@ function convert_MOI_Coluna_termination_statuses()
217225
(MOI.ALMOST_OPTIMAL, ClB.UNCOVERED_TERMINATION_STATUS),
218226
(MOI.SLOW_PROGRESS, ClB.UNCOVERED_TERMINATION_STATUS),
219227
(MOI.MEMORY_LIMIT, ClB.UNCOVERED_TERMINATION_STATUS),
220-
(MOI.ALMOST_OPTIMAL, ClB.UNCOVERED_TERMINATION_STATUS)
228+
(MOI.ALMOST_OPTIMAL, ClB.UNCOVERED_TERMINATION_STATUS),
221229
]
222230

223231
for (moi_status, coluna_status) in statuses_bijection
@@ -236,7 +244,7 @@ function convert_MOI_Coluna_result_statuses()
236244
@test ClB.convert_status(MOI.NO_SOLUTION) == ClB.UNKNOWN_SOLUTION_STATUS
237245
@test ClB.convert_status(MOI.FEASIBLE_POINT) == ClB.FEASIBLE_SOL
238246
@test ClB.convert_status(MOI.INFEASIBLE_POINT) == ClB.INFEASIBLE_SOL
239-
@test ClB.convert_status(MOI.NEARLY_FEASIBLE_POINT) == ClB.UNCOVERED_SOLUTION_STATUS
247+
@test ClB.convert_status(MOI.NEARLY_FEASIBLE_POINT) == ClB.UNCOVERED_SOLUTION_STATUS
240248
end
241249
register!(unit_tests, "convert_MOI_Coluna", convert_MOI_Coluna_result_statuses)
242250

@@ -290,18 +298,18 @@ function solution_constructor_iterate_print()
290298
test_solution_iterations(primal_sol, dict_sol)
291299
@test ClB.getvalue(primal_sol) == 12.3
292300
@test ClB.getstatus(primal_sol) == ClB.FEASIBLE_SOL
293-
301+
294302
dict_sol = Dict(1 => 2.0, 2 => 3.0, 3 => 4.0)
295303
primal_sol = Solution(model, collect(keys(dict_sol)), collect(values(dict_sol)), 0.0, ClB.FEASIBLE_SOL)
296-
304+
297305
@test length(primal_sol) == typemax(Coluna.MAX_NB_ELEMS)
298306
@test nnz(primal_sol) == 3
299307
@test primal_sol[1] == 2.0
300308
primal_sol[1] = 5.0 # change the value
301309
@test primal_sol[1] == 5.0
302-
310+
303311
io = IOBuffer()
304-
show(io, primal_sol)
312+
ClB.show(io, primal_sol)
305313

306314
@test String(take!(io)) == "Solution\n| 1 = 5.0\n| 2 = 3.0\n| 3 = 4.0\n└ value = 0.00 \n"
307315
end
@@ -324,7 +332,7 @@ function solution_isequal()
324332
sol6 = Solution(model, collect(keys(dict_sol2)), collect(values(dict_sol2)), 12.0, ClB.FEASIBLE_SOL)
325333
sol7 = Solution(model, collect(keys(dict_sol3)), collect(values(dict_sol3)), 12.0, ClB.FEASIBLE_SOL)
326334
sol8 = Solution(model, collect(keys(dict_sol4)), collect(values(dict_sol4)), 12.0, ClB.FEASIBLE_SOL)
327-
335+
328336
@test sol1 == sol2
329337
@test sol1 != sol3 # different cost
330338
@test sol1 != sol4 # different solution status

0 commit comments

Comments
 (0)