"""Outside markers for centile and age-block references in modern and legacy tea. Fixtures: parameterized baseline modules and in-memory synthetic control values. """ import numpy as np import pytest from tea.biomarkers.spindles import _baseline as modern from tea.legacy.biomarkers.spindles import _baseline as legacy @pytest.mark.parametrize("baseline", (modern, legacy)) def test_centile_outside_requires_a_reference(baseline): """Pin float -1/0/+1 and missing values. Fails if missing data, uncovered ages or sparse controls give zero.""" curve = baseline.CentileCurves().fit(np.tile([1, 2, 3], 50), np.repeat([12, 24, 36], 50)) outside, _ = curve.deviation([0, 2, 4, np.nan, 2, 2], [24, 24, 24, 24, 60, np.nan]) assert outside.dtype.kind == "f" np.testing.assert_array_equal(outside, [-1, 0, 1, np.nan, np.nan, np.nan]) sparse = baseline.CentileCurves().fit([1, 2], [12, 36]) assert np.isnan(sparse.deviation([2], [24])[0][0]) @pytest.mark.parametrize("baseline", (modern, legacy)) def test_age_block_outside_requires_a_z_score(baseline): """Pin float markers with a valid score. Fails if a missing score or degenerate MAD is classified in range.""" fitted = baseline.AgeBlockZ().fit(np.arange(30), np.full(30, 24)) outside, _ = fitted.deviation([-2, 15, 40, np.nan, 15], [24, 24, 24, 24, np.nan]) assert outside.dtype.kind == "f" np.testing.assert_array_equal(outside, [-1, 0, 1, np.nan, np.nan]) flat = baseline.AgeBlockZ().fit(np.ones(30), np.full(30, 24)) assert np.isnan(flat.deviation([1], [24])[0][0])