Files
beta_shape_pnpi/tests/quality/test_neutrino_mass_cli.py
T

90 lines
3.3 KiB
Python

"""
Tests for neutrino mass functionality in CLI and configuration.
"""
import numpy as np
from beta_spectrum.spectrum import SpectrumConfig
from beta_spectrum.components.phase_space import PhaseSpace
class TestNeutrinoMassConfig:
"""Test neutrino mass parameter in SpectrumConfig."""
def test_neutrino_mass_default_value(self):
"""Test that neutrino_mass_MeV defaults to 0.0 in SpectrumConfig."""
config = SpectrumConfig(
Z_parent=43,
Z_daughter=44,
A_number=99,
endpoint_MeV=0.2111,
transition_type="F2",
e_step_MeV=0.001,
)
assert config.neutrino_mass_MeV == 0.0, "Default neutrino mass should be 0.0"
def test_neutrino_mass_custom_value(self):
"""Test that neutrino_mass_MeV can be set to a custom value."""
config = SpectrumConfig(
Z_parent=43,
Z_daughter=44,
A_number=99,
endpoint_MeV=0.2111,
transition_type="F2",
e_step_MeV=0.001,
neutrino_mass_MeV=0.01,
)
assert config.neutrino_mass_MeV == 0.01, "Neutrino mass should be 0.01 MeV"
class TestNeutrinoMassPhaseSpace:
"""Test neutrino mass parameter in PhaseSpace component."""
def test_phase_space_neutrino_mass_parameter(self):
"""Test that PhaseSpace accepts and uses neutrino mass parameter."""
ps = PhaseSpace(W0=5.0, transition_type="A", m_nu=0.01)
assert ps.m_nu == 0.01, "PhaseSpace should store neutrino mass parameter"
def test_phase_space_neutrino_mass_effect(self):
"""Test that neutrino mass affects the phase space calculation."""
ps_zero = PhaseSpace(W0=5.0, transition_type="A", m_nu=0.0)
ps_massive = PhaseSpace(W0=5.0, transition_type="A", m_nu=0.1)
# Test near endpoint where neutrino mass effect should be visible
W_near_endpoint = np.array([4.8]) # W₀−W = 0.2 > m_nu=0.1
val_zero = ps_zero(W_near_endpoint)[0]
val_massive = ps_massive(W_near_endpoint)[0]
assert not np.isnan(val_massive), "Should produce finite value"
assert val_massive < val_zero, (
"Massive neutrino must suppress spectrum near endpoint"
)
class TestCLIArguments:
"""Test CLI argument parsing for neutrino mass."""
def test_neutrino_mass_cli_argument_exists(self):
"""Test that --neutrino-mass argument is available in CLI parser."""
from beta_spectrum.cli import _build_parser
parser = _build_parser()
# Check that the argument is in the parser
args = parser.parse_args(["--nuclide", "Tc99", "--neutrino-mass", "0.01"])
assert hasattr(args, "neutrino_mass"), "CLI should have neutrino_mass argument"
assert args.neutrino_mass == 0.01, "CLI neutrino_mass should be 0.01"
def test_neutrino_mass_cli_default_value(self):
"""Unset flag parses as None ("not provided") so JSON file
values are not overwritten; the effective default (0.0 MeV) is
applied when the config is built."""
from beta_spectrum.cli import _build_parser
parser = _build_parser()
args = parser.parse_args(["--nuclide", "Tc99"])
assert args.neutrino_mass is None, (
"unset --neutrino-mass must parse as None (not a value)"
)