Skip to content

Commit

Permalink
improve coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
mlubin committed Apr 10, 2015
1 parent 7c4f858 commit 6a54613
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 0 deletions.
19 changes: 19 additions & 0 deletions test/automatic_differentiation_test.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ y = x^3
@test_approx_eq real(y) 2.0^3
@test_approx_eq epsilon(y) 3.0*2^2

y = x^3.0

@test_approx_eq real(y) 2.0^3
@test_approx_eq epsilon(y) 3.0*2^2

y = sin(x)+exp(x)
@test_approx_eq real(y) sin(2)+exp(2)
@test_approx_eq epsilon(y) cos(2)+exp(2)
Expand Down Expand Up @@ -41,3 +46,17 @@ end

@test_approx_eq epsilon(exp(1)^Dual(1.0,1.0)) exp(1)
@test_approx_eq epsilon(NaNMath.pow(exp(1),Dual(1.0,1.0))) exp(1)
@test_approx_eq epsilon(NaNMath.sin(Dual(1.0,1.0))) cos(1)

@test Dual(1.0,3) == Dual(1.0,3.0)
x = Dual(1.0,1.0)
@test eps(x) == eps(1.0)
@test eps(Dual{Float64}) == eps(Float64)
@test one(x) == Dual(1.0,0.0)
@test one(Dual{Float64}) == Dual(1.0,0.0)
@test inf(Dual{Float64}) == inf(Float64)
@test isnan(nan(Dual{Float64}))

@test convert(Dual{Float64},Dual(1,2)) == Dual(1.0,2.0)
@test convert(Float64, Dual(10.0,0.0)) == 10.0
@test convert(Dual{Int}, Dual(10.0,0.0)) == Dual(10,0)
24 changes: 24 additions & 0 deletions test/dual_n.jl
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,36 @@ y = x^3
@test_approx_eq epsilon3(y) 3*3.0*2^2
@test_approx_eq epsilon4(y) 4*3.0*2^2

y = x^3.0

@test_approx_eq real(y) 2.0^3
@test_approx_eq epsilon1(y) 3.0*2^2
@test_approx_eq epsilon2(y) 2*3.0*2^2
@test_approx_eq epsilon3(y) 3*3.0*2^2
@test_approx_eq epsilon4(y) 4*3.0*2^2

y = NaNMath.pow(x,3)

@test_approx_eq real(y) 2.0^3
@test_approx_eq epsilon1(y) 3.0*2^2
@test_approx_eq epsilon2(y) 2*3.0*2^2
@test_approx_eq epsilon3(y) 3*3.0*2^2
@test_approx_eq epsilon4(y) 4*3.0*2^2

y = sin(x)+exp(x)
@test_approx_eq real(y) sin(2)+exp(2)
@test_approx_eq epsilon1(y) cos(2)+exp(2)
@test_approx_eq epsilon2(y) 2*(cos(2)+exp(2))
@test_approx_eq epsilon3(y) 3*(cos(2)+exp(2))
@test_approx_eq epsilon4(y) 4*(cos(2)+exp(2))

y = x/2
@test_approx_eq real(y) 1.0
@test_approx_eq epsilon1(y) 0.5
@test_approx_eq epsilon2(y) 1.0
@test_approx_eq epsilon3(y) 3/2
@test_approx_eq epsilon4(y) 2.0


@test x > 1
y = abs(-x)
Expand Down Expand Up @@ -55,6 +78,7 @@ sq = squareroot(Dual4(10000.0,1.0,2.0,3.0,4.0))
@test_approx_eq epsilon2(exp(1)^Dual4(1.0,1.0,2.0,3.0,4.0)) 2exp(1)
@test_approx_eq epsilon3(exp(1)^Dual4(1.0,1.0,2.0,3.0,4.0)) 3exp(1)
@test_approx_eq epsilon4(exp(1)^Dual4(1.0,1.0,2.0,3.0,4.0)) 4exp(1)
@test_approx_eq epsilon2(NaNMath.sin(Dual4(1.0,1.0,2.0,3.0,4.0))) 2cos(1)

@test_approx_eq epsilon1(NaNMath.pow(exp(1),Dual4(1.0,1.0,2.0,3.0,4.0))) exp(1)
@test_approx_eq epsilon2(NaNMath.pow(exp(1),Dual4(1.0,1.0,2.0,3.0,4.0))) 2exp(1)
Expand Down

0 comments on commit 6a54613

Please sign in to comment.