test(kjoring): the median when exactly half the draws cannot be built

And the docstring of the percentile says how it is computed
(clarification 103).

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
This commit is contained in:
Kjell Tore Guttormsen 2026-11-13 15:48:11 +01:00
commit 1a3a2fd5a8
Signed by: ktg
SSH key fingerprint: SHA256:JakMjO6FTBBzN0Bhfj9saOoEjaFxlSdYuZQQpM/lF9Q
2 changed files with 9 additions and 2 deletions

View file

@ -1,4 +1,4 @@
"""The run over the draws (chapter 11; chapter 16, clarifications 95 to 102).
"""The run over the draws (chapter 11; chapter 16, clarifications 95 to 103).
One draw is one set of values. For every draw the seven solutions are
computed on every step of the ladder and in every scenario, and the outcomes
@ -527,6 +527,8 @@ def persentil(verdier: Sequence[float], p: float) -> float:
With the values sorted ascending, x_1 .. x_N, it is x_j + (h - j)(x_{j+1} - x_j)
with h = 1 + (N - 1) p and j the whole part of h. At p = 0.5 it is the median.
It is computed in floating point as the formula stands (clarification 103): exact
rational arithmetic, or numpy's percentile, can differ in the last digit.
"""
if not verdier:
msg = "a percentile needs at least one value"

View file

@ -1,4 +1,4 @@
"""The run over the draws (chapter 11; clarifications 95 to 102).
"""The run over the draws (chapter 11; clarifications 95 to 103).
Made-up draws only: variants of the made-up set of ``conftest.py``, and invented outcomes per
draw for the verdicts and the timeline. Nothing here says anything about the hypothesis.
@ -271,6 +271,11 @@ def test_en_losning_er_felt_av_negativ_median_eller_et_maal_som_ikke_holder() ->
assert not kj.losningsdommer([_u()] * 5, Dom.HOLDER).felt
# more than half cannot be built: the median ranks below every value
assert kj.losningsdommer([None, None, _u()], Dom.HOLDER).median_M1 == -math.inf
# exactly half cannot be built: the two middle draws are one without a value and one with,
# the median is below every value and the solution cannot carry part I (clarification 103)
halvt = kj.losningsdommer([None, _u(5.0), None, _u(7.0)], Dom.HOLDER)
assert halvt.median_M1 == -math.inf
assert halvt.felt
def test_trinnet_settes_i_normalisering_og_gjelder_alle_scenarioene() -> None: