From 3c5079a9d8ebfcd3e2702e59fe65de63c1adafa5 Mon Sep 17 00:00:00 2001 From: typosaurus Date: Sun, 26 Jul 2026 17:06:20 +0000 Subject: [PATCH] feat(nadia): Implement variance function in calculator.py MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- src/calculator.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/calculator.py b/src/calculator.py index e4e6afd..69ae964 100644 --- a/src/calculator.py +++ b/src/calculator.py @@ -1,5 +1,8 @@ # retoor +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) + +