Skip to content

Commit 73aee00

Browse files
committed
Add suggested tests
1 parent e74bdb4 commit 73aee00

File tree

1 file changed

+15
-9
lines changed

1 file changed

+15
-9
lines changed

test/diagonal.jl

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1577,16 +1577,22 @@ end
15771577
end
15781578

15791579
@testset "norm" begin
1580-
D = Diagonal(float.(1:3))
1581-
A = Array(D)
1582-
@testset for p in -2:2
1583-
p == 0 && continue
1584-
@test norm(D, p) sum(abs.(D).^p)^(1/p)
1585-
@test norm(D, p) norm(A, p)
1580+
# test x ≈ y but also ensure that the types are identical
1581+
function test_isapprox_and_type(x::T, y::T) where {T}
1582+
@test x y
1583+
end
1584+
@testset "size(D,1) = $(size(D,1))" for D in ( Diagonal(1:3), Diagonal(1:1), Diagonal(1:0) )
1585+
A = Array(D)
1586+
@testset for p in -2:2
1587+
p == 0 && continue
1588+
s = sum(float.(abs.(D)).^p)^(1/p)
1589+
test_isapprox_and_type(norm(D, p), isempty(D) ? zero(s) : s)
1590+
test_isapprox_and_type(norm(D, p), norm(A, p))
1591+
end
1592+
test_isapprox_and_type(norm(D, Inf), norm(A, Inf))
1593+
test_isapprox_and_type(norm(D, -Inf), norm(A, -Inf))
1594+
test_isapprox_and_type(norm(D, 0), norm(A, 0))
15861595
end
1587-
@test norm(D, Inf) norm(A, Inf)
1588-
@test norm(D, -Inf) norm(A, -Inf)
1589-
@test norm(D, 0) norm(A, 0)
15901596
end
15911597

15921598
end # module TestDiagonal

0 commit comments

Comments
 (0)