Skip to content

Commit fcec1e5

Browse files
committed
add tests
1 parent ede5b5a commit fcec1e5

File tree

1 file changed

+33
-25
lines changed

1 file changed

+33
-25
lines changed

test/hankel_test.jl

Lines changed: 33 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -3,31 +3,39 @@
33
# here we will test just a few cases of the overall hankel function
44
# focusing on negative arguments and reflection
55

6-
v, x = 1.5, 1.3
7-
@test isapprox(hankelh1(v, x), SpecialFunctions.hankelh1(v, x), rtol=2e-13)
8-
@test isapprox(hankelh2(v, x), SpecialFunctions.hankelh2(v, x), rtol=2e-13)
9-
@test isapprox(besselh(v, 1, x), SpecialFunctions.besselh(v, 1, x), rtol=2e-13)
10-
@test isapprox(besselh(v, 2, x), SpecialFunctions.besselh(v, 2, x), rtol=2e-13)
6+
@testset "$T" for T in (Float32, Float64)
7+
rtol = T == Float64 ? 2e-13 : 2e-6
8+
v, x = T(1.5), T(1.3)
9+
@test isapprox(hankelh1(v, x), SpecialFunctions.hankelh1(v, x); rtol)
10+
@test isapprox(hankelh2(v, x), SpecialFunctions.hankelh2(v, x); rtol)
11+
@test isapprox(besselh(v, 1, x), SpecialFunctions.besselh(v, 1, x); rtol)
12+
@test isapprox(besselh(v, 2, x), SpecialFunctions.besselh(v, 2, x); rtol)
13+
@inferred besselh(v, 2, x)
14+
15+
v, x = T(-2.6), T(9.2)
16+
@test isapprox(hankelh1(v, x), SpecialFunctions.hankelh1(v, x); rtol)
17+
@test isapprox(hankelh2(v, x), SpecialFunctions.hankelh2(v, x); rtol)
18+
@test isapprox(besselh(v, 1, x), SpecialFunctions.besselh(v, 1, x); rtol)
19+
@test isapprox(besselh(v, 2, x), SpecialFunctions.besselh(v, 2, x); rtol)
20+
@inferred besselh(v, 2, x)
1121

12-
v, x = -2.6, 9.2
13-
@test isapprox(hankelh1(v, x), SpecialFunctions.hankelh1(v, x), rtol=2e-13)
14-
@test isapprox(hankelh2(v, x), SpecialFunctions.hankelh2(v, x), rtol=2e-13)
15-
@test isapprox(besselh(v, 1, x), SpecialFunctions.besselh(v, 1, x), rtol=2e-13)
16-
@test isapprox(besselh(v, 2, x), SpecialFunctions.besselh(v, 2, x), rtol=2e-13)
22+
v, x = T(-4.0), T(11.4)
23+
@test isapprox(hankelh1(v, x), SpecialFunctions.hankelh1(v, x); rtol)
24+
@test isapprox(hankelh2(v, x), SpecialFunctions.hankelh2(v, x); rtol)
25+
@test isapprox(besselh(v, 1, x), SpecialFunctions.besselh(v, 1, x); rtol)
26+
@test isapprox(besselh(v, 2, x), SpecialFunctions.besselh(v, 2, x); rtol)
27+
@inferred besselh(v, 2, x)
1728

18-
v, x = -4.0, 11.4
19-
@test isapprox(hankelh1(v, x), SpecialFunctions.hankelh1(v, x), rtol=2e-13)
20-
@test isapprox(hankelh2(v, x), SpecialFunctions.hankelh2(v, x), rtol=2e-13)
21-
@test isapprox(besselh(v, 1, x), SpecialFunctions.besselh(v, 1, x), rtol=2e-13)
22-
@test isapprox(besselh(v, 2, x), SpecialFunctions.besselh(v, 2, x), rtol=2e-13)
29+
v, x = T(14.3), T(29.4)
30+
@test isapprox(hankelh1(v, x), SpecialFunctions.hankelh1(v, x); rtol)
31+
@test isapprox(hankelh2(v, x), SpecialFunctions.hankelh2(v, x); rtol)
32+
@test isapprox(besselh(v, 1, x), SpecialFunctions.besselh(v, 1, x); rtol)
33+
@test isapprox(besselh(v, 2, x), SpecialFunctions.besselh(v, 2, x); rtol)
34+
@inferred besselh(v, 2, x)
2335

24-
v, x = 14.3, 29.4
25-
@test isapprox(hankelh1(v, x), SpecialFunctions.hankelh1(v, x), rtol=2e-13)
26-
@test isapprox(hankelh2(v, x), SpecialFunctions.hankelh2(v, x), rtol=2e-13)
27-
@test isapprox(besselh(v, 1, x), SpecialFunctions.besselh(v, 1, x), rtol=2e-13)
28-
@test isapprox(besselh(v, 2, x), SpecialFunctions.besselh(v, 2, x), rtol=2e-13)
29-
30-
@test isapprox(hankelh1(1:50, 10.0), SpecialFunctions.hankelh1.(1:50, 10.0), rtol=2e-13)
31-
@test isapprox(hankelh1(0.5:1:25.5, 15.0), SpecialFunctions.hankelh1.(0.5:1:25.5, 15.0), rtol=2e-13)
32-
@test isapprox(hankelh1(1:50, 100.0), SpecialFunctions.hankelh1.(1:50, 100.0), rtol=2e-13)
33-
@test isapprox(hankelh2(1:50, 10.0), SpecialFunctions.hankelh2.(1:50, 10.0), rtol=2e-13)
36+
@test isapprox(hankelh1(1:50, T(10)), SpecialFunctions.hankelh1.(1:50, 10.0); rtol)
37+
@test isapprox(hankelh1(T(0.5):T(25.5), T(15)), SpecialFunctions.hankelh1.(0.5:1:25.5, 15.0); rtol)
38+
@test isapprox(hankelh1(1:50, T(100)), SpecialFunctions.hankelh1.(1:50, 100.0); 2*rtol)
39+
@test isapprox(hankelh2(1:50, T(10)), SpecialFunctions.hankelh2.(1:50, 10.0); rtol)
40+
@inferred hankelh2(1:50, T(10))
41+
end

0 commit comments

Comments
 (0)