Skip to content

Commit 84f6f55

Browse files
authored
split tests into components (#211)
1 parent 69b7a2e commit 84f6f55

File tree

7 files changed

+801
-792
lines changed

7 files changed

+801
-792
lines changed

test/bessel.jl

Lines changed: 247 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,247 @@
1+
@testset "airy" begin
2+
@test_throws AmosException airyai(200im)
3+
@test_throws AmosException airybi(200)
4+
5+
for T in [Float16, Float32, Float64,Complex{Float16}, Complex{Float32},Complex{Float64}]
6+
@test airyai(T(1.8)) 0.0470362168668458052247
7+
@test airyaiprime(T(1.8)) -0.0685247801186109345638
8+
@test airybi(T(1.8)) 2.595869356743906290060
9+
@test airybiprime(T(1.8)) 2.98554005084659907283
10+
end
11+
for T in [Complex{Float16}, Complex{Float32}, Complex{Float64}]
12+
z = convert(T,1.8 + 1.0im)
13+
@test airyaix(z) airyai(z) * exp(2/3 * z * sqrt(z))
14+
@test airyaiprimex(z) airyaiprime(z) * exp(2/3 * z * sqrt(z))
15+
@test airybix(z) airybi(z) * exp(-abs(real(2/3 * z * sqrt(z))))
16+
@test airybiprimex(z) airybiprime(z) * exp(-abs(real(2/3 * z * sqrt(z))))
17+
end
18+
@test_throws MethodError airyai(complex(big(1.0)))
19+
20+
for x = -3:3
21+
@test airyai(x) airyai(complex(x))
22+
@test airyaiprime(x) airyaiprime(complex(x))
23+
@test airybi(x) airybi(complex(x))
24+
@test airybiprime(x) airybiprime(complex(x))
25+
if x >= 0
26+
@test airyaix(x) airyaix(complex(x))
27+
@test airyaiprimex(x) airyaiprimex(complex(x))
28+
else
29+
@test_throws DomainError airyaix(x)
30+
@test_throws DomainError airyaiprimex(x)
31+
end
32+
@test airybix(x) airybix(complex(x))
33+
@test airybiprimex(x) airybiprimex(complex(x))
34+
end
35+
end
36+
37+
@testset "bessel functions" begin
38+
bessel_funcs = [(bessely0, bessely1, bessely), (besselj0, besselj1, besselj)]
39+
@testset "$z, $o" for (z, o, f) in bessel_funcs
40+
@test z(Float32(2.0)) z(Float64(2.0))
41+
@test o(Float32(2.0)) o(Float64(2.0))
42+
@test z(Float16(2.0)) z(Float64(2.0))
43+
@test o(Float16(2.0)) o(Float64(2.0))
44+
@test z(2) z(2.0)
45+
@test o(2) o(2.0)
46+
@test z(2.0 + im) f(0, 2.0 + im)
47+
@test o(2.0 + im) f(1, 2.0 + im)
48+
end
49+
@testset "besselj error throwing" begin
50+
@test_throws MethodError besselj(1.2,big(1.0))
51+
@test_throws MethodError besselj(1,complex(big(1.0)))
52+
@test_throws MethodError besseljx(1,big(1.0))
53+
@test_throws MethodError besseljx(1,complex(big(1.0)))
54+
end
55+
@testset "besselh" begin
56+
true_h133 = 0.30906272225525164362 - 0.53854161610503161800im
57+
@test besselh(3,1,3) true_h133
58+
@test besselh(-3,1,3) -true_h133
59+
@test besselh(Float32(3),1,Float32(3)) true_h133
60+
@test besselh(Float16(3),1,Float16(3)) true_h133
61+
@test besselh(3,2,3) conj(true_h133)
62+
@test besselh(-3,2,3) -conj(true_h133)
63+
@test besselh(1,1,0) complex(0,-Inf)
64+
@test besselh(1,2,0) complex(0,Inf)
65+
@testset "Error throwing" begin
66+
@test_throws AmosException besselh(1,5,0)
67+
@test_throws MethodError besselh(1,big(1.0))
68+
@test_throws MethodError besselh(1,complex(big(1.0)))
69+
@test_throws MethodError besselhx(1,big(1.0))
70+
@test_throws MethodError besselhx(1,complex(big(1.0)))
71+
end
72+
end
73+
@testset "besseli" begin
74+
true_i33 = 0.95975362949600785698
75+
@test besseli(3,3) true_i33
76+
@test besseli(-3,3) true_i33
77+
@test besseli(3,-3) -true_i33
78+
@test besseli(-3,-3) -true_i33
79+
@test besseli(Float32(-3),Complex{Float32}(-3,0)) -true_i33
80+
@test besseli(Float16(-3),Complex{Float16}(-3,0)) -true_i33
81+
true_im3p1_3 = 0.84371226532586351965
82+
@test besseli(-3.1,3) true_im3p1_3
83+
for i in [-5 -3 -1 1 3 5]
84+
@test besseli(i,0) == 0.0
85+
@test besseli(i,Float32(0)) == 0
86+
@test besseli(i,Complex{Float32}(0)) == 0
87+
@test besseli(i,Float16(0)) == 0
88+
@test besseli(i,Complex{Float16}(0)) == 0
89+
end
90+
@testset "Error throwing" begin
91+
@test_throws AmosException besseli(1,1000)
92+
@test_throws DomainError besseli(0.4,-1.0)
93+
@test_throws MethodError besseli(1,big(1.0))
94+
@test_throws MethodError besseli(1,complex(big(1.0)))
95+
@test_throws MethodError besselix(1,big(1.0))
96+
@test_throws MethodError besselix(1,complex(big(1.0)))
97+
end
98+
end
99+
@testset "besselj" begin
100+
@test besselj(0,0) == 1
101+
for i in [-5 -3 -1 1 3 5]
102+
@test besselj(i,0) == 0
103+
@test besselj(i,Float32(0)) == 0
104+
@test besselj(i,Complex{Float32}(0)) == 0.0
105+
end
106+
107+
j33 = besselj(3,3.)
108+
@test besselj(3,3) == j33
109+
@test besselj(-3,-3) == j33
110+
@test besselj(-3,3) == -j33
111+
@test besselj(3,-3) == -j33
112+
@test besselj(3,3f0) j33
113+
@test besselj(3,complex(3.)) j33
114+
@test besselj(3,complex(3f0)) j33
115+
@test besselj(3,complex(3)) j33
116+
117+
j43 = besselj(4,3.)
118+
@test besselj(4,3) == j43
119+
@test besselj(-4,-3) == j43
120+
@test besselj(-4,3) == j43
121+
@test besselj(4,-3) == j43
122+
@test besselj(4,3f0) j43
123+
@test besselj(4,complex(3.)) j43
124+
@test besselj(4,complex(3f0)) j43
125+
@test besselj(4,complex(3)) j43
126+
127+
@test j33 0.30906272225525164362
128+
@test j43 0.13203418392461221033
129+
@test besselj(0.1, complex(-0.4)) 0.820421842809028916 + 0.266571215948350899im
130+
@test besselj(3.2, 1.3+0.6im) 0.01135309305831220201 + 0.03927719044393515275im
131+
@test besselj(1, 3im) 3.953370217402609396im
132+
@test besselj(1.0,3im) besselj(1,3im)
133+
134+
true_jm3p1_3 = -0.45024252862270713882
135+
@test besselj(-3.1,3) true_jm3p1_3
136+
@test besselj(Float16(-3.1),Float16(3)) true_jm3p1_3
137+
138+
@testset "Error throwing" begin
139+
@test_throws DomainError besselj(0.1, -0.4)
140+
@test_throws AmosException besselj(20,1000im)
141+
@test_throws MethodError besselj(big(1.0),3im)
142+
end
143+
end
144+
145+
@testset "besselk" begin
146+
true_k33 = 0.12217037575718356792
147+
@test besselk(3,3) true_k33
148+
@test besselk(Float32(3),Float32(3)) true_k33
149+
@test besselk(Float16(3),Float16(3)) true_k33
150+
@test besselk(-3,3) true_k33
151+
true_k3m3 = -0.1221703757571835679 - 3.0151549516807985776im
152+
@test besselk(3,complex(-3)) true_k3m3
153+
@test besselk(-3,complex(-3)) true_k3m3
154+
# issue #6564
155+
@test besselk(1.0,0.0) == Inf
156+
@testset "Error throwing" begin
157+
@test_throws AmosException besselk(200,0.01)
158+
@test_throws DomainError besselk(3,-3)
159+
@test_throws MethodError besselk(1,big(1.0))
160+
@test_throws MethodError besselk(1,complex(big(1.0)))
161+
@test_throws MethodError besselkx(1,big(1.0))
162+
@test_throws MethodError besselkx(1,complex(big(1.0)))
163+
end
164+
end
165+
166+
@testset "bessely" begin
167+
y33 = bessely(3,3.)
168+
@test bessely(3,3) == y33
169+
@test bessely(3.,3.) == y33
170+
@test bessely(3,Float32(3.)) y33
171+
@test bessely(-3,3) -y33
172+
@test y33 -0.53854161610503161800
173+
@test bessely(3,complex(-3)) 0.53854161610503161800 - 0.61812544451050328724im
174+
@testset "Error throwing" begin
175+
@test_throws AmosException bessely(200.5,0.1)
176+
@test_throws DomainError bessely(3,-3)
177+
@test_throws DomainError bessely(0.4,-1.0)
178+
@test_throws DomainError bessely(0.4,Float32(-1.0))
179+
@test_throws DomainError bessely(1,Float32(-1.0))
180+
@test_throws DomainError bessely(0.4,BigFloat(-1.0))
181+
@test_throws DomainError bessely(1,BigFloat(-1.0))
182+
@test_throws DomainError bessely(Cint(3),Float32(-3.))
183+
@test_throws DomainError bessely(Cint(3),Float64(-3.))
184+
185+
@test_throws MethodError bessely(1.2,big(1.0))
186+
@test_throws MethodError bessely(1,complex(big(1.0)))
187+
@test_throws MethodError besselyx(1,big(1.0))
188+
@test_throws MethodError besselyx(1,complex(big(1.0)))
189+
end
190+
end
191+
192+
@testset "besselhx" begin
193+
for elty in [Complex{Float16},Complex{Float32},Complex{Float64}]
194+
z = convert(elty, 1.0 + 1.9im)
195+
@test besselhx(1.0, 1, z) convert(elty,-0.5949634147786144 - 0.18451272807835967im)
196+
@test besselhx(Float32(1.0), 1, z) convert(elty,-0.5949634147786144 - 0.18451272807835967im)
197+
end
198+
@testset "Error throwing" begin
199+
@test_throws MethodError besselh(1,1,big(1.0))
200+
@test_throws MethodError besselh(1,1,complex(big(1.0)))
201+
@test_throws MethodError besselhx(1,1,big(1.0))
202+
@test_throws MethodError besselhx(1,1,complex(big(1.0)))
203+
end
204+
end
205+
@testset "scaled bessel[ijky] and hankelh[12]" begin
206+
for x in (1.0, 0.0, -1.0), y in (1.0, 0.0, -1.0), nu in (1.0, 0.0, -1.0)
207+
z = Complex{Float64}(x + y * im)
208+
z == zero(z) || @test hankelh1x(nu, z) hankelh1(nu, z) * exp(-z * im)
209+
z == zero(z) || @test hankelh2x(nu, z) hankelh2(nu, z) * exp(z * im)
210+
(nu < 0 && z == zero(z)) || @test besselix(nu, z) besseli(nu, z) * exp(-abs(real(z)))
211+
(nu < 0 && z == zero(z)) || @test besseljx(nu, z) besselj(nu, z) * exp(-abs(imag(z)))
212+
z == zero(z) || @test besselkx(nu, z) besselk(nu, z) * exp(z)
213+
z == zero(z) || @test besselyx(nu, z) bessely(nu, z) * exp(-abs(imag(z)))
214+
end
215+
@test besselkx(1, 0) == Inf
216+
for i = [-5 -3 -1 1 3 5]
217+
@test besseljx(i,0) == 0
218+
@test besselix(i,0) == 0
219+
@test besseljx(i,Float32(0)) == 0
220+
@test besselix(i,Float32(0)) == 0
221+
@test besseljx(i,Complex{Float32}(0)) == 0
222+
@test besselix(i,Complex{Float32}(0)) == 0
223+
@test besseljx(i,Float16(0)) == 0
224+
@test besselix(i,Float16(0)) == 0
225+
@test besseljx(i,Complex{Float16}(0)) == 0
226+
@test besselix(i,Complex{Float16}(0)) == 0
227+
end
228+
@testset "Error throwing" begin
229+
@test_throws AmosException hankelh1x(1, 0)
230+
@test_throws AmosException hankelh2x(1, 0)
231+
@test_throws AmosException besselix(-1.01, 0)
232+
@test_throws AmosException besseljx(-1.01, 0)
233+
@test_throws AmosException besselyx(1, 0)
234+
@test_throws DomainError besselix(0.4,-1.0)
235+
@test_throws DomainError besseljx(0.4, -1.0)
236+
@test_throws DomainError besselkx(0.4,-1.0)
237+
@test_throws DomainError besselyx(0.4,-1.0)
238+
end
239+
end
240+
@testset "issue #6653" begin
241+
@testset "$f" for f in (besselj,bessely,besseli,besselk,hankelh1,hankelh2)
242+
@test f(0,1) f(0,Complex{Float64}(1))
243+
@test f(0,1) f(0,Complex{Float32}(1))
244+
@test f(0,1) f(0,Complex{Float16}(1))
245+
end
246+
end
247+
end

0 commit comments

Comments
 (0)