chore(gitignore): remove notebooks and ipynb from gitignore

style: fix black formatting in test files (unused imports, assert reformatting)
This commit is contained in:
2026-05-01 19:16:50 +03:00
parent 21901aac70
commit c9a738baab
6 changed files with 52 additions and 56 deletions
-2
View File
@@ -64,8 +64,6 @@ venv.bak/
# ========================= # =========================
.ipynb_checkpoints/ .ipynb_checkpoints/
*.ipynb
notebooks/
# IPython # IPython
+10 -10
View File
@@ -45,23 +45,23 @@ class TestExchangeLowEnergy:
low_W = np.array([1.1]) # T ≈ 50 keV — still "low" but above cutoff low_W = np.array([1.1]) # T ≈ 50 keV — still "low" but above cutoff
result = ex(low_W) result = ex(low_W)
assert result[0] > 1.0, ( assert (
f"Exchange must enhance spectrum at low energy for heavy Z: got {result[0]}" result[0] > 1.0
) ), f"Exchange must enhance spectrum at low energy for heavy Z: got {result[0]}"
def test_correction_grows_as_energy_decreases(self): def test_correction_grows_as_energy_decreases(self):
"""X(W) should increase as W → 1 (lower momentum → stronger exchange).""" """X(W) should increase as W → 1 (lower momentum → stronger exchange)."""
ex = ExchangeCorrection(Z=50) # Tin — moderate-heavy ex = ExchangeCorrection(Z=50) # Tin — moderate-heavy
low_W = np.array([1.2]) # Higher energy low_W = np.array([1.2]) # Higher energy
lower_W = np.array([1.05]) # Lower energy (above cutoff W_cut=1.005) lower_W = np.array([1.05]) # Lower energy (above cutoff W_cut=1.005)
s_low = ex(low_W)[0] s_low = ex(low_W)[0]
s_lower = ex(lower_W)[0] s_lower = ex(lower_W)[0]
assert s_lower > s_low, ( assert (
f"Exchange must increase at lower energy: {s_low} → {s_lower}" s_lower > s_low
) ), f"Exchange must increase at lower energy: {s_low} → {s_lower}"
class TestExchangeHighEnergy: class TestExchangeHighEnergy:
@@ -74,9 +74,9 @@ class TestExchangeHighEnergy:
high_W = np.array([3.0, 5.0]) high_W = np.array([3.0, 5.0])
result = ex(high_W) result = ex(high_W)
assert abs(result[0] - 1.0) < 0.5, ( assert (
f"Exchange must approach unity at high energy: got {result}" abs(result[0] - 1.0) < 0.5
) ), f"Exchange must approach unity at high energy: got {result}"
class TestExchangeNumericalStability: class TestExchangeNumericalStability:
+12 -11
View File
@@ -25,7 +25,6 @@ Common practice: When testing a function with special mathematical functions
""" """
import numpy as np import numpy as np
import pytest
from beta_spectrum.components.fermi import FermiFunction from beta_spectrum.components.fermi import FermiFunction
@@ -45,9 +44,9 @@ class TestFermiZeros:
result = ff(W_test) result = ff(W_test)
# For Z=1, the correction from finite nuclear size and Coulomb terms gives ~3% deviation # For Z=1, the correction from finite nuclear size and Coulomb terms gives ~3% deviation
assert np.all(np.abs(result - 1.0) < 0.05), ( assert np.all(
f"Z=1 Fermi function should be ≈1 but got {result}" np.abs(result - 1.0) < 0.05
) ), f"Z=1 Fermi function should be ≈1 but got {result}"
class TestFermiPhysicalBehavior: class TestFermiPhysicalBehavior:
@@ -64,7 +63,9 @@ class TestFermiPhysicalBehavior:
# Check monotonic decrease (each successive point should be smaller) # Check monotonic decrease (each successive point should be smaller)
diffs = np.diff(result) diffs = np.diff(result)
assert np.all(diffs < 0), f"Fermi function must decrease with W; got diffs {diffs}" assert np.all(
diffs < 0
), f"Fermi function must decrease with W; got diffs {diffs}"
def test_increases_with_Z(self): def test_increases_with_Z(self):
"""Higher Z → stronger Coulomb attraction → larger F₀ at low energy. """Higher Z → stronger Coulomb attraction → larger F₀ at low energy.
@@ -82,9 +83,9 @@ class TestFermiPhysicalBehavior:
f_30 = ff_z30(W_test)[0] f_30 = ff_z30(W_test)[0]
f_80 = ff_z80(W_test)[0] f_80 = ff_z80(W_test)[0]
assert f_80 > f_30 > f_10, ( assert (
f"Fermi function must increase with Z: {f_10} < {f_30} < {f_80}" f_80 > f_30 > f_10
) ), f"Fermi function must increase with Z: {f_10} < {f_30} < {f_80}"
def test_positive_values(self): def test_positive_values(self):
"""F₀ must be positive everywhere — it's a probability enhancement factor.""" """F₀ must be positive everywhere — it's a probability enhancement factor."""
@@ -126,6 +127,6 @@ class TestFermiOutputShape:
for n_points in [1, 5, 100]: for n_points in [1, 5, 100]:
W_test = np.linspace(1.1, 3.0, n_points) W_test = np.linspace(1.1, 3.0, n_points)
result = ff(W_test) result = ff(W_test)
assert result.shape == W_test.shape, ( assert (
f"Shape mismatch: input {W_test.shape} → output {result.shape}" result.shape == W_test.shape
) ), f"Shape mismatch: input {W_test.shape} → output {result.shape}"
+15 -16
View File
@@ -23,7 +23,6 @@ This catches sign errors and magnitude bugs early.
""" """
import numpy as np import numpy as np
import pytest
from beta_spectrum.components.finite_size import FiniteSizeL0, ChargeDistributionU from beta_spectrum.components.finite_size import FiniteSizeL0, ChargeDistributionU
@@ -41,9 +40,9 @@ class TestFiniteSizeL0:
W_test = np.array([2.0]) # Mid-range energy W_test = np.array([2.0]) # Mid-range energy
result = fs(W_test) result = fs(W_test)
assert abs(result[0] - 1.0) < 0.05, ( assert (
f"L₀ for Z=6 should be near unity but got {result[0]}" abs(result[0] - 1.0) < 0.05
) ), f"L₀ for Z=6 should be near unity but got {result[0]}"
def test_correction_increases_with_Z(self): def test_correction_increases_with_Z(self):
"""Higher Z → larger αZ term in L₀ expansion → larger deviation from 1.""" """Higher Z → larger αZ term in L₀ expansion → larger deviation from 1."""
@@ -57,9 +56,9 @@ class TestFiniteSizeL0:
dev_30 = abs(fs_z30(W_test)[0] - 1.0) dev_30 = abs(fs_z30(W_test)[0] - 1.0)
dev_80 = abs(fs_z80(W_test)[0] - 1.0) dev_80 = abs(fs_z80(W_test)[0] - 1.0)
assert dev_80 > dev_30 > dev_6, ( assert (
f"Deviation from unity must increase with Z: {dev_6}, {dev_30}, {dev_80}" dev_80 > dev_30 > dev_6
) ), f"Deviation from unity must increase with Z: {dev_6}, {dev_30}, {dev_80}"
def test_positive_everywhere(self): def test_positive_everywhere(self):
"""L₀ should be positive — it's a correction factor multiplicative to the spectrum.""" """L₀ should be positive — it's a correction factor multiplicative to the spectrum."""
@@ -78,9 +77,9 @@ class TestChargeDistributionU:
u = ChargeDistributionU(Z=6, A=12) u = ChargeDistributionU(Z=6, A=12)
result = u(np.array([2.0])) result = u(np.array([2.0]))
assert abs(result[0] - 1.0) < 0.01, ( assert (
f"U for Z=6 should be near unity but got {result[0]}" abs(result[0] - 1.0) < 0.01
) ), f"U for Z=6 should be near unity but got {result[0]}"
def test_always_positive_correction(self): def test_always_positive_correction(self):
"""U = 1 + (1/5)(αZW R)² is always > 1 since the squared term is positive.""" """U = 1 + (1/5)(αZW R)² is always > 1 since the squared term is positive."""
@@ -97,9 +96,9 @@ class TestChargeDistributionU:
W_test = np.array([3.0]) W_test = np.array([3.0])
assert u_z60(W_test)[0] > u_z20(W_test)[0], ( assert (
f"U must increase with Z: {u_z20(W_test)} < {u_z60(W_test)}" u_z60(W_test)[0] > u_z20(W_test)[0]
) ), f"U must increase with Z: {u_z20(W_test)} < {u_z60(W_test)}"
class TestFiniteSizeCombined: class TestFiniteSizeCombined:
@@ -113,9 +112,9 @@ class TestFiniteSizeCombined:
W_test = np.linspace(1.5, 4.0, 10) W_test = np.linspace(1.5, 4.0, 10)
combined = l0(W_test) * u(W_test) combined = l0(W_test) * u(W_test)
assert np.all(np.abs(combined - 1.0) < 0.05), ( assert np.all(
f"Combined finite-size for carbon should be near unity: {combined}" np.abs(combined - 1.0) < 0.05
) ), f"Combined finite-size for carbon should be near unity: {combined}"
def test_combined_positive(self): def test_combined_positive(self):
"""Product of two positive factors must be positive.""" """Product of two positive factors must be positive."""
+6 -7
View File
@@ -18,7 +18,6 @@ large arrays only when testing numerical stability or performance.
""" """
import numpy as np import numpy as np
import pytest
from beta_spectrum.components.phase_space import PhaseSpace from beta_spectrum.components.phase_space import PhaseSpace
@@ -82,9 +81,9 @@ class TestPhaseSpaceNeutrinoMass:
val_massive = ps_massive(W_near_endpoint)[0] val_massive = ps_massive(W_near_endpoint)[0]
assert not np.isnan(val_massive), "Should produce finite value" assert not np.isnan(val_massive), "Should produce finite value"
assert val_massive < val_zero, ( assert (
"Massive neutrino must suppress spectrum near endpoint" val_massive < val_zero
) ), "Massive neutrino must suppress spectrum near endpoint"
def test_massive_neutrino_gives_nan_below_threshold(self): def test_massive_neutrino_gives_nan_below_threshold(self):
"""With m_nu > 0, below the effective threshold (W₀−W < m_nu), sqrt gives NaN. """With m_nu > 0, below the effective threshold (W₀−W < m_nu), sqrt gives NaN.
@@ -102,9 +101,9 @@ class TestPhaseSpaceNeutrinoMass:
W_deep_below = np.array([4.95]) # W₀ − W = 0.05 < m_nu=0.1 — below threshold W_deep_below = np.array([4.95]) # W₀ − W = 0.05 < m_nu=0.1 — below threshold
result_below = ps(W_deep_below) result_below = ps(W_deep_below)
assert np.isnan(result_below[0]), ( assert np.isnan(
"Below kinematic threshold, spectrum should be NaN" result_below[0]
) ), "Below kinematic threshold, spectrum should be NaN"
class TestPhaseSpaceArrayType: class TestPhaseSpaceArrayType:
+9 -10
View File
@@ -24,7 +24,6 @@ Common practice: For components with "switching" logic, always test both the on-
""" """
import numpy as np import numpy as np
import pytest
from beta_spectrum.components.fermi import FermiFunction from beta_spectrum.components.fermi import FermiFunction
from beta_spectrum.components.screening import ScreeningCorrection from beta_spectrum.components.screening import ScreeningCorrection
@@ -44,9 +43,9 @@ class TestScreeningBasicProperties:
high_W = np.array([3.0, 5.0]) high_W = np.array([3.0, 5.0])
result = sc(high_W) result = sc(high_W)
assert abs(result[0] - 1.0) < 0.1, ( assert (
f"Screening must approach unity at high energy: got {result}" abs(result[0] - 1.0) < 0.1
) ), f"Screening must approach unity at high energy: got {result}"
def test_positive_values(self): def test_positive_values(self):
"""S(W) must be positive everywhere — it multiplies the spectrum.""" """S(W) must be positive everywhere — it multiplies the spectrum."""
@@ -80,9 +79,9 @@ class TestScreeningEnergyDependence:
# At low energy, correction is active and reduces the spectrum # At low energy, correction is active and reduces the spectrum
assert s_low < 1.1, f"Low-energy screening should suppress: {s_low}" assert s_low < 1.1, f"Low-energy screening should suppress: {s_low}"
# At mid energy, it's closer to unity # At mid energy, it's closer to unity
assert abs(s_mid - 1.0) < abs(s_low - 1.0), ( assert abs(s_mid - 1.0) < abs(
"Correction must decrease toward unity as W increases" s_low - 1.0
) ), "Correction must decrease toward unity as W increases"
class TestScreeningParameters: class TestScreeningParameters:
@@ -99,9 +98,9 @@ class TestScreeningParameters:
result_custom = sc_custom(low_W)[0] result_custom = sc_custom(low_W)[0]
# Different V₀ should give different results at low energy # Different V₀ should give different results at low energy
assert abs(result_default - result_custom) > 0, ( assert (
"Custom V₀ must change the screening behavior" abs(result_default - result_custom) > 0
) ), "Custom V₀ must change the screening behavior"
class TestScreeningOutputShape: class TestScreeningOutputShape: