Skip to content

Commit 35e05d0

Browse files
committed
Add tests
1 parent ab8aa54 commit 35e05d0

File tree

6 files changed

+15
-2
lines changed

6 files changed

+15
-2
lines changed

test/algorithms/Chalmet.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ function test_knapsack_max()
105105
[0, 1, 1, 1, 1, 0, 1, 0, 1, 1] => [3043, 4627],
106106
[1, 0, 1, 1, 1, 0, 1, 1, 0, 1] => [3395, 3817],
107107
]
108+
reverse!(results)
108109
@test MOI.get(model, MOI.ResultCount()) == length(results)
109110
for (i, (x_sol, y_sol)) in enumerate(results)
110111
@test (x_sol, MOI.get(model, MOI.VariablePrimal(i), x); atol = 1e-6)

test/algorithms/Dichotomy.jl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,8 @@ function test_moi_bolp_1_maximize()
9898
@test MOI.get(model, MOI.ResultCount()) == 3
9999
X = [[1.0, 0.25], [0.5, 0.5], [0.0, 1.0]]
100100
Y = [[-2.25, -1.25], [-1.5, -1.5], [-1.0, -2.5]]
101+
reverse!(X)
102+
reverse!(Y)
101103
for i in 1:3
102104
@test MOI.get(model, MOI.PrimalStatus(i)) == MOI.FEASIBLE_POINT
103105
@test MOI.get(model, MOI.DualStatus(i)) == MOI.NO_SOLUTION
@@ -227,6 +229,7 @@ function test_biobjective_knapsack()
227229
[948.0, 939.0] => [1, 2, 3, 5, 6, 8, 10, 11, 15, 16, 17],
228230
[955.0, 906.0] => [2, 3, 5, 6, 9, 10, 11, 14, 15, 16, 17],
229231
]
232+
reverse!(results)
230233
for i in 1:MOI.get(model, MOI.ResultCount())
231234
x_sol = MOI.get(model, MOI.VariablePrimal(i), x)
232235
@test results[i][2] == findall(elt -> elt > 0.9, x_sol)

test/algorithms/EpsilonConstraint.jl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ function test_biobjective_knapsack()
6969
[950, 915] => [1, 2, 5, 6, 8, 9, 10, 11, 15, 16, 17],
7070
[956, 906] => [2, 3, 5, 6, 9, 10, 11, 14, 15, 16, 17],
7171
]
72+
reverse!(results)
7273
@test MOI.get(model, MOI.ResultCount()) == 9
7374
for i in 1:MOI.get(model, MOI.ResultCount())
7475
x_sol = MOI.get(model, MOI.VariablePrimal(i), x)
@@ -113,6 +114,7 @@ function test_biobjective_knapsack_atol()
113114
[949, 915] => [1, 2, 5, 6, 8, 9, 10, 11, 15, 16, 17],
114115
[955, 906] => [2, 3, 5, 6, 9, 10, 11, 14, 15, 16, 17],
115116
]
117+
reverse!(results)
116118
@test MOI.get(model, MOI.ResultCount()) == 9
117119
for i in 1:MOI.get(model, MOI.ResultCount())
118120
x_sol = MOI.get(model, MOI.VariablePrimal(i), x)
@@ -154,6 +156,7 @@ function test_biobjective_knapsack_atol_large()
154156
[948, 939] => [1, 2, 3, 5, 6, 8, 10, 11, 15, 16, 17],
155157
[955, 906] => [2, 3, 5, 6, 9, 10, 11, 14, 15, 16, 17],
156158
]
159+
reverse!(results)
157160
@test MOI.get(model, MOI.ResultCount()) == 4
158161
for i in 1:MOI.get(model, MOI.ResultCount())
159162
x_sol = MOI.get(model, MOI.VariablePrimal(i), x)
@@ -238,6 +241,7 @@ function test_biobjective_knapsack_min_solution_limit()
238241
[943, 940] => [2, 3, 5, 6, 8, 9, 10, 11, 15, 16, 17],
239242
[955, 906] => [2, 3, 5, 6, 9, 10, 11, 14, 15, 16, 17],
240243
]
244+
reverse!(results)
241245
@test MOI.get(model, MOI.ResultCount()) == 3
242246
for i in 1:MOI.get(model, MOI.ResultCount())
243247
x_sol = MOI.get(model, MOI.VariablePrimal(i), x)

