Skip to content

Commit

Permalink
Make the tests compact
Browse files Browse the repository at this point in the history
  • Loading branch information
krish8484 committed Aug 11, 2020
1 parent ba320f9 commit ce08851
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 38 deletions.
8 changes: 4 additions & 4 deletions src/intervals/arithmetic.jl
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,9 @@ function *(x::S, a::Interval{T}) where {T, S<:AbstractFloat}
(iszero(a) || iszero(x)) && return zero(Interval{T})

if x 0.0
c = @round(Interval{T}, a.lo*x, a.hi*x)
return @round(Interval{T}, a.lo*x, a.hi*x)
else
c = @round(Interval{T}, a.hi*x, a.lo*x)
return @round(Interval{T}, a.hi*x, a.lo*x)
end

end
Expand Down Expand Up @@ -155,9 +155,9 @@ function /(a::Interval{T}, x::S) where {T, S<:AbstractFloat}
iszero(a) && return zero(Interval{T})

if x 0.0
c = @round(Interval{T}, a.lo/x, a.hi/x)
return @round(Interval{T}, a.lo/x, a.hi/x)
else
c = @round(Interval{T}, a.hi/x, a.lo/x)
return @round(Interval{T}, a.hi/x, a.lo/x)
end

end
Expand Down
46 changes: 12 additions & 34 deletions test/interval_tests/numeric.jl
Original file line number Diff line number Diff line change
Expand Up @@ -393,40 +393,18 @@ end

@testset "function call for mathematical operators" begin

@testset "+ operator" begin
@test which(+, (Interval{Float64}, Float32)).module == IntervalArithmetic
@test which(+, (Interval{Float32}, Float64)).module == IntervalArithmetic
@test which(+, (Interval{BigFloat}, Float64)).module == IntervalArithmetic
@test which(+, (Interval{Float64}, BigFloat)).module == IntervalArithmetic
@test which(+, (Interval{Float32}, Float64)).module == IntervalArithmetic
@test which(+, (Interval{BigFloat}, Float32)).module == IntervalArithmetic
end

@testset "- operator" begin
@test which(-, (Interval{Float64}, Float32)).module == IntervalArithmetic
@test which(-, (Interval{Float32}, Float64)).module == IntervalArithmetic
@test which(-, (Interval{BigFloat}, Float64)).module == IntervalArithmetic
@test which(-, (Interval{Float64}, BigFloat)).module == IntervalArithmetic
@test which(-, (Interval{Float32}, Float64)).module == IntervalArithmetic
@test which(-, (Interval{BigFloat}, Float32)).module == IntervalArithmetic
end

@testset "* operator" begin
@test which(*, (Interval{Float64}, Float32)).module == IntervalArithmetic
@test which(*, (Interval{Float32}, Float64)).module == IntervalArithmetic
@test which(*, (Interval{BigFloat}, Float64)).module == IntervalArithmetic
@test which(*, (Interval{Float64}, BigFloat)).module == IntervalArithmetic
@test which(*, (Interval{Float32}, Float64)).module == IntervalArithmetic
@test which(*, (Interval{BigFloat}, Float32)).module == IntervalArithmetic
end

@testset "/ operator" begin
@test which(/, (Interval{Float64}, Float32)).module == IntervalArithmetic
@test which(/, (Interval{Float32}, Float64)).module == IntervalArithmetic
@test which(/, (Interval{BigFloat}, Float64)).module == IntervalArithmetic
@test which(/, (Interval{Float64}, BigFloat)).module == IntervalArithmetic
@test which(/, (Interval{Float32}, Float64)).module == IntervalArithmetic
@test which(/, (Interval{BigFloat}, Float32)).module == IntervalArithmetic
types = [Float32, Float64, BigFloat]
operations = [+, *, -, /]

for op in operations
for T1 in types
for T2 in types
@test which(op, (Interval{T1}, T2)).module == IntervalArithmetic
if(op != /)
@test which(op, (T1, Interval{T2})).module == IntervalArithmetic
end
end
end
end
end

Expand Down

0 comments on commit ce08851

Please sign in to comment.