Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
araujoms committed Dec 6, 2024
1 parent b0f080f commit a5bb06d
Showing 1 changed file with 34 additions and 58 deletions.
92 changes: 34 additions & 58 deletions test/random.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,49 +5,34 @@
ψ = random_state_ket(3)
@test isa(ψ, Vector{ComplexF64})
for R in [Float64, Double64, Float128, BigFloat]
Random.seed!(1337) #make ranks behave
ψ = random_state_ket(R, 3)
@test ψ' * ψ 1
@test isa(ψ, Vector{R})
ρ = random_state(R, 3)
@test tr(ρ) 1
@test rank(ρ; rtol = Ket._rtol(R)) == 3
ρ = random_state(R, 3, 2)
@test tr(ρ) 1
@test rank(ρ; rtol = Ket._rtol(R)) == 2
ρ = random_state(R, 3, 1)
@test tr(ρ) 1
@test rank(ρ; rtol = Ket._rtol(R)) == 1
@test minimum(eigvals(ρ)) > -Ket._rtol(R)
@test isa(ρ, Hermitian{R})
T = Complex{R}
ψ = random_state_ket(T, 3)
@test ψ' * ψ 1
@test isa(ψ, Vector{T})
ρ = random_state(T, 3)
@test tr(ρ) 1
@test rank(ρ; rtol = Ket._rtol(R)) == 3
ρ = random_state(T, 3, 2)
@test tr(ρ) 1
@test rank(ρ; rtol = Ket._rtol(R)) == 2
ρ = random_state(T, 3, 1)
@test tr(ρ) 1
@test rank(ρ; rtol = Ket._rtol(R)) == 1
@test minimum(eigvals(ρ)) > -Ket._rtol(R)
@test isa(ρ, Hermitian{T})
for f in (identity, complex)
Random.seed!(1337) #make ranks behave
ψ = random_state_ket(f(R), 3)
@test ψ' * ψ 1
@test isa(ψ, Vector{f(R)})
ρ = random_state(f(R), 3)
@test tr(ρ) 1
@test rank(ρ; rtol = Ket._rtol(f(R))) == 3
ρ = random_state(f(R), 3, 2)
@test tr(ρ) 1
@test rank(ρ; rtol = Ket._rtol(f(R))) == 2
ρ = random_state(f(R), 3, 1)
@test tr(ρ) 1
@test rank(ρ; rtol = Ket._rtol(f(R))) == 1
@test minimum(eigvals(ρ)) > -Ket._rtol(f(R))
@test isa(ρ, Hermitian{f(R)})
end
end
end
@testset "Unitaries" begin
U = random_unitary(3)
@test isa(U, Matrix{ComplexF64})
@test eltype(U) <: ComplexF64
for R in [Float64, Double64, Float128, BigFloat]
U = random_unitary(R, 3)
@test U * U' I(3)
@test isa(U, Matrix{R})
T = Complex{R}
U = random_unitary(T, 3)
@test U * U' I(3)
@test isa(U, Matrix{T})
for f in (identity, complex)
U = random_unitary(f(R), 3)
@test U * U' I(3)
@test eltype(U) <: f(R)
end
end
end
@testset "Probability" begin
Expand All @@ -62,26 +47,17 @@
end
@testset "POVM" begin
for R in [Float64, Double64, Float128, BigFloat]
E = random_povm(R, 2, 3)
@test test_povm(E)
for i in 1:length(E)
@test rank(E[i]; rtol = Ket._rtol(R)) == 2
end
E = random_povm(R, 2, 3, 1)
@test test_povm(E)
for i in 1:length(E)
@test rank(E[i]; rtol = Ket._rtol(R)) == 1
end
T = Complex{R}
E = random_povm(T, 2, 3)
@test test_povm(E)
for i in 1:length(E)
@test rank(E[i]; rtol = Ket._rtol(R)) == 2
end
E = random_povm(T, 2, 3, 1)
@test test_povm(E)
for i in 1:length(E)
@test rank(E[i]; rtol = Ket._rtol(R)) == 1
for f in (identity, complex)
E = random_povm(f(R), 2, 3)
@test test_povm(E)
for i in 1:length(E)
@test rank(E[i]; rtol = Ket._rtol(f(R))) == 2
end
E = random_povm(f(R), 2, 3, 1)
@test test_povm(E)
for i in 1:length(E)
@test rank(E[i]; rtol = Ket._rtol(f(R))) == 1
end
end
end
end
Expand Down

0 comments on commit a5bb06d

Please sign in to comment.