"""Test for #84.7 — _median helper used by the queue-metrics time-per-item proxy."""

from __future__ import annotations

import pytest

from legal_mcp.services import metrics


def test_median_empty_is_none():
    assert metrics._median([]) is None
    assert metrics._median([None, None]) is None


def test_median_odd():
    assert metrics._median([3.0, 1.0, 2.0]) == 2.0


def test_median_even_averages_middle():
    assert metrics._median([4.0, 1.0, 3.0, 2.0]) == pytest.approx(2.5)


def test_median_ignores_none():
    assert metrics._median([None, 5.0, None, 1.0, 3.0]) == 3.0
