2020class TestBesselFunctions :
2121 """Validate Bessel-related function values against reference data."""
2222
23- def setup_method (self ):
24- """Set a shared complex argument and numerical tolerance."""
25- self .z = 1.5 - 0.5j
26- self .tolerance = 1e-5
23+ Z = 1.5 - 0.5j
24+ TOLERANCE = 1e-5
2725
2826 def test_spherical_h1 (self ):
2927 """Check spherical Hankel function of the first kind."""
@@ -36,9 +34,9 @@ def test_spherical_h1(self):
3634 ]
3735
3836 for n in range (4 ):
39- result = spherical_h1 (n , self .z )
40- assert result .real == pytest .approx (expected [n ].real , abs = self .tolerance )
41- assert result .imag == pytest .approx (expected [n ].imag , abs = self .tolerance )
37+ result = spherical_h1 (n , self .Z )
38+ assert result .real == pytest .approx (expected [n ].real , abs = self .TOLERANCE )
39+ assert result .imag == pytest .approx (expected [n ].imag , abs = self .TOLERANCE )
4240
4341 def test_spherical_h2 (self ):
4442 """Check spherical Hankel function of the second kind."""
@@ -51,9 +49,9 @@ def test_spherical_h2(self):
5149 ]
5250
5351 for n in range (4 ):
54- result = spherical_h2 (n , self .z )
55- assert result .real == pytest .approx (expected [n ].real , abs = self .tolerance )
56- assert result .imag == pytest .approx (expected [n ].imag , abs = self .tolerance )
52+ result = spherical_h2 (n , self .Z )
53+ assert result .real == pytest .approx (expected [n ].real , abs = self .TOLERANCE )
54+ assert result .imag == pytest .approx (expected [n ].imag , abs = self .TOLERANCE )
5755
5856 def test_riccati_bessel_jn (self ):
5957 """Check Riccati-Bessel j_n values."""
@@ -66,9 +64,9 @@ def test_riccati_bessel_jn(self):
6664 ]
6765
6866 for n in range (4 ):
69- result = riccati_bessel_jn (n , self .z )
70- assert result .real == pytest .approx (expected [n ].real , abs = self .tolerance )
71- assert result .imag == pytest .approx (expected [n ].imag , abs = self .tolerance )
67+ result = riccati_bessel_jn (n , self .Z )
68+ assert result .real == pytest .approx (expected [n ].real , abs = self .TOLERANCE )
69+ assert result .imag == pytest .approx (expected [n ].imag , abs = self .TOLERANCE )
7270
7371 def test_riccati_bessel_h1 (self ):
7472 """Check Riccati-Bessel h_n^(1) values."""
@@ -81,9 +79,9 @@ def test_riccati_bessel_h1(self):
8179 ]
8280
8381 for n in range (4 ):
84- result = riccati_bessel_h1 (n , self .z )
85- assert result .real == pytest .approx (expected [n ].real , abs = self .tolerance )
86- assert result .imag == pytest .approx (expected [n ].imag , abs = self .tolerance )
82+ result = riccati_bessel_h1 (n , self .Z )
83+ assert result .real == pytest .approx (expected [n ].real , abs = self .TOLERANCE )
84+ assert result .imag == pytest .approx (expected [n ].imag , abs = self .TOLERANCE )
8785
8886 def test_riccati_bessel_h2 (self ):
8987 """Check Riccati-Bessel h_n^(2) values."""
@@ -96,9 +94,9 @@ def test_riccati_bessel_h2(self):
9694 ]
9795
9896 for n in range (4 ):
99- result = riccati_bessel_h2 (n , self .z )
100- assert result .real == pytest .approx (expected [n ].real , abs = self .tolerance )
101- assert result .imag == pytest .approx (expected [n ].imag , abs = self .tolerance )
97+ result = riccati_bessel_h2 (n , self .Z )
98+ assert result .real == pytest .approx (expected [n ].real , abs = self .TOLERANCE )
99+ assert result .imag == pytest .approx (expected [n ].imag , abs = self .TOLERANCE )
102100
103101 def test_d_spherical_jn (self ):
104102 """Check derivatives of spherical Bessel j_n."""
@@ -111,9 +109,9 @@ def test_d_spherical_jn(self):
111109 ]
112110
113111 for n in range (0 , 4 ):
114- result = d_spherical_jn (n , self .z )
115- assert result .real == pytest .approx (expected [n ].real , abs = self .tolerance )
116- assert result .imag == pytest .approx (expected [n ].imag , abs = self .tolerance )
112+ result = d_spherical_jn (n , self .Z )
113+ assert result .real == pytest .approx (expected [n ].real , abs = self .TOLERANCE )
114+ assert result .imag == pytest .approx (expected [n ].imag , abs = self .TOLERANCE )
117115
118116 def test_d_spherical_h1 (self ):
119117 """Check derivatives of spherical Hankel h_n^(1)."""
@@ -126,9 +124,9 @@ def test_d_spherical_h1(self):
126124 ]
127125
128126 for n in range (1 , 4 ):
129- result = d_spherical_h1 (n , self .z )
130- assert result .real == pytest .approx (expected [n ].real , abs = self .tolerance )
131- assert result .imag == pytest .approx (expected [n ].imag , abs = self .tolerance )
127+ result = d_spherical_h1 (n , self .Z )
128+ assert result .real == pytest .approx (expected [n ].real , abs = self .TOLERANCE )
129+ assert result .imag == pytest .approx (expected [n ].imag , abs = self .TOLERANCE )
132130
133131 def test_d_spherical_h2 (self ):
134132 """Check derivatives of spherical Hankel h_n^(2)."""
@@ -141,9 +139,9 @@ def test_d_spherical_h2(self):
141139 ]
142140
143141 for n in range (1 , 4 ):
144- result = d_spherical_h2 (n , self .z )
145- assert result .real == pytest .approx (expected [n ].real , abs = self .tolerance )
146- assert result .imag == pytest .approx (expected [n ].imag , abs = self .tolerance )
142+ result = d_spherical_h2 (n , self .Z )
143+ assert result .real == pytest .approx (expected [n ].real , abs = self .TOLERANCE )
144+ assert result .imag == pytest .approx (expected [n ].imag , abs = self .TOLERANCE )
147145
148146 def test_d_riccati_bessel_jn (self ):
149147 """Check derivatives of Riccati-Bessel j_n."""
@@ -156,9 +154,9 @@ def test_d_riccati_bessel_jn(self):
156154 ]
157155
158156 for n in range (4 ):
159- result = d_riccati_bessel_jn (n , self .z )
160- assert result .real == pytest .approx (expected [n ].real , abs = self .tolerance )
161- assert result .imag == pytest .approx (expected [n ].imag , abs = self .tolerance )
157+ result = d_riccati_bessel_jn (n , self .Z )
158+ assert result .real == pytest .approx (expected [n ].real , abs = self .TOLERANCE )
159+ assert result .imag == pytest .approx (expected [n ].imag , abs = self .TOLERANCE )
162160
163161 def test_d_riccati_bessel_h1 (self ):
164162 """Check derivatives of Riccati-Bessel h_n^(1)."""
@@ -171,9 +169,9 @@ def test_d_riccati_bessel_h1(self):
171169 ]
172170
173171 for n in range (1 , 4 ):
174- result = d_riccati_bessel_h1 (n , self .z )
175- assert result .real == pytest .approx (expected [n ].real , abs = self .tolerance )
176- assert result .imag == pytest .approx (expected [n ].imag , abs = self .tolerance )
172+ result = d_riccati_bessel_h1 (n , self .Z )
173+ assert result .real == pytest .approx (expected [n ].real , abs = self .TOLERANCE )
174+ assert result .imag == pytest .approx (expected [n ].imag , abs = self .TOLERANCE )
177175
178176 def test_d_riccati_bessel_h2 (self ):
179177 """Check derivatives of Riccati-Bessel h_n^(2)."""
@@ -186,24 +184,18 @@ def test_d_riccati_bessel_h2(self):
186184 ]
187185
188186 for n in range (1 , 4 ):
189- result = d_riccati_bessel_h2 (n , self .z )
190- assert result .real == pytest .approx (expected [n ].real , abs = self .tolerance )
191- assert result .imag == pytest .approx (expected [n ].imag , abs = self .tolerance )
192-
193-
194- class TestAsymptotic :
195- """Validate large-argument asymptotic behavior."""
196-
197- def setup_method (self ):
198- """Set a large argument for asymptotic comparisons."""
199- self .z = 1000
200- self .tolerance = 1e-5
201-
202- def test_spherical_h1 (self ):
203- """Check h_n^(1) against the large-argument asymptotic form."""
204- expected = np .exp (1j * self .z ) / (1j * self .z )
205- for n in range (1 , 4 ):
206- expected = (- 1j ) ** n * np .exp (1j * self .z ) / (1j * self .z )
207- result = spherical_h1 (n , self .z )
208- assert result .real == pytest .approx (expected .real , abs = self .tolerance )
209- assert result .imag == pytest .approx (expected .imag , abs = self .tolerance )
187+ result = d_riccati_bessel_h2 (n , self .Z )
188+ assert result .real == pytest .approx (expected [n ].real , abs = self .TOLERANCE )
189+ assert result .imag == pytest .approx (expected [n ].imag , abs = self .TOLERANCE )
190+
191+
192+ def test_asymptotic_spherical_h1 ():
193+ """Check h_n^(1) against the large-argument asymptotic form."""
194+ z = 1000
195+ tolerance = 1e-5
196+ expected = np .exp (1j * z ) / (1j * z )
197+ for n in range (1 , 4 ):
198+ expected = (- 1j ) ** n * np .exp (1j * z ) / (1j * z )
199+ result = spherical_h1 (n , z )
200+ assert result .real == pytest .approx (expected .real , abs = tolerance )
201+ assert result .imag == pytest .approx (expected .imag , abs = tolerance )
0 commit comments