Skip to content

Commit

Permalink
add tests for arithmetics.jl
Browse files Browse the repository at this point in the history
  • Loading branch information
TimSiebert1 committed Jul 5, 2024
1 parent 643f1eb commit 1283439
Show file tree
Hide file tree
Showing 2 changed files with 83 additions and 0 deletions.
81 changes: 81 additions & 0 deletions test/arithmetics.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@

bin_ops = [+, -, *, /, max, min] # ^]
un_ops = [
abs,
sqrt,
log,
log10,
sin,
cos,
exp,
tan,
#asin,
acos,
atan,
sinh,
cosh,
tanh,
sinh,
asinh,
atanh,
ceil,
floor,
#frexp, frexp(a, Ref(Cint(3)))
#erf,
#eps,
#SpecialFunctions.erfc,
]

comps = [>=, >, <=, <, ==]

@testset "binary operations" begin()
for t in [Adouble{TlAlloc}, Adouble{TbAlloc}]
for op in bin_ops
a = t(2.0, adouble=true)
@test getValue(op(a, -2.0)) == op(2.0, -2.0)
@test getValue(op(-2.0, a)) == op(-2.0, 2.0)
@test getValue(op(a, a)) == op(getValue(a), getValue(a))
a = t(2.0, adouble=false)
@test getValue(op(a, -2.0)) == op(2.0, -2.0)
@test getValue(op(-2.0, a)) == op(-2.0, 2.0)
@test getValue(op(a, a)) == op(getValue(a), getValue(a))
end
op = ldexp
a = t(2.0, adouble=true)
@test getValue(op(a, 3)) == op(2.0, 3)
a = t(2.0, adouble=false)
@test getValue(op(a, 3)) == op(2.0, 3)
end
end

@testset "unary operations" begin()
for t in [Adouble{TlAlloc}, Adouble{TbAlloc}]
for op in un_ops
a = t(0.5, adouble=true)
@test getValue(op(a)) op(0.5)
a = t(0.5, adouble=false)
@test getValue(op(a)) op(0.5)
end
a = t(1.5, adouble=true)
@test getValue(acosh(a)) acosh(1.5)
a = t(1.5, adouble=false)
@test getValue(acosh(a)) acosh(1.5)
end
end

@testset "comps" begin()

for t in [Adouble{TlAlloc}, Adouble{TbAlloc}]
for op in comps
a = t(0.5, adouble=true)
@test op(a, 2) == op(0.5, 2)
@test op(2, a) == op(2, 0.5)
@test op(a, a) == op(0.5, 0.5)

a = t(0.5, adouble=false)
@test op(a, 2) == op(0.5, 2)
@test op(2, a) == op(2, 0.5)
@test op(a, a) == op(0.5, 0.5)
end
end
end
2 changes: 2 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@ using ADOLC.TbadoubleModule
using ADOLC.array_types
using Test
using CxxWrap
using SpecialFunctions: SpecialFunctions

include("test_adouble.jl")
include("test_array_types.jl")
include("arithmetics.jl")
include("first_order/test_derivative.jl")
include("first_order/test_derivative!.jl")
include("second_order/test_derivative.jl")
Expand Down

0 comments on commit 1283439

Please sign in to comment.