1111"""
1212
1313from __future__ import annotations
14+
1415import numpy as np
15- from test_particle_sim_1d import fields
1616
17+ from test_particle_sim_1d import fields
1718
1819# ----------------------------------------------------------------------
1920# 1. Analytic equivalence for B_mirror
2021# ----------------------------------------------------------------------
2122
23+
2224def test_B_mirror_matches_analytic ():
2325 """Numerical B_mirror matches analytic formula exactly."""
2426 z = np .linspace (- 0.05 , 0.05 , 200 )
@@ -32,6 +34,7 @@ def test_B_mirror_matches_analytic():
3234# 2. Derivative (gradient) consistency
3335# ----------------------------------------------------------------------
3436
37+
3538def test_B_mirror_derivative_consistency ():
3639 """Numerical dBz/dz matches analytic derivative of B_mirror."""
3740 z = np .linspace (- 0.05 , 0.05 , 400 )
@@ -49,20 +52,22 @@ def test_B_mirror_derivative_consistency():
4952# 3. Symmetry about z = 0
5053# ----------------------------------------------------------------------
5154
55+
5256def test_B_mirror_symmetry ():
5357 """B_mirror field must be perfectly symmetric: Bz(z) = Bz(-z)."""
5458 z = np .linspace (- 0.05 , 0.05 , 1001 )
5559 Bz = fields .B_mirror (z , B0 = 1.0 , z_mirror = 0.05 )[:, 2 ]
5660
57- left = Bz [: len (Bz )// 2 ]
58- right = Bz [len (Bz )// 2 + 1 :][::- 1 ]
61+ left = Bz [: len (Bz ) // 2 ]
62+ right = Bz [len (Bz ) // 2 + 1 :][::- 1 ]
5963 np .testing .assert_allclose (left , right , rtol = 1e-10 )
6064
6165
6266# ----------------------------------------------------------------------
6367# 4. Parameter-scaling behavior
6468# ----------------------------------------------------------------------
6569
70+
6671def test_B_mirror_scales_with_B0 ():
6772 """Scaling B0 should scale the entire field linearly."""
6873 z = np .linspace (- 0.05 , 0.05 , 50 )
@@ -79,7 +84,7 @@ def test_B_mirror_scales_with_zmirror():
7984 B2 = fields .B_mirror (z , B0 = 1.0 , z_mirror = L2 )[:, 2 ]
8085
8186 # Both fields equal at z=0
82- np .testing .assert_allclose (B1 [len (z )// 2 ], B2 [len (z )// 2 ], atol = 1e-3 )
87+ np .testing .assert_allclose (B1 [len (z ) // 2 ], B2 [len (z ) // 2 ], atol = 1e-3 )
8388 # At edges, smaller L (stronger mirror) should give larger Bz
8489 assert B1 [- 1 ] > B2 [- 1 ]
8590
@@ -88,11 +93,12 @@ def test_B_mirror_scales_with_zmirror():
8893# 5. Direction tests for uniform fields
8994# ----------------------------------------------------------------------
9095
96+
9197def test_uniform_field_directions ():
9298 """Uniform fields populate the correct axis only."""
9399 z = np .linspace (0 , 1 , 5 )
94100 for func in [fields .E_uniform , fields .B_uniform ]:
95- for direction , idx in zip ("xyz" , [0 , 1 , 2 ]):
101+ for direction , idx in zip ("xyz" , [0 , 1 , 2 ], strict = False ):
96102 F = func (z , 5.0 , direction )
97103 assert F .shape == (5 , 3 )
98104 assert np .allclose (F [:, idx ], 5.0 )
@@ -105,6 +111,7 @@ def test_uniform_field_directions():
105111# 6. Vector magnitude checks
106112# ----------------------------------------------------------------------
107113
114+
108115def test_uniform_field_magnitude_constant ():
109116 """Uniform field should have constant magnitude everywhere."""
110117 z = np .linspace (0 , 1 , 5 )
@@ -117,6 +124,7 @@ def test_uniform_field_magnitude_constant():
117124# 7. Input type robustness
118125# ----------------------------------------------------------------------
119126
127+
120128def test_accepts_python_lists ():
121129 """Ensure field functions accept Python lists and return NumPy arrays."""
122130 z_list = [0.0 , 0.5 , 1.0 ]
@@ -132,6 +140,7 @@ def test_accepts_python_lists():
132140# 8. Edge case: empty input
133141# ----------------------------------------------------------------------
134142
143+
135144def test_empty_input_returns_empty ():
136145 """Functions should safely handle empty arrays."""
137146 E = fields .E_uniform (np .array ([]), E0 = 5.0 )
0 commit comments