Skip to content

Commit

Permalink
improve test coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
GiggleLiu committed Oct 7, 2023
1 parent 70e341c commit 1c01004
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
1 change: 1 addition & 0 deletions lib/YaoSym/src/symengine/blocks.jl
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ Base.angle(x::Basic)::Basic = Basic(angle(SymEngine.BasicType(x)))
Base.angle(x::BasicType)::Basic = sangle(x.x)
Base.angle(::BasicType{Val{:Symbol}})::Basic = Basic(0)
Base.angle(::BasicType{Val{:Constant}})::Basic = Basic(0)
Base.angle(::SymEngine.BasicRealNumber)::Basic = Basic(0)

Base.conj(x::BiVarOp) = juliafunc(x)(conj.(get_args(x.x))...)
Base.conj(x::BasicTrigFunction) = juliafunc(x)(conj.(get_args(x.x)...)...)
Expand Down
16 changes: 14 additions & 2 deletions lib/YaoSym/test/symengine/blocks.jl
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
using YaoSym, YaoBlocks, YaoArrayRegister, SymEngine
using YaoSym: simplify_expi
using YaoSym: simplify_expi, BasicType
using SymEngine
using Test

@testset "imag and conj" begin
@vars a b c x
@vars a b c d x
@test imag(Basic(2 + im * a)) == a
@test imag(Basic((2 + im) * (im * a + 1))) == 2 * a + 1
@test real(sin(a)) == sin(a)
Expand All @@ -14,6 +14,9 @@ using Test
@test real(exp(im * a)) == cos(a)
@test imag(exp(im * a)) == sin(a)
@test abs(exp(im * a)) == 1
@test BasicType(imag(cos(im * a + b))) isa BasicType{Val{:FunctionSymbol}}
@test BasicType(real((im*c + d)^(im * a + b))) isa BasicType{Val{:FunctionSymbol}}
@test BasicType(real(sin(im * a + b))) isa BasicType{Val{:FunctionSymbol}}
end

@testset "mat" begin
Expand Down Expand Up @@ -122,3 +125,12 @@ end
@test test_check_dumpload(time_evolve(X, θ))
@test test_check_dumpload(rot(X, θ))
end

@testset "angle" begin
@vars x
@test_broken Float64(angle(Basic(1 + im))) π / 4
@test angle(x) == Basic(0)
@test BasicType(angle((1+x)^x)) isa BasicType{Val{:FunctionSymbol}}
@test angle(Basic(1)) == Basic(0)
@test angle(exp(Basic(1))) == Basic(0)
end

0 comments on commit 1c01004

Please sign in to comment.