feat(nadia): Implement median function in src/calculator.py
**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
This commit is contained in:
parent
078766216d
commit
f06ab4d690
@ -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
|
||||
|
||||
Loading…
Reference in New Issue
Block a user