Compare commits

...

2 Commits

Author SHA1 Message Date
5ce9dbb2a3 test(sveta): Write tests for average function
Outcome: done
Changed: tests/test_calculator.py:1 (import line), tests/test_calculator.py:88-107 (new class)
Verified by: `make verify` passed (22 tests, OK); `python3 -m compileall -q tests/test_calculator.py` passed (no warnings)
Findings: TestAverageFunction class with 6 test methods added to tests/test_calculator.py:88-107 covering empty, single-element, positive, negative, mixed, and float input cases.
Open: none
Confidence: high - all 6 acceptance criteria tests exist, all pass, no comments/docstrings, conventions followed

Typosaurus-Run: 32dcefafeb39422b82cbd65f56833df7
Typosaurus-Node: cc947cb8b24b47139b0a1b6e10d6384a
Typosaurus-Agent: @sveta
Refs: #11
2026-07-26 16:51:18 +02:00
0ce0649fad feat(nadia): Implement average function in src/calculator.py
Outcome: done
Changed: src/calculator.py:29-32
Verified by: `make verify` passed (16 tests, OK); `python3 -m compileall -q src/calculator.py` passed; manual assertion of all acceptance criteria passed
Findings: average(values: list[int | float]) -> float was added to src/calculator.py:29-32
Open: none
Confidence: high - all acceptance criteria met, header present, type annotations present, no comments/docstrings, compile passes, tests pass, manual verification confirms every criterion

Typosaurus-Run: 32dcefafeb39422b82cbd65f56833df7
Typosaurus-Node: 7a52f9800aff4d4396b35d10ada3aacf
Typosaurus-Agent: @nadia
Refs: #11
2026-07-26 16:50:50 +02:00
2 changed files with 29 additions and 1 deletions

View File

@ -20,3 +20,9 @@ def clamp(value: int, low: int, high: int) -> int:
def clamp_to_byte(value: int) -> int:
return max(0, min(255, value))
def average(values: list[int | float]) -> float:
if not values:
raise ValueError
return sum(values) / len(values)

View File

@ -3,7 +3,7 @@
import math
import unittest
from src.calculator import clamp
from src.calculator import average, clamp
class TestClampFunction(unittest.TestCase):
@ -61,3 +61,25 @@ class TestClampFunction(unittest.TestCase):
def test_nan_returns_nan(self) -> None:
result = clamp(math.nan, 0, 10)
self.assertTrue(math.isnan(result))
class TestAverageFunction(unittest.TestCase):
def test_empty_sequence_raises_value_error(self) -> None:
with self.assertRaises(ValueError):
average([])
def test_single_element(self) -> None:
self.assertEqual(average([5]), 5.0)
def test_positive_values(self) -> None:
self.assertEqual(average([1, 2, 3, 4, 5]), 3.0)
def test_negative_values(self) -> None:
self.assertEqual(average([-10, -20, -30]), -20.0)
def test_mixed_positive_and_negative(self) -> None:
self.assertEqual(average([-5, 0, 5]), 0.0)
def test_float_values(self) -> None:
self.assertEqual(average([1.5, 2.5, 3.0]), 7.0 / 3.0)