Skip to content

Commit

Permalink
revert changes to test sets
Browse files Browse the repository at this point in the history
  • Loading branch information
gwater committed Jul 25, 2018
1 parent 3ced063 commit ab77d5e
Show file tree
Hide file tree
Showing 5 changed files with 76 additions and 86 deletions.
8 changes: 4 additions & 4 deletions test/interval_tests/bisect.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ using Base.Test

@testset "`bisect` function" begin
X = 0..1
@test bisect(X, 0.5) === (0..0.5, 0.5..1)
@test bisect(X, 0.25) === (0..0.25, 0.25..1)
@test bisect(X, 0.5) == (0..0.5, 0.5..1)
@test bisect(X, 0.25) == (0..0.25, 0.25..1)

@test bisect(X) === (interval(0.0, 0.49609375), interval(0.49609375, 1.0))
@test bisect(X) == (interval(0.0, 0.49609375), interval(0.49609375, 1.0))

X = -..
@test bisect(X, 0.5) === (-..0, 0..∞)
@test bisect(X, 0.5) == (-..0, 0..∞)
B = bisect(X, 0.75)
@test B[1].hi > 0
@test B[1].hi == B[2].lo
Expand Down
11 changes: 4 additions & 7 deletions test/interval_tests/complex.jl
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,13 @@ end
@test a == Interval(0) + Interval(1)*im
@test a * a == Interval(-1)
@test a + a == Interval(2)*im
@test iszero(a - a)
@test isequal(a / a, 1)
@test a - a == 0
@test a / a == 1
@test a^2 == -1
end

@testset "Complex functions" begin
Z = (3 ± 1e-7) + (4 ± 1e-7)*im
@test isequal(sin(Z),
complex(sin(real(Z))*cosh(imag(Z)),sinh(imag(Z))*cos(real(Z))))
@test isequal(exp(-im * Interval(π)),
Interval(-1.0, -0.9999999999999999) -
Interval(1.224646799147353e-16, 1.2246467991473532e-16)*im)
@test sin(Z) == complex(sin(real(Z))*cosh(imag(Z)),sinh(imag(Z))*cos(real(Z)))
@test exp(-im * Interval(π)) == Interval(-1.0, -0.9999999999999999) - Interval(1.224646799147353e-16, 1.2246467991473532e-16)*im
end
12 changes: 6 additions & 6 deletions test/interval_tests/consistency.jl
Original file line number Diff line number Diff line change
Expand Up @@ -343,11 +343,11 @@ setprecision(Interval, Float64)
a = @interval(1, 2)
b = @interval(3, 4)

@test a^b === @interval(1, 16)
@test a^@interval(0.5, 1) === a
@test a^@interval(0.3, 0.5) === @interval(1, sqrt(2))
@test a^b == @interval(1, 16)
@test a^@interval(0.5, 1) == a
@test a^@interval(0.3, 0.5) == @interval(1, sqrt(2))

@test b^@interval(0.3) === Interval(1.3903891703159093, 1.5157165665103982)
@test b^@interval(0.3) == Interval(1.3903891703159093, 1.5157165665103982)
end

@testset "isatomic" begin
Expand All @@ -369,11 +369,11 @@ setprecision(Interval, Float64)
@test iszero(Interval(-0.0, 0.0))

@test !iszero(1..2)
@test_throws IntervalArithmetic.UndecidableError !iszero(Interval(0.0, nextfloat(0.0)))
@test !iszero(Interval(0.0, nextfloat(0.0)))
end

@testset "Difference between Interval and interval" begin
@test interval(1, 2) === Interval(1, 2)
@test interval(1, 2) == Interval(1, 2)

@test inf(Interval(3, 2)) == 3
@test_throws ArgumentError interval(3, 2)
Expand Down
107 changes: 50 additions & 57 deletions test/interval_tests/construction.jl
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ end
@test IntervalArithmetic.parameters.precision_type == Float64
@test IntervalArithmetic.parameters.precision == 53
@test IntervalArithmetic.parameters.rounding == :narrow
@test isequal(IntervalArithmetic.parameters.pi, @biginterval(pi))
@test IntervalArithmetic.parameters.pi == @biginterval(pi)

