Skip to content

Commit 09ab3f0

Browse files
author
Luis Benet
committed
Added tests (julia)
1 parent 5f46ff5 commit 09ab3f0

File tree

1 file changed

+98
-0
lines changed

1 file changed

+98
-0
lines changed

src/julia/runtests.jl

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
# Simple tests for Intervals
2+
using Intervals
3+
using Base.Test
4+
5+
a = Interval(1.1,0.1)
6+
b = Interval(0.9,2.0)
7+
c = Interval(0.25,4.0)
8+
9+
@test isa(Interval(1,2),Interval)
10+
@test isa(Interval(BigFloat("0.1")),Interval)
11+
@test zero(b) == 0.0
12+
@test one(a) == BigFloat("1.0")
13+
@test !(a == b)
14+
@test a != b
15+
@test 1 == zero(a)+one(b)
16+
@test Interval(0.25)-one(c)/4 == zero(c)
17+
@test isempty(a,Interval(-1))
18+
19+
@test Interval(0.1) == Interval(0.0999999999999999999,0.1)
20+
@test a == Interval(a.lo,a.hi)
21+
@test a+b == Interval(0.9999999999999999,3.1)
22+
@test -a == Interval(-1.1,-0.0999999999999999999)
23+
@test a-b == Interval(BigFloat("-1.9000000000000001e+00"), BigFloat("2.0000000000000018e-01"))
24+
@test a*b == Interval(a.lo*b.lo, a.hi*b.hi)
25+
@test 10a == Interval(BigFloat("9.9999999999999989e-01"), BigFloat("1.1000000000000002e+01"))
26+
@test b/a == Interval(BigFloat("8.181818181818179e-01"), BigFloat("2.0000000000000004e+01"))
27+
@test a/c == Interval(BigFloat("0.024999999999999998"),BigFloat("4.4"))
28+
@test c/4.0 == Interval(0.0625,1.0)
29+
30+
@test inv(zero(a)) == Interval(Inf,Inf)
31+
@test inv(Interval(0,1)) == Interval(1,Inf)
32+
@test inv(Interval(1,Inf)) == Interval(0,1)
33+
@test inv(c) == c
34+
@test one(a)/b == inv(b)
35+
36+
@test Interval(-3,2)^2 == Interval(0,9)
37+
@test Interval(-3,2)^3 == Interval(-27,8)
38+
@test Interval(-3,4)^0.5 == Interval(0,2) == Interval(-3,4)^(1//2)
39+
@test Interval(1,27)^Interval(1//3) == Interval(1,3)
40+
@test Interval(-3,2)^Interval(2) == Interval(0,9)
41+
@test Interval(-3,4)^Interval(0.5) == Interval(0,2)
42+
@test Interval(0.1,0.7)^(1/3) ==
43+
Interval(BigFloat("4.6415888336127786e-01"), BigFloat("8.8790400174260076e-01"))
44+
45+
@test inv(zero(a)) == Interval(Inf,Inf)
46+
@test inv(Interval(0,1)) == Interval(1,Inf)
47+
@test inv(Interval(1,Inf)) == Interval(0,1)
48+
@test inv(c) == c
49+
@test one(a)/b == inv(b)
50+
51+
@test in(0.1,Interval(0.1))
52+
@test !isinside(0.1,Interval(0.1))
53+
@test intersect(a,Interval(-1)) == nothing
54+
@test intersect(a,hull(a,b)) == a
55+
@test union(a,b) == Interval(a.lo,b.hi)
56+
57+
@test diam( Interval(1//2) ) == zero(BigFloat)
58+
@test diam( Interval(0.1) ) == eps(0.1)
59+
@test mig(Interval(-2,2)) == BigFloat(0.0)
60+
@test mag(-b) == b.hi
61+
@test diam(a) == a.hi - a.lo
62+
63+
@test exp(Interval(1//2)) ==
64+
Interval(BigFloat("1.648721270700128e+00"), BigFloat("1.6487212707001282e+00"))
65+
@test exp(Interval(0.1)) ==
66+
Interval(BigFloat("1.1051709180756475e+00"), BigFloat("1.1051709180756477e+00"))
67+
@test diam(exp(Interval(0.1))) == eps(exp(0.1))
68+
@test log(Interval(1//2)) ==
69+
Interval(BigFloat("-6.931471805599454e-01"), BigFloat("-6.9314718055994529e-01"))
70+
@test log(Interval(0.1)) ==
71+
Interval(BigFloat("-2.3025850929940459e+00"), BigFloat("-2.3025850929940455e+00"))
72+
@test diam(log(Interval(0.1))) == eps(log(0.1))
73+
@test log(Interval(-2,5)) == Interval(-Inf,log(5.0))
74+
75+
@test sin(Interval(0.5)) ==
76+
Interval(BigFloat("0.47942553860420295"), BigFloat("0.47942553860420301"))
77+
@test sin(Interval(0.5, 1.67)) ==
78+
Interval(BigFloat("4.7942553860420295e-01"), BigFloat("1.0"))
79+
@test sin(Interval(1.67,3.2)) ==
80+
Interval(BigFloat("-5.8374143427580093e-02"), BigFloat("9.9508334981018021e-01"))
81+
@test sin(Interval(2.1, 5.6)) ==
82+
Interval(BigFloat("-1.0"), BigFloat("8.6320936664887404e-01"))
83+
@test sin(Interval(0.5,8.5)) == Interval(-1.0, 1.0)
84+
@test cos(Interval(0.5)) ==
85+
Interval(BigFloat("0.87758256189037265"), BigFloat("0.87758256189037276"))
86+
@test cos(Interval(0.5,1.67)) ==
87+
Interval(BigFloat("-0.099041036598728246"), BigFloat("0.87758256189037276"))
88+
@test cos(Interval(2.1, 5.6)) ==
89+
Interval(BigFloat("-1.0"), BigFloat("0.77556587851025016"))
90+
@test cos(Interval(0.5,8.5)) == Interval(BigFloat("-1.0"), BigFloat("1.0"))
91+
@test cos(Interval(1.67,3.2)) == Interval(BigFloat("-1.0"), BigFloat("-0.099041036598728011"))
92+
@test tan(Interval(0.5)) ==
93+
Interval(BigFloat("0.54630248984379048"), BigFloat("0.5463024898437906"))
94+
@test tan(Interval(0.5,1.67)) == Interval(BigFloat("-inf"), BigFloat("inf"))
95+
@test tan(Interval(1.67, 3.2)) ==
96+
Interval(BigFloat("-10.047182299210307"), BigFloat("0.058473854459578652"))
97+
98+
println(" \033[32;1mSUCCESS\033[0m")

0 commit comments

Comments
 (0)