test/algorithms/Lexicographic.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ function test_knapsack_default()
9494
[1, 0, 1] => [1, 0, 0, 1],
9595
[1, 1, 0] => [1, 1, 0, 0],
9696
]
97+
reverse!(results)
9798
@test MOI.get(model, MOI.ResultCount()) == 3
9899
for i in 1:MOI.get(model, MOI.ResultCount())
99100
X = round.(Int, MOI.get(model, MOI.VariablePrimal(i), x))
@@ -247,6 +248,7 @@ function test_knapsack_5_objectives()
247248
[1, 0, 1, 0, 2] => [1, 0, 1, 0],
248249
[1, 1, 0, 0, 2] => [1, 1, 0, 0],
249250
]
251+
reverse!(results)
250252
for i in 1:MOI.get(model, MOI.ResultCount())
251253
X = round.(Int, MOI.get(model, MOI.VariablePrimal(i), x))
252254
Y = round.(Int, MOI.get(model, MOI.ObjectiveValue(i)))

test/algorithms/RandomWeighting.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,7 @@ function test_knapsack_max()
124124
[0, 1, 1, 1, 1, 0, 1, 0, 1, 1] => [3043, 4627],
125125
[1, 0, 1, 1, 1, 0, 1, 1, 0, 1] => [3395, 3817],
126126
]
127+
reverse!(results)
127128
@test MOI.get(model, MOI.ResultCount()) == length(results)
128129
for (i, (x_sol, y_sol)) in enumerate(results)
129130
@test (x_sol, MOI.get(model, MOI.VariablePrimal(i), x); atol = 1e-6)

test/problems.jl

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ function test_problem_knapsack_max_p3(model)
113113
[0, 1, 1, 1, 1, 0, 1, 0, 1, 1] => [3042, 4627, 3189],
114114
[1, 0, 1, 1, 1, 0, 1, 1, 0, 1] => [3394, 3817, 3408],
115115
]
116+
reverse!(results)
116117
N = MOI.get(model, MOI.ResultCount())
117118
@assert N == length(results)
118119
for i in 1:length(results)
@@ -223,6 +224,7 @@ function test_problem_knapsack_max_p4(model)
223224
[0, 1, 1, 0, 1, 1, 1, 1, 1, 0] => [3152, 3232, 3596, 3382],
224225
[1, 1, 1, 0, 1, 1, 1, 0, 0, 0] => [3269, 2320, 3059, 2891],
225226
]
227+
reverse!(results)
226228
@test MOI.get(model, MOI.ResultCount()) == length(results)
227229
for (i, (x_sol, y_sol)) in enumerate(results)
228230
@test (x_sol, MOI.get(model, MOI.VariablePrimal(i), x); atol = 1e-6)
@@ -368,7 +370,7 @@ function test_problem_assignment_max_p3(model)
368370
MOI.set(model, MOI.ObjectiveSense(), MOI.MAX_SENSE)
369371
MOI.set(model, MOI.ObjectiveFunction{typeof(f)}(), f)
370372
MOI.optimize!(model)
371-
results = reverse([
373+
results = [
372374
[0 1 0 0 0 1 0 0 0 0 0 0 0 1 0 0 0 1 0 0 0 0 0 0 1] => [16, 61, 47],
373375
[0 0 1 0 0 0 1 0 0 0 0 0 0 1 0 1 0 0 0 0 0 0 0 0 1] => [17, 43, 71],
374376
[0 1 0 0 0 0 0 1 0 0 0 0 0 1 0 1 0 0 0 0 0 0 0 0 1] => [18, 47, 67],
@@ -390,7 +392,7 @@ function test_problem_assignment_max_p3(model)
390392
[0 1 0 0 0 0 0 0 0 1 1 0 0 0 0 0 0 1 0 0 0 0 0 1 0] => [43, 51, 31],
391393
[0 1 0 0 0 0 0 0 1 0 1 0 0 0 0 0 0 0 0 1 0 0 1 0 0] => [45, 33, 34],
392394
[0 1 0 0 0 0 0 0 0 1 1 0 0 0 0 0 0 0 1 0 0 0 1 0 0] => [50, 40, 32],
393-
])
395+
]
394396
@test MOI.get(model, MOI.ResultCount()) == length(results)
395397
@test MOI.get(model, MOA.SubproblemCount()) >= length(results)
396398
for (i, (x_sol, y_sol)) in enumerate(results)

0 commit comments

Comments
 (0)