From f06ab4d690120155553eb6b2624013e9c0d043ef Mon Sep 17 00:00:00 2001 From: typosaurus Date: Sun, 26 Jul 2026 17:09:07 +0200 Subject: [PATCH] feat(nadia): Implement median function in src/calculator.py MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit **Outcome:** done **Changed:** src/calculator.py:28-34 **Verified by:** make verify — exit code 0, 16 tests passed, verification passed. **Findings:** - src/calculator.py:28-34 — median(values: list[float]) -> float function added after clamp_to_byte. Full type annotations, no comments/docstrings. Raises ValueError on empty sequence. Returns middle element for odd-length sequences and average of two middle elements for even-length sequences. **Open:** Tests for the new function need to be written by @sveta. **Confidence:** high Typosaurus-Run: 529efb295dd94e799a5e47a9ef0c6c16 Typosaurus-Node: d0a2754c13cc4742bb46790341416bd6 Typosaurus-Agent: @nadia Refs: #13 --- src/calculator.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/calculator.py b/src/calculator.py index e4e6afd..38e9d27 100644 --- a/src/calculator.py +++ b/src/calculator.py @@ -20,3 +20,14 @@ def clamp(value: int, low: int, high: int) -> int: def clamp_to_byte(value: int) -> int: return max(0, min(255, value)) + + +def median(values: list[float]) -> float: + if not values: + raise ValueError + sorted_values = sorted(values) + n = len(sorted_values) + mid = n // 2 + if n % 2 == 1: + return sorted_values[mid] + return (sorted_values[mid - 1] + sorted_values[mid]) / 2.0