11"""Regression tests for spherical and Riccati-Bessel helper functions."""
22
3- import unittest
3+ import pytest
44import numpy as np
55from miepython .bessel import (
66 d_riccati_bessel_h1 ,
1717)
1818
1919
20- class TestBesselFunctions ( unittest . TestCase ) :
20+ class TestBesselFunctions :
2121 """Validate Bessel-related function values against reference data."""
2222
23- def setUp (self ):
23+ def setup_method (self ):
2424 """Set a shared complex argument and numerical tolerance."""
2525 self .z = 1.5 - 0.5j
2626 self .tolerance = 1e-5
@@ -37,8 +37,8 @@ def test_spherical_h1(self):
3737
3838 for n in range (4 ):
3939 result = spherical_h1 (n , self .z )
40- self . assertAlmostEqual ( result .real , expected [n ].real , delta = self .tolerance )
41- self . assertAlmostEqual ( result .imag , expected [n ].imag , delta = self .tolerance )
40+ assert result .real == pytest . approx ( expected [n ].real , abs = self .tolerance )
41+ assert result .imag == pytest . approx ( expected [n ].imag , abs = self .tolerance )
4242
4343 def test_spherical_h2 (self ):
4444 """Check spherical Hankel function of the second kind."""
@@ -52,8 +52,8 @@ def test_spherical_h2(self):
5252
5353 for n in range (4 ):
5454 result = spherical_h2 (n , self .z )
55- self . assertAlmostEqual ( result .real , expected [n ].real , delta = self .tolerance )
56- self . assertAlmostEqual ( result .imag , expected [n ].imag , delta = self .tolerance )
55+ assert result .real == pytest . approx ( expected [n ].real , abs = self .tolerance )
56+ assert result .imag == pytest . approx ( expected [n ].imag , abs = self .tolerance )
5757
5858 def test_riccati_bessel_jn (self ):
5959 """Check Riccati-Bessel j_n values."""
@@ -67,8 +67,8 @@ def test_riccati_bessel_jn(self):
6767
6868 for n in range (4 ):
6969 result = riccati_bessel_jn (n , self .z )
70- self . assertAlmostEqual ( result .real , expected [n ].real , delta = self .tolerance )
71- self . assertAlmostEqual ( result .imag , expected [n ].imag , delta = self .tolerance )
70+ assert result .real == pytest . approx ( expected [n ].real , abs = self .tolerance )
71+ assert result .imag == pytest . approx ( expected [n ].imag , abs = self .tolerance )
7272
7373 def test_riccati_bessel_h1 (self ):
7474 """Check Riccati-Bessel h_n^(1) values."""
@@ -82,8 +82,8 @@ def test_riccati_bessel_h1(self):
8282
8383 for n in range (4 ):
8484 result = riccati_bessel_h1 (n , self .z )
85- self . assertAlmostEqual ( result .real , expected [n ].real , delta = self .tolerance )
86- self . assertAlmostEqual ( result .imag , expected [n ].imag , delta = self .tolerance )
85+ assert result .real == pytest . approx ( expected [n ].real , abs = self .tolerance )
86+ assert result .imag == pytest . approx ( expected [n ].imag , abs = self .tolerance )
8787
8888 def test_riccati_bessel_h2 (self ):
8989 """Check Riccati-Bessel h_n^(2) values."""
@@ -97,8 +97,8 @@ def test_riccati_bessel_h2(self):
9797
9898 for n in range (4 ):
9999 result = riccati_bessel_h2 (n , self .z )
100- self . assertAlmostEqual ( result .real , expected [n ].real , delta = self .tolerance )
101- self . assertAlmostEqual ( result .imag , expected [n ].imag , delta = self .tolerance )
100+ assert result .real == pytest . approx ( expected [n ].real , abs = self .tolerance )
101+ assert result .imag == pytest . approx ( expected [n ].imag , abs = self .tolerance )
102102
103103 def test_d_spherical_jn (self ):
104104 """Check derivatives of spherical Bessel j_n."""
@@ -112,8 +112,8 @@ def test_d_spherical_jn(self):
112112
113113 for n in range (0 , 4 ):
114114 result = d_spherical_jn (n , self .z )
115- self . assertAlmostEqual ( result .real , expected [n ].real , delta = self .tolerance )
116- self . assertAlmostEqual ( result .imag , expected [n ].imag , delta = self .tolerance )
115+ assert result .real == pytest . approx ( expected [n ].real , abs = self .tolerance )
116+ assert result .imag == pytest . approx ( expected [n ].imag , abs = self .tolerance )
117117
118118 def test_d_spherical_h1 (self ):
119119 """Check derivatives of spherical Hankel h_n^(1)."""
@@ -127,8 +127,8 @@ def test_d_spherical_h1(self):
127127
128128 for n in range (1 , 4 ):
129129 result = d_spherical_h1 (n , self .z )
130- self . assertAlmostEqual ( result .real , expected [n ].real , delta = self .tolerance )
131- self . assertAlmostEqual ( result .imag , expected [n ].imag , delta = self .tolerance )
130+ assert result .real == pytest . approx ( expected [n ].real , abs = self .tolerance )
131+ assert result .imag == pytest . approx ( expected [n ].imag , abs = self .tolerance )
132132
133133 def test_d_spherical_h2 (self ):
134134 """Check derivatives of spherical Hankel h_n^(2)."""
@@ -142,8 +142,8 @@ def test_d_spherical_h2(self):
142142
143143 for n in range (1 , 4 ):
144144 result = d_spherical_h2 (n , self .z )
145- self . assertAlmostEqual ( result .real , expected [n ].real , delta = self .tolerance )
146- self . assertAlmostEqual ( result .imag , expected [n ].imag , delta = self .tolerance )
145+ assert result .real == pytest . approx ( expected [n ].real , abs = self .tolerance )
146+ assert result .imag == pytest . approx ( expected [n ].imag , abs = self .tolerance )
147147
148148 def test_d_riccati_bessel_jn (self ):
149149 """Check derivatives of Riccati-Bessel j_n."""
@@ -157,8 +157,8 @@ def test_d_riccati_bessel_jn(self):
157157
158158 for n in range (4 ):
159159 result = d_riccati_bessel_jn (n , self .z )
160- self . assertAlmostEqual ( result .real , expected [n ].real , delta = self .tolerance )
161- self . assertAlmostEqual ( result .imag , expected [n ].imag , delta = self .tolerance )
160+ assert result .real == pytest . approx ( expected [n ].real , abs = self .tolerance )
161+ assert result .imag == pytest . approx ( expected [n ].imag , abs = self .tolerance )
162162
163163 def test_d_riccati_bessel_h1 (self ):
164164 """Check derivatives of Riccati-Bessel h_n^(1)."""
@@ -172,8 +172,8 @@ def test_d_riccati_bessel_h1(self):
172172
173173 for n in range (1 , 4 ):
174174 result = d_riccati_bessel_h1 (n , self .z )
175- self . assertAlmostEqual ( result .real , expected [n ].real , delta = self .tolerance )
176- self . assertAlmostEqual ( result .imag , expected [n ].imag , delta = self .tolerance )
175+ assert result .real == pytest . approx ( expected [n ].real , abs = self .tolerance )
176+ assert result .imag == pytest . approx ( expected [n ].imag , abs = self .tolerance )
177177
178178 def test_d_riccati_bessel_h2 (self ):
179179 """Check derivatives of Riccati-Bessel h_n^(2)."""
@@ -187,34 +187,23 @@ def test_d_riccati_bessel_h2(self):
187187
188188 for n in range (1 , 4 ):
189189 result = d_riccati_bessel_h2 (n , self .z )
190- self . assertAlmostEqual ( result .real , expected [n ].real , delta = self .tolerance )
191- self . assertAlmostEqual ( result .imag , expected [n ].imag , delta = self .tolerance )
190+ assert result .real == pytest . approx ( expected [n ].real , abs = self .tolerance )
191+ assert result .imag == pytest . approx ( expected [n ].imag , abs = self .tolerance )
192192
193193
194- class TestAsymptotic ( unittest . TestCase ) :
194+ class TestAsymptotic :
195195 """Validate large-argument asymptotic behavior."""
196196
197- def setUp (self ):
197+ def setup_method (self ):
198198 """Set a large argument for asymptotic comparisons."""
199199 self .z = 1000
200200 self .tolerance = 1e-5
201201
202- # def test_spherical_jn(self):
203- # for n in range(1, 4):
204- # expected = (-1j) ** n * np.exp(1j * self.z) / (1j * self.z)
205- # result = spherical_jn(n, self.z)
206- # self.assertAlmostEqual(result.real, expected.real, delta=self.tolerance)
207- # self.assertAlmostEqual(result.imag, expected.imag, delta=self.tolerance)
208-
209202 def test_spherical_h1 (self ):
210203 """Check h_n^(1) against the large-argument asymptotic form."""
211204 expected = np .exp (1j * self .z ) / (1j * self .z )
212205 for n in range (1 , 4 ):
213206 expected = (- 1j ) ** n * np .exp (1j * self .z ) / (1j * self .z )
214207 result = spherical_h1 (n , self .z )
215- self .assertAlmostEqual (result .real , expected .real , delta = self .tolerance )
216- self .assertAlmostEqual (result .imag , expected .imag , delta = self .tolerance )
217-
218-
219- if __name__ == "__main__" :
220- unittest .main ()
208+ assert result .real == pytest .approx (expected .real , abs = self .tolerance )
209+ assert result .imag == pytest .approx (expected .imag , abs = self .tolerance )
0 commit comments