# Naive constructors, with no conversion involved
@test Interval(1) == Interval(1.0, 1.0)
Expand All @@ -33,7 +33,7 @@ end
@test Interval(eeuler) == Interval(1.0*eeuler)
@test Interval(1//10) == Interval{Rational{Int}}(1//10, 1//10)
@test Interval(BigInt(1)//10) == Interval{Rational{BigInt}}(1//10, 1//10)
@test isequal(Interval( (1.0, 2.0) ), Interval(1.0, 2.0))
@test Interval( (1.0, 2.0) ) == Interval(1.0, 2.0)

@test Interval{Rational{Int}}(1) == Interval(1//1)
#@test Interval{Rational{Int}}(pi) == Interval(rationalize(1.0*pi))
Expand All @@ -42,21 +42,18 @@ end
@test Interval{BigFloat}(1) == Interval{BigFloat}(big(1.0), big(1.0))
@test Interval{BigFloat}(pi) == Interval{BigFloat}(big(pi), big(pi))

@test isequal(-pi..pi, @interval(-pi,pi))
@test isequal(0..pi, hull(interval(0), pi_interval(Float64)))
@test isequal(1.2..pi, @interval(1.2, pi))
@test isequal(pi..big(4), hull(pi_interval(BigFloat), interval(4)))
@test isequal(pi..pi, pi_interval(Float64))
@test isequal(eeuler..pi, hull(@interval(eeuler), pi_interval(Float64)))
@test -pi..pi == @interval(-pi,pi)
@test 0..pi == hull(interval(0), pi_interval(Float64))
@test 1.2..pi == @interval(1.2, pi)
@test pi..big(4) == hull(pi_interval(BigFloat), interval(4))
@test pi..pi == pi_interval(Float64)
@test eeuler..pi == hull(@interval(eeuler), pi_interval(Float64))

# a < Inf and b > -Inf
@test isequal(@interval(1e300),
Interval(9.999999999999999e299, 1.0e300))
@test isequal(@interval(-1e307),
Interval(-1.0000000000000001e307, -1.0e307))
@test isequal(@interval(Inf), IntervalArithmetic.wideinterval(Inf))
@test isequal(IntervalArithmetic.wideinterval(-big(Inf)),
Interval(-Inf, nextfloat(big(-Inf))))
@test @interval(1e300) == Interval(9.999999999999999e299, 1.0e300)
@test @interval(-1e307) == Interval(-1.0000000000000001e307, -1.0e307)
@test @interval(Inf) == IntervalArithmetic.wideinterval(Inf)
@test IntervalArithmetic.wideinterval(-big(Inf)) == Interval(-Inf, nextfloat(big(-Inf)))

# Disallowed conversions with a > b

Expand All @@ -77,19 +74,19 @@ end

# Conversion to Interval without type
@test convert(Interval, 1) == Interval(1.0)
@test isequal(convert(Interval, pi), @interval(pi))
@test isequal(convert(Interval, eeuler), @interval(eeuler))
@test convert(Interval, pi) == @interval(pi)
@test convert(Interval, eeuler) == @interval(eeuler)
@test convert(Interval, BigInt(1)) == Interval(BigInt(1))
@test isequal(convert(Interval, 1//10), @interval(1//10))
@test convert(Interval, 1//10) == @interval(1//10)
@test convert(Interval, Interval(0.1, 0.2)) === Interval(0.1, 0.2)

@test convert(Interval{Rational{Int}}, 0.1) == Interval(1//10)
# @test convert(Interval{Rational{BigInt}}, pi) == Interval{Rational{BigInt}}(pi)

## promotion
@test isequal(promote(Interval(2//1,3//1), Interval(1, 2)),
(Interval(2.0,3.0), Interval(1.0,2.0)))
@test isequal(promote(Interval(1.0), pi), (Interval(1.0), @interval(pi)))
@test promote(Interval(2//1,3//1), Interval(1, 2)) ==
(Interval(2.0,3.0), Interval(1.0,2.0))
@test promote(Interval(1.0), pi) == (Interval(1.0), @interval(pi))

# Constructors from the macros @interval, @floatinterval @biginterval
setprecision(Interval, 53)
Expand All @@ -99,13 +96,13 @@ end

@test nextfloat(a.lo) == a.hi
@test typeof(a) == Interval{BigFloat}
@test isequal(a, @biginterval("0.1"))
@test isequal(convert(Interval{Float64}, a), @floatinterval(0.1))
@test a == @biginterval("0.1")
@test convert(Interval{Float64}, a) == @floatinterval(0.1)
@test nextfloat(b.lo) == b.hi

@test isequal(b, @biginterval(pi))
@test b == @biginterval(pi)
x = 10238971209348170283710298347019823749182374098172309487120398471029837409182374098127304987123049817032984712039487
@test isequal(@interval(x), @biginterval(x))
@test @interval(x) == @biginterval(x)
@test isthin(@interval(x)) == false

x = 0.1
Expand All @@ -117,14 +114,14 @@ end
a = @interval(0.1)
b = @interval(pi)

@test isequal(a, @floatinterval("0.1"))
@test a == @floatinterval("0.1")
@test typeof(a) == Interval{Float64}
@test nextfloat(a.lo) == a.hi
@test isequal(b, @floatinterval(pi))
@test b == @floatinterval(pi)
@test nextfloat(b.lo) == b.hi
@test isequal(convert(Interval{Float64}, @biginterval(0.1)), a)
@test convert(Interval{Float64}, @biginterval(0.1)) == a
x = typemax(Int64)
@test isequal(@interval(x), @floatinterval(x))
@test @interval(x) == @floatinterval(x)
@test isthin(@interval(x)) == false
x = rand()
c = @interval(x)
Expand All @@ -134,7 +131,7 @@ end
a = @interval("[0.1, 0.2]")
b = @interval(0.1, 0.2)

@test isequal(a, b)
@test a == b

@test_throws ArgumentError @interval("[0.1, 0.2")

Expand Down Expand Up @@ -176,28 +173,24 @@ end

setprecision(Interval, 53)
a = big(1)//3
@test isequal(@interval(a),
Interval(big(3.3333333333333331e-01), big(3.3333333333333337e-01)))
@test @interval(a) == Interval(big(3.3333333333333331e-01), big(3.3333333333333337e-01))
end

@testset "Big intervals" begin
a = @floatinterval(3)
@test typeof(a)== Interval{Float64}
@test typeof(big(a)) == Interval{BigFloat}

@test isequal(@floatinterval(123412341234123412341241234),
Interval(1.234123412341234e26, 1.2341234123412342e26))
@test @floatinterval(123412341234123412341241234) == Interval(1.234123412341234e26, 1.2341234123412342e26)
@test @interval(big"3") == @floatinterval(3)


@test_skip @floatinterval(big"1e10000") == Interval(1.7976931348623157e308, ∞)

a = big(10)^10000
@test isequal(@floatinterval(a), Interval(1.7976931348623157e308, ∞))
@test @floatinterval(a) == Interval(1.7976931348623157e308, ∞)
setprecision(Interval, 53)
@test isequal(@biginterval(a),
Interval(big"9.9999999999999994e+9999",
big"1.0000000000000001e+10000"))
@test @biginterval(a) == Interval(big"9.9999999999999994e+9999", big"1.0000000000000001e+10000")
end

@testset "Complex intervals" begin
Expand All @@ -214,7 +207,7 @@ end
@testset ".. tests" begin

a = 0.1..0.3
@test isequal(a, Interval(0.09999999999999999, 0.30000000000000004))
@test a == Interval(0.09999999999999999, 0.30000000000000004)
@test big"0.1" a
@test big"0.3" a

Expand All @@ -227,13 +220,13 @@ end
@testset "± tests" begin
setprecision(Interval, Float64)

@test 3 ± 1 === Interval(2.0, 4.0)
@test 3 ± 0.5 === 2.5..3.5
@test 3 ± 0.1 === 2.9..3.1
@test 0.5 ± 1 === -0.5..1.5
@test 3 ± 1 == Interval(2.0, 4.0)
@test 3 ± 0.5 == 2.5..3.5
@test 3 ± 0.1 == 2.9..3.1
@test 0.5 ± 1 == -0.5..1.5

# issue 172:
@test (1..1) ± 1 === 0..2
@test (1..1) ± 1 == 0..2

end

Expand Down Expand Up @@ -282,43 +275,43 @@ end
setprecision(Interval, Float64)

@testset "Interval strings" begin
@test I"[1, 2]" === @interval("[1, 2]")
@test I"[2/3, 1.1]" === @interval("[2/3, 1.1]") === Interval(0.6666666666666666, 1.1)
@test I"[1, 2]" == @interval("[1, 2]")
@test I"[2/3, 1.1]" == @interval("[2/3, 1.1]") == Interval(0.6666666666666666, 1.1)
@test I"[1]" == @interval("[1]") == Interval(1.0, 1.0)
@test I"[-0x1.3p-1, 2/3]" === @interval("[-0x1.3p-1, 2/3]") === Interval(-0.59375, 0.6666666666666667)
@test I"[-0x1.3p-1, 2/3]" == @interval("[-0x1.3p-1, 2/3]") == Interval(-0.59375, 0.6666666666666667)
end

@testset "setdiff tests" begin
x = 1..3
y = 2..4
@test isequal(setdiff(x, y), [1..2])
@test isequal(setdiff(y, x), [3..4])
@test setdiff(x, y) == [1..2]
@test setdiff(y, x) == [3..4]

@test isequal(setdiff(x, x), Interval{Float64}[])
@test setdiff(x, x) == Interval{Float64}[]

@test isequal(setdiff(x, emptyinterval(x)), [x])
@test setdiff(x, emptyinterval(x)) == [x]

z = 0..5
@test isequal(setdiff(x, z), Interval{Float64}[])
@test isequal(setdiff(z, x), [0..1, 3..5])
@test setdiff(x, z) == Interval{Float64}[]
@test setdiff(z, x) == [0..1, 3..5]
end

@testset "Interval{T}(x::Interval)" begin
@test Interval{Float64}(3..4) === Interval(3.0, 4.0)
@test isequal(Interval{BigFloat}(3..4), Interval{BigFloat}(3, 4))
@test Interval{Float64}(3..4) == Interval(3.0, 4.0)
@test Interval{BigFloat}(3..4) == Interval{BigFloat}(3, 4)
end

@testset "@interval with fields" begin
a = 3..4
x = @interval(a.lo, 2*a.hi)
@test isequal(x, Interval(3, 8))
@test x == Interval(3, 8)
end

@testset "@interval with user-defined function" begin
f(x) = x==Inf ? one(x) : x/(1+x) # monotonic

x = 3..4
@test isequal(@interval(f(x.lo), f(x.hi)), Interval(0.75, 0.8))
@test @interval(f(x.lo), f(x.hi)) == Interval(0.75, 0.8)
end

@testset "a..b with a > b" begin
Expand Down
24 changes: 12 additions & 12 deletions test/interval_tests/hyperbolic.jl
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ setprecision(Interval, 128)
setprecision(Interval, Float64)

@testset "Hyperb tests" begin
@test sinh(emptyinterval()) === emptyinterval()
@test sinh(Interval(0.5)) === Interval(0.5210953054937473, 0.5210953054937474)
@test sinh(Interval(0.5, 1.67)) === Interval(0.5210953054937473, 2.5619603657712102)
@test sinh(Interval(-4.5, 0.1)) === Interval(-45.00301115199179, 0.10016675001984404)
@test sinh(emptyinterval()) == emptyinterval()
@test sinh(Interval(0.5)) == Interval(0.5210953054937473, 0.5210953054937474)
@test sinh(Interval(0.5, 1.67)) == Interval(0.5210953054937473, 2.5619603657712102)
@test sinh(Interval(-4.5, 0.1)) == Interval(-45.00301115199179, 0.10016675001984404)
@test sinh(@biginterval(0.5)) sinh(@interval(0.5))


Expand All @@ -26,10 +26,10 @@ setprecision(Interval, Float64)
@test sinh(@biginterval(-4.5, 0.1)) sinh(@interval(-4.5, 0.1))
@test sinh(@biginterval(1.3, 6.3)) sinh(@interval(1.3, 6.3))

@test cosh(emptyinterval()) === emptyinterval()
@test cosh(Interval(0.5)) === Interval(1.1276259652063807, 1.127625965206381)
@test cosh(Interval(0.5, 1.67)) === Interval(1.1276259652063807, 2.750207431409957)
@test cosh(Interval(-4.5, 0.1)) === Interval(1.0, 45.01412014853003)
@test cosh(emptyinterval()) == emptyinterval()
@test cosh(Interval(0.5)) == Interval(1.1276259652063807, 1.127625965206381)
@test cosh(Interval(0.5, 1.67)) == Interval(1.1276259652063807, 2.750207431409957)
@test cosh(Interval(-4.5, 0.1)) == Interval(1.0, 45.01412014853003)
@test cosh(@biginterval(0.5)) cosh(@interval(0.5))
@test cosh(@biginterval(0.5, 1.67)) cosh(@interval(0.5, 1.67))
@test cosh(@biginterval(1.67, 3.2)) cosh(@interval(1.67, 3.2))
Expand All @@ -38,10 +38,10 @@ setprecision(Interval, Float64)
@test cosh(@biginterval(-4.5, 0.1)) cosh(@interval(-4.5, 0.1))
@test cosh(@biginterval(1.3, 6.3)) cosh(@interval(1.3, 6.3))

@test tanh(emptyinterval()) === emptyinterval()
@test tanh(Interval(0.5)) === Interval(0.46211715726000974, 0.4621171572600098)
@test tanh(Interval(0.5, 1.67)) === Interval(0.46211715726000974, 0.9315516846152083)
@test tanh(Interval(-4.5, 0.1)) === Interval(-0.9997532108480276, 0.09966799462495583)
@test tanh(emptyinterval()) == emptyinterval()
@test tanh(Interval(0.5)) == Interval(0.46211715726000974, 0.4621171572600098)
@test tanh(Interval(0.5, 1.67)) == Interval(0.46211715726000974, 0.9315516846152083)
@test tanh(Interval(-4.5, 0.1)) == Interval(-0.9997532108480276, 0.09966799462495583)

@test tanh(@biginterval(0.5)) tanh(@interval(0.5))
@test tanh(@biginterval(0.5, 1.67)) tanh(@interval(0.5, 1.67))
Expand Down

0 comments on commit ab77d5e

Please sign in to comment.