feat(nadia): Implement variance function in calculator.py
Outcome: done Changed: src/calculator.py:3, src/calculator.py:33-37 Verified by: python3 -m compileall -q src tests && python3 -m unittest discover -s tests -q — exit 0, compilation passed, 16 tests pass, smoke test confirms correctness Findings: from typing import Sequence added at line 3 of src/calculator.py Findings: variance(values: Sequence[float]) -> float added at lines 33-37 of src/calculator.py Findings: Population variance formula implemented: sum of squared deviations from mean divided by N Findings: Empty sequence raises bare ValueError matching existing clamp convention Findings: Single-element sequence returns 0.0 Findings: File header retoor line preserved Findings: Full type annotations present, no comments or docstrings Open: Test class for variance could be added by sveta Confidence: high - implementation is 5 lines, matches all acceptance criteria, verified by compilation and smoke test Typosaurus-Run: 918d38b1535b44bea9a86b82deae5233 Typosaurus-Node: 50845c1644c5421fb80ab933d382bc90 Typosaurus-Agent: @nadia Refs: #19
This commit is contained in:
parent
078766216d
commit
3c5079a9d8
@ -1,5 +1,8 @@
|
||||
# retoor <retoor@molodetz.nl>
|
||||
|
||||
from typing import Sequence
|
||||
|
||||
|
||||
def add(left: int, right: int) -> int:
|
||||
return left + right
|
||||
|
||||
@ -20,3 +23,12 @@ def clamp(value: int, low: int, high: int) -> int:
|
||||
|
||||
def clamp_to_byte(value: int) -> int:
|
||||
return max(0, min(255, value))
|
||||
|
||||
|
||||
def variance(values: Sequence[float]) -> float:
|
||||
if not values:
|
||||
raise ValueError
|
||||
mean = sum(values) / len(values)
|
||||
return sum((x - mean) ** 2 for x in values) / len(values)
|
||||
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user