44 lines
1.2 KiB
Python
44 lines
1.2 KiB
Python
"""Limits on public inputs: the High Needs cap, normalization, shrinkage."""
|
|
|
|
from __future__ import annotations
|
|
|
|
import pytest
|
|
|
|
from lead.benchmark import CAPPED, WITHIN_CAP
|
|
from lead.limits import (
|
|
Headroom,
|
|
earlier_qualification_headroom,
|
|
normalization_sensitivity,
|
|
shrinkage_weight,
|
|
)
|
|
|
|
|
|
def test_catching_high_needs_above_the_cap_forgoes_the_excess():
|
|
room = earlier_qualification_headroom(1.0, 1.05)
|
|
assert room == Headroom(room.scored, CAPPED, room.forgone)
|
|
assert room.scored == 1.04
|
|
assert room.forgone == pytest.approx(0.01)
|
|
|
|
|
|
def test_growth_inside_the_cap_forgoes_nothing():
|
|
room = earlier_qualification_headroom(1.0, 1.035)
|
|
assert room == Headroom(1.035, WITHIN_CAP, 0.0)
|
|
|
|
|
|
def test_normalization_divides_by_the_caller_factor():
|
|
assert normalization_sensitivity(1000.0, 1.25) == 800.0
|
|
|
|
|
|
def test_a_nonpositive_normalization_factor_raises():
|
|
with pytest.raises(ValueError):
|
|
normalization_sensitivity(1000.0, 0)
|
|
|
|
|
|
def test_shrinkage_is_the_aco_share():
|
|
assert shrinkage_weight(100, 300) == 0.25
|
|
|
|
|
|
def test_shrinkage_with_no_observations_raises():
|
|
with pytest.raises(ValueError):
|
|
shrinkage_weight(0, 0)
|