a818847b99
Share log-age interpolation with scoring and preserve nulls outside coverage. Use a synthetic geometric midpoint and values on both sides of the median to check numeric parity.
26 lines
823 B
Python
26 lines
823 B
Python
import pytest
|
|
|
|
from models.tea.eeg import curves
|
|
|
|
|
|
def test_centile_interpolation_preserves_scoring():
|
|
baseline = {
|
|
"kind": "curves",
|
|
"curve": {
|
|
"age_months": [16, 36],
|
|
"p5": [1, 3],
|
|
"p25": [2, 4],
|
|
"median": [3, 5],
|
|
"p75": [5, 7],
|
|
"p95": [7, 9],
|
|
},
|
|
}
|
|
# At the geometric midpoint, the original log-age interpolation gives the means.
|
|
assert curves.centiles(baseline, 24) == pytest.approx(
|
|
{"p5": 2, "p25": 3, "median": 4, "p75": 6, "p95": 8}
|
|
)
|
|
for value, z, outside in ((0, -3.29, -1), (3, -0.8225, 0), (6, 0.8225, 0), (10, 2.4675, 1)):
|
|
assert curves.score(baseline, value, 24) == pytest.approx(
|
|
{"z": z, "outside": outside, "p5": 2, "median": 4, "p95": 8}, rel=1e-9
|
|
)
|