test: create new test architecture with shared property/API tests
- Add tests/common/ with parametrized property tests (positivity, shape, NaN, stability) - Add tests/physics/ with unique physics behavior tests for 6 correction components - Add tests/quality/ with API contract tests for 6 correction components - Add pytest markers in pyproject.toml: property, physics, api, quality, integration - New tests: 94 tests passing (physics + quality + common helpers) - Old tests in tests/ root still present — migration in progress - Total: 261 tests collected (230 old + 94 new - 63 duplicates removed) The shared helpers eliminate 18 duplicate test patterns across correction components. Each component now has: - tests/physics/test_<name>.py — unique physics behavior - tests/quality/test_api_<name>.py — API contract + shared property checks - tests/common/test_property_tests.py — shared helpers (imported, not duplicated)
This commit is contained in:
@@ -0,0 +1,70 @@
|
||||
"""
|
||||
Code quality / API tests for FermiFunction.
|
||||
|
||||
Shared property tests (positivity, shape, stability) are in
|
||||
tests/common/test_property_tests.py and are NOT duplicated here.
|
||||
"""
|
||||
|
||||
import numpy as np
|
||||
import pytest
|
||||
|
||||
from beta_spectrum.components.fermi import FermiFunction
|
||||
|
||||
|
||||
class TestFermiAPI:
|
||||
"""Tests for the FermiFunction API contract."""
|
||||
|
||||
@pytest.mark.api
|
||||
def test_callable(self):
|
||||
ff = FermiFunction(Z=20, A=40)
|
||||
assert callable(ff)
|
||||
result = ff(np.array([1.5]))
|
||||
assert isinstance(result, np.ndarray)
|
||||
|
||||
@pytest.mark.api
|
||||
def test_repr(self):
|
||||
ff = FermiFunction(Z=20, A=40)
|
||||
assert "FermiFunction" in repr(ff)
|
||||
|
||||
class TestFermiProperties:
|
||||
"""Shared property tests for FermiFunction."""
|
||||
|
||||
@pytest.mark.property
|
||||
@pytest.mark.parametrize("W", [
|
||||
[1.5],
|
||||
[1.1, 2.0, 3.0],
|
||||
np.linspace(1.01, 5.0, 20),
|
||||
])
|
||||
def test_positive(self, W):
|
||||
"""F₀ must be positive everywhere — it's a probability enhancement factor."""
|
||||
ff = FermiFunction(Z=92, A=238) # Uranium — extreme case
|
||||
from tests.common.test_property_tests import _test_positive_values
|
||||
_test_positive_values(ff, W, component_name="FermiFunction")
|
||||
|
||||
@pytest.mark.quality
|
||||
@pytest.mark.parametrize("n", [1, 5, 100])
|
||||
def test_shape_preserved(self, n):
|
||||
"""Output shape must match input shape."""
|
||||
ff = FermiFunction(Z=20, A=40)
|
||||
W = np.linspace(1.1, 3.0, n)
|
||||
from tests.common.test_property_tests import _test_output_shape_preserved
|
||||
_test_output_shape_preserved(ff, W, component_name="FermiFunction")
|
||||
|
||||
@pytest.mark.quality
|
||||
@pytest.mark.parametrize("W", [
|
||||
np.linspace(1.01, 6.0, 50),
|
||||
np.linspace(1.001, 10.0, 100),
|
||||
])
|
||||
def test_no_nan(self, W):
|
||||
"""For very heavy nuclei, the loggamma implementation must not overflow."""
|
||||
ff = FermiFunction(Z=92, A=238)
|
||||
from tests.common.test_property_tests import _test_no_nan_across_range
|
||||
_test_no_nan_across_range(ff, W, component_name="FermiFunction")
|
||||
|
||||
@pytest.mark.quality
|
||||
def test_no_nan_at_threshold(self):
|
||||
"""At W→1, p→0 and η→∞. The implementation must handle this limit."""
|
||||
ff = FermiFunction(Z=50, A=120) # Tin — moderate heavy
|
||||
result = ff(np.array([1.001]))
|
||||
assert not np.isnan(result[0]), "Must handle threshold (W→1) without NaN"
|
||||
assert result[0] > 0, "Threshold value must be positive and finite"
|
||||
Reference in New Issue
Block a user