Skip to content

Commit

Permalink
Add unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mewilhel committed Apr 10, 2020
1 parent 575cf9c commit 5513355
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 3 deletions.
3 changes: 2 additions & 1 deletion src/forward_operators/other.jl
Original file line number Diff line number Diff line change
Expand Up @@ -177,5 +177,6 @@ end
max_MC.cv_grad, min_MC.cc_grad, x.cnst)
end

@inline in(x::MC) = in(x.Intv)
@inline in(a::Int, x::MC) = in(a, x.Intv)
@inline in(a::T, x::MC) where T<:AbstractFloat = in(a, x.Intv)
@inline isempty(x::MC) = isempty(x.Intv)
4 changes: 2 additions & 2 deletions src/forward_operators/power.jl
Original file line number Diff line number Diff line change
Expand Up @@ -335,8 +335,8 @@ function (^)(x::MC{N,Diff}, c::Float64, y::Interval{Float64}) where N
return MC{N,Diff}(z.cv, z.cc, y, z.cv_grad, z.cc_grad, x.cnst)
end

(^)(x::MC, c::Float32, y::Interval{Float64}) = (^)(x, Float32(c), y)
(^)(x::MC, c::Float16, y::Interval{Float64}) = (^)(x, Float16(c), y)
(^)(x::MC, c::Float32, y::Interval{Float64}) = (^)(x, Float64(c), y)
(^)(x::MC, c::Float16, y::Interval{Float64}) = (^)(x, Float64(c), y)
(^)(x::MC, c::Float64) = (^)(x, c, x.Intv^c)
(^)(x::MC, c::Float32) = x^Float64(c) # DONE
(^)(x::MC, c::Float16) = x^Float64(c) # DONE
Expand Down
22 changes: 22 additions & 0 deletions test/forward_mccormick.jl
Original file line number Diff line number Diff line change
Expand Up @@ -413,6 +413,28 @@ end
@test isapprox(Z7.cc, 1.0e30, rtol = 1E-3)
@test isapprox(Z8.cv, -1.0e30, rtol = 1E-3)
@test isapprox(Z8.cc, 1.0e30, rtol = 1E-3)

@test isapprox(McCormick.tanh_deriv(3.0, 2.0, 4.0), 0.009866, rtol=1E-3)
@test isapprox(McCormick.tanh_envd(3.0, 2.0, 4.0), 6.258589, rtol=1E-3)
@test isapprox(McCormick.atan_deriv(3.0, 2.0, 4.0), 0.100, rtol=1E-3)
@test isapprox(McCormick.asin_deriv(0.5, 0.0, 0.9), 1.1547005, rtol=1E-3)
@test isapprox(McCormick.tan_deriv(3.0, 2.0, 4.0), 1.0203195, rtol=1E-3)
@test isapprox(McCormick.tan_envd(3.0, 2.0, 4.0), -0.570704, rtol=1E-3)
@test isapprox(McCormick.acos_deriv(0.5, 0.0, 0.9), -1.1547005, rtol=1E-3)
@test isapprox(McCormick.acos_env(0.5, 0.0, 0.9), -0.04655, rtol=1E-3)
@test isapprox(McCormick.asinh_deriv(3.0, 2.0, 4.0), 0.31622, rtol=1E-3)

xD = MC{2,Diff}(2.0,2.0,Interval{Float64}(1.0,4.0), seed_gradient(2,Val(2)), seed_gradient(2,Val(2)),false)
xNS = MC{2,NS}(2.0,2.0,Interval{Float64}(1.0,4.0), seed_gradient(2,Val(2)), seed_gradient(2,Val(2)),false)

@test xD^0 == one(xD)
@test xNS^0 == one(xNS)
@test ~isnan(xD)
@test ~in(0.5,xD)
@test in(2,xD)
@test ~isempty(xD)

@test_throws ErrorException (-0.5)^xNS
end


Expand Down

0 comments on commit 5513355

Please sign in to comment.