@@ -13,38 +13,38 @@ def test_funcionality(self):
1313 r = 2
1414 phi = jnp .pi / 4
1515 res = utils .rect (r , phi )
16- assert res == jnp .sqrt (2 ) + jnp .sqrt (2 ) * 1j
16+ assert jnp . allclose ( res , jnp .sqrt (2 ) + jnp .sqrt (2 ) * 1j )
1717
1818 def test_boundary (self ):
1919 # 1 + 0j
2020 r = 1
2121 phi = 0
2222 res = utils .rect (r , phi )
23- assert res == pytest . approx ( 1 , abs = 1e-15 )
23+ assert jnp . allclose ( res , 1 + 0j )
2424
2525 # 0 + 1j
2626 r = 1
2727 phi = jnp .pi / 2
2828 res = utils .rect (r , phi )
29- assert res == pytest . approx ( 1j , abs = 1e-15 )
29+ assert jnp . allclose ( res , 0 + 1j )
3030
3131 # -1 + 0j
3232 r = 1
3333 phi = jnp .pi
3434 res = utils .rect (r , phi )
35- assert res == pytest . approx ( - 1 , abs = 1e-15 )
35+ assert jnp . allclose ( res , - 1 + 0j )
3636
3737 # 0 - 1j
3838 r = 1
3939 phi = 3 * jnp .pi / 2
4040 res = utils .rect (r , phi )
41- assert res == pytest . approx ( - 1j , abs = 1e-15 )
41+ assert jnp . allclose ( res , 0 - 1j )
4242
4343 # 0 + 0j
4444 r = 0
4545 phi = 0
4646 res = utils .rect (r , phi )
47- assert res == pytest . approx ( 0 , abs = 1e-15 )
47+ assert jnp . allclose ( res , 0 + 0j )
4848
4949 def test_exceptions (self ):
5050 # Negative radius
@@ -56,33 +56,39 @@ class TestPolar:
5656 def test_funcionality (self ):
5757 z = 1 + 1j
5858 res = utils .polar (z )
59- assert res == (jnp .sqrt (2 ), jnp .pi / 4 )
59+ assert jnp .allclose (res [0 ], jnp .sqrt (2 ))
60+ assert jnp .allclose (res [1 ], jnp .pi / 4 )
6061
6162 def test_boundary (self ):
6263 # 1 + 0j
6364 z = 1
6465 res = utils .polar (z )
65- assert res == (1 , 0 )
66+ assert jnp .allclose (res [0 ], 1 , atol = 1e-15 )
67+ assert jnp .allclose (res [1 ], 0 , atol = 1e-15 )
6668
6769 # 0 + 1j
6870 z = 1j
6971 res = utils .polar (z )
70- assert res == (1 , jnp .pi / 2 )
72+ assert jnp .allclose (res [0 ], 1 , atol = 1e-15 )
73+ assert jnp .allclose (res [1 ], jnp .pi / 2 , atol = 1e-15 )
7174
7275 # -1 + 0j
7376 z = - 1
7477 res = utils .polar (z )
75- assert res == (1 , jnp .pi )
78+ assert jnp .allclose (res [0 ], 1 , atol = 1e-15 )
79+ assert jnp .allclose (res [1 ], jnp .pi , atol = 1e-15 )
7680
7781 # 0 - 1j
7882 z = - 1j
7983 res = utils .polar (z )
80- assert res == (1 , - jnp .pi / 2 )
84+ assert jnp .allclose (res [0 ], 1 , atol = 1e-15 )
85+ assert jnp .allclose (res [1 ], - jnp .pi / 2 , atol = 1e-15 )
8186
8287 # 0 + 0j
8388 z = 0
8489 res = utils .polar (z )
85- assert res == (0 , 0 )
90+ assert jnp .allclose (res [0 ], 0 , atol = 1e-15 )
91+ assert jnp .allclose (res [1 ], 0 , atol = 1e-15 )
8692
8793 def test_exceptions (self ):
8894 pass
@@ -153,43 +159,43 @@ class TestMatAddPolar:
153159
154160class TestString2Float :
155161 def test_no_suffix (self ):
156- assert utils .str2float ("2.53" ) == 2.53
162+ assert utils .str2float ("2.53" ) == pytest . approx ( 2.53 )
157163
158164 def test_femto (self ):
159- assert utils .str2float ("17.83f" ) == 17.83e-15
165+ assert utils .str2float ("17.83f" ) == pytest . approx ( 17.83e-15 )
160166
161167 def test_pico (self ):
162- assert utils .str2float ("-15.37p" ) == - 15.37e-12
168+ assert utils .str2float ("-15.37p" ) == pytest . approx ( - 15.37e-12 )
163169
164170 def test_nano (self ):
165- assert utils .str2float ("158.784n" ) == 158.784e-9
171+ assert utils .str2float ("158.784n" ) == pytest . approx ( 158.784e-9 )
166172
167173 def test_micro (self ):
168- assert utils .str2float ("15.26u" ) == 15.26e-06
174+ assert utils .str2float ("15.26u" ) == pytest . approx ( 15.26e-06 )
169175
170176 def test_milli (self ):
171- assert utils .str2float ("-15.781m" ) == - 15.781e-3
177+ assert utils .str2float ("-15.781m" ) == pytest . approx ( - 15.781e-3 )
172178
173179 def test_centi (self ):
174- assert utils .str2float ("14.5c" ) == 14.5e-2
180+ assert utils .str2float ("14.5c" ) == pytest . approx ( 14.5e-2 )
175181
176182 def test_kilo (self ):
177- assert utils .str2float ("-0.257k" ) == - 0.257e3
183+ assert utils .str2float ("-0.257k" ) == pytest . approx ( - 0.257e3 )
178184
179185 def test_Mega (self ):
180- assert utils .str2float ("15.26M" ) == 15.26e6
186+ assert utils .str2float ("15.26M" ) == pytest . approx ( 15.26e6 )
181187
182188 def test_Giga (self ):
183- assert utils .str2float ("-8.73G" ) == - 8.73e9
189+ assert utils .str2float ("-8.73G" ) == pytest . approx ( - 8.73e9 )
184190
185191 def test_Tera (self ):
186- assert utils .str2float ("183.4T" ) == 183.4e12
192+ assert utils .str2float ("183.4T" ) == pytest . approx ( 183.4e12 )
187193
188194 def test_e (self ):
189- assert utils .str2float ("15.2e-6" ) == 15.2e-6
195+ assert utils .str2float ("15.2e-6" ) == pytest . approx ( 15.2e-6 )
190196
191197 def test_E (self ):
192- assert utils .str2float ("0.4E6" ) == 0.4e6
198+ assert utils .str2float ("0.4E6" ) == pytest . approx ( 0.4e6 )
193199
194200 def test_unrecognized (self ):
195201 with pytest .raises (ValueError ):
@@ -203,12 +209,12 @@ def test_malformed(self):
203209class TestFreq2Wl :
204210 def test_funcionality (self ):
205211 # Test converting a few random frequencies to wavelengths
206- assert utils .freq2wl (299792458 ) == 1
207- assert utils .freq2wl (149896229 ) == 2
208- assert utils .freq2wl (99930819.33333333 ) == 3
209- assert utils .freq2wl (4 ) == 74948114.5
210- assert utils .freq2wl (5 ) == 59958491.6
211- assert utils .freq2wl (6 ) == 49965409.666666664
212+ assert jnp . allclose ( utils .freq2wl (299792458 ), 1 )
213+ assert jnp . allclose ( utils .freq2wl (149896229 ), 2 )
214+ assert jnp . allclose ( utils .freq2wl (99930819.33333333 ), 3 )
215+ assert jnp . allclose ( utils .freq2wl (4 ), 74948114.5 )
216+ assert jnp . allclose ( utils .freq2wl (5 ), 59958491.6 )
217+ assert jnp . allclose ( utils .freq2wl (6 ), 49965409.666666664 )
212218
213219 def test_exceptions (self ):
214220 # Test with negative frequency
@@ -230,9 +236,9 @@ def test_boundary(self):
230236class TestWl2Freq :
231237 def test_funcionality (self ):
232238 # Test converting a few random wavelengths to frequencies
233- assert utils .wl2freq (1 ) == 299792458
234- assert utils .wl2freq (2 ) == 149896229
235- assert utils .wl2freq (3 ) == 99930819.33333333
239+ assert jnp . allclose ( utils .wl2freq (1 ), 299792458 )
240+ assert jnp . allclose ( utils .wl2freq (2 ), 149896229 )
241+ assert jnp . allclose ( utils .wl2freq (3 ), 99930819.33333333 )
236242
237243 def test_exceptions (self ):
238244 # Test with negative wavelength
@@ -254,9 +260,9 @@ def test_boundary(self):
254260class TestWlum2Freq :
255261 def test_funcionality (self ):
256262 # Test converting a few random wavelengths in microns to frequencies
257- assert utils .wlum2freq (1 ) == utils .wl2freq (1e-6 )
258- assert utils .wlum2freq (2 ) == utils .wl2freq (2e-6 )
259- assert utils .wlum2freq (3 ) == utils .wl2freq (3e-6 )
263+ assert jnp . allclose ( utils .wlum2freq (1 ), utils .wl2freq (1e-6 ) )
264+ assert jnp . allclose ( utils .wlum2freq (2 ), utils .wl2freq (2e-6 ) )
265+ assert jnp . allclose ( utils .wlum2freq (3 ), utils .wl2freq (3e-6 ) )
260266
261267 def test_exceptions (self ):
262268 # Test with negative wavelength in microns
0 commit comments