Skip to content

Commit 38ea407

Browse files
committed
Improve test coverage for zeros
xref #15
1 parent ee03f45 commit 38ea407

1 file changed

Lines changed: 18 additions & 0 deletions

File tree

test/runtests.jl

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,17 @@ using Test
149149
@test cover_qobjective(a_qmin, A) <= cover_qobjective(a_fast, A) + 1e-8
150150
@test cover_qobjective(a_qmin, A) <= cover_qobjective(a_lmin, A) + 1e-8
151151
end
152+
# Case with zeros to ensure optimal solution
153+
A = [0 0 1; 0 0 2; 1 2 1]
154+
a = symcover_lmin(A)
155+
@test all(a[i] * a[j] >= abs(A[i, j]) - 1e-10 for i in axes(A, 1), j in axes(A, 2))
156+
@test a [1, 2, 1]
157+
@test abs(cover_lobjective(a, A)) < 1e-10
158+
a = symcover_qmin(A)
159+
@test all(a[i] * a[j] >= abs(A[i, j]) - 1e-10 for i in axes(A, 1), j in axes(A, 2))
160+
@test a [1, 2, 1]
161+
@test abs(cover_qobjective(a, A)) < 1e-10
162+
152163
for A in ([2.0 1.0; 1.0 3.0], [100.0 1.0; 0.5 0.01], [1.0 2.0 3.0; 4.0 5.0 6.0])
153164
a_fast, b_fast = cover(A)
154165
a_lmin, b_lmin = cover_lmin(A)
@@ -159,6 +170,13 @@ using Test
159170
@test cover_qobjective(a_qmin, b_qmin, A) <= cover_qobjective(a_fast, b_fast, A) + 1e-8
160171
@test cover_qobjective(a_qmin, b_qmin, A) <= cover_qobjective(a_lmin, b_lmin, A) + 1e-8
161172
end
173+
A = [0 0 0 1; 1 1 0 2; 1 0 2 1]
174+
a, b = cover_lmin(A)
175+
@test all(a[i] * b[j] >= abs(A[i, j]) - 1e-10 for i in axes(A, 1), j in axes(A, 2))
176+
@test cover_lobjective(a, b, A) log(2)
177+
a, b = cover_qmin(A)
178+
@test all(a[i] * b[j] >= abs(A[i, j]) - 1e-10 for i in axes(A, 1), j in axes(A, 2))
179+
@test cover_qobjective(a, b, A) 2*log(sqrt(2))^2
162180
end
163181

164182
@testset "SparseMatrixCSC" begin

0 commit comments

Comments
 (0)