@testset "Functionals" begin

@testset "trace norm" begin
    Ï� = [0.25 0.25im; -0.25im 0.75]
    @test norm_trace(Ï�) â‰ˆ 1
    @test norm_trace(sx*Ï�) â‰ˆ 1
end

@testset "trace distance" begin
    Ï� = [0.25 0.25im; -0.25im 0.75]
    Ïƒ = [0.4 0.1im; -0.1im 0.6]

    @test trace_distance(Ï�, Ï�) â‰ˆ 0 atol=1e-14
    @test trace_distance(Ï�, Ïƒ) â‰ˆ 3/(10sqrt(2)) atol=1e-15
end

@testset "HS norm" begin
    Ï� = [0.25 0.25im; -0.25im 0.75]
    @test norm_hs(Ï�) â‰ˆ sqrt(3)/2
    @test norm_hs(sx*Ï�) â‰ˆ sqrt(3)/2
end

@testset "HS distance" begin
    Ï� = [0.25 0.25im; -0.25im 0.75]
    Ïƒ = [0.4 0.1im; -0.1im 0.6]

    @test hs_distance(Ï�, Ï�) â‰ˆ 0 atol=1e-14
    @test hs_distance(Ï�, Ïƒ) â‰ˆ 3/10 atol=1e-15
end

@testset "fidelity_sqrt" begin
    Ï� = [0.25 0.25im; -0.25im 0.75]
    Ïƒ = [0.4 0.1im; -0.1im 0.6]
    @test fidelity_sqrt(Ï�, Ïƒ) â‰ˆ real(tr(sqrt(sqrt(Ï�) * Ïƒ * sqrt(Ï�)))) atol=1e-15
    @test_throws ArgumentError fidelity_sqrt(ones(2, 3), ones(2, 2))
end

@testset "fidelity" begin
    Ï• = ket(1, 2)
    Ïˆ = ket(2, 2)
    Ï� = [0.25 0.25im; -0.25im 0.75]
    Ïƒ = [0.4 0.1im; -0.1im 0.6]
    @test fidelity(Ï•, Ï•) â‰ˆ 1. atol=1e-15
    @test fidelity(Ï•, Ïˆ) â‰ˆ 0. atol=1e-15
    @test fidelity(Ï�, Ïˆ) â‰ˆ 0.75 atol=1e-15
    @test fidelity(Ï•, Ïƒ) â‰ˆ 0.4 atol=1e-15
    @test fidelity(Ï�, Ïƒ) â‰ˆ real(tr(sqrt(sqrt(Ï�) * Ïƒ * sqrt(Ï�))))^2 atol=1e-15
end

@testset "gate fidelity" begin
    H = [1 1; 1 -1+0im]/sqrt(2)
    @test gate_fidelity(sx, sy) â‰ˆ 0
    @test gate_fidelity(sx, H) â‰ˆ 1/sqrt(2)
    @test gate_fidelity(sy, H) â‰ˆ 0
    @test gate_fidelity(sz, H) â‰ˆ 1/sqrt(2)
    @test gate_fidelity(H, sx) â‰ˆ 1/sqrt(2)
end

@testset "Shannon entropy" begin
    @test shannon_entropy(1/2) â‰ˆ log(2) atol=1e-15
    @test shannon_entropy(1/4) â‰ˆ 0.5623351446188083 atol=1e-15
    @test shannon_entropy(0.5*ones(20)) â‰ˆ 10log(2) atol=1e-15
end

@testset "von Neumann entropy" begin
    Ï• = ket(1, 2)
    Ï� = [0.25 0.25im; -0.25im 0.75]
    @test vonneumann_entropy(Ï•) == 0
    @test vonneumann_entropy(Ï�) â‰ˆ 0.25(log(64)-2sqrt(2)*acoth(sqrt(2)))
end

@testset "renyi entropy" begin
    d = 3
    Ï� = ğ�•€(d)/d
    @test renyi_entropy(Ï�, 2) == log(d)
    @test renyi_entropy(Ï�, 3) == log(d)
end

@testset "relative entropy, js divergence" begin
    Ï� = [0.25 0.25im; -0.25im 0.75]
    Ïƒ = [0.4 0.1im; -0.1im 0.6]
    expected = -acoth(5/sqrt(2))/sqrt(2)+acoth(sqrt(2))/sqrt(2)+log(5)-log(46)/2
    expected2 = -1/5*sqrt(2)*atanh(3/(4sqrt(2)))+1/2*log(46/25)
    @test relative_entropy(Ï�, Ïƒ) â‰ˆ expected
    @test kl_divergence(Ï�, Ïƒ) â‰ˆ expected
    @test relative_entropy(Ïƒ, Ï�) â‰ˆ expected2
    @test kl_divergence(Ïƒ, Ï�) â‰ˆ expected2
    @test js_divergence(Ï�, Ïƒ) â‰ˆ 0.5expected+0.5expected2
end

@testset "bures distance, bures angle" begin
    Ï� = [0.25 0.25im; -0.25im 0.75]
    Ïƒ = [0.4 0.1im; -0.1im 0.6]
    fsqrt = 1/2 * sqrt(1/5 * (12 + sqrt(46)))

    @test bures_distance(Ï�, Ïƒ) â‰ˆ sqrt(2 - 2fsqrt)
    @test bures_distance(Ïƒ, Ï�) â‰ˆ sqrt(2 - 2fsqrt)
    @test bures_angle(Ï�, Ïƒ) â‰ˆ acos(fsqrt)
    @test bures_angle(Ïƒ, Ï�) â‰ˆ acos(fsqrt)
end

@testset "superfidelity" begin
    Ï� = [0.25 0.25im; -0.25im 0.75]
    Ïƒ = [0.4 0.1im; -0.1im 0.6]
    expected = 1/20 * (12 + sqrt(46))
    @test superfidelity(Ï�, Ïƒ) â‰ˆ expected
    @test superfidelity(Ï�, Ïƒ) â‰ˆ superfidelity(Ïƒ, Ï�)
end

@testset "(log) negativity, ppt, concurrence" begin
    Ï� = [0.25 0.25im; -0.25im 0.75]
    Ïƒ = [0.4 0.1im; -0.1im 0.6]
    @test negativity(Ï� âŠ— Ïƒ, [2, 2], 2) â‰ˆ 0 atol=1e-15
    @test log_negativity(Ï� âŠ— Ïƒ, [2, 2], 2) â‰ˆ 0 atol=1e-15
    @test ppt(Ï� âŠ— Ïƒ, [2, 2], 2) > 0
    @test concurrence(Ï� âŠ— Ïƒ) â‰ˆ 0 atol=1e-15

    Ï� = proj([1, 0, 0, 1. + 0im])/2
    @test negativity(Ï�, [2, 2], 2) â‰ˆ 1/2 atol=1e-15
    @test log_negativity(Ï�, [2, 2], 2) â‰ˆ log(2) atol=1e-15
    @test ppt(Ï�, [2, 2], 2) â‰ˆ -1/2 atol=1e-15
    @test concurrence(Ï�) â‰ˆ 1 atol=1e-15

    Ï� = 9/10*proj([1, 0, 0, 1. + 0im])/2 + 1/10*I/4

    @test negativity(Ï�, [2, 2], 2) â‰ˆ 17/40 atol=1e-15
    @test log_negativity(Ï�, [2, 2], 2) â‰ˆ log(37/20) atol=1e-15
    @test ppt(Ï�, [2, 2], 2) â‰ˆ -17/40 atol=1e-15
end

end
