test(sveta): Write tests for median function
Outcome: done Changed: tests/test_calculator.py:3, tests/test_calculator.py:68-90 Verified by: make verify — exit code 0, 22 tests passed, verification passed. Findings: - tests/test_calculator.py:3 — `median` imported alongside `clamp`. - tests/test_calculator.py:68-90 — `TestMedianFunction` class added with 6 tests: odd-length returns middle element, even-length returns float average, single-element returns that element, empty list raises ValueError, unsorted odd-length sorts correctly, unsorted even-length sorts and returns float average. - All 6 acceptance criteria addressed: odd-length, even-length (float), single-element, empty (ValueError), unsorted sorting, and existing conventions (retoor header, unittest.TestCase, full type annotations). Open: none Confidence: high — verification passed with all 22 tests, coverage confirmed against every acceptance criterion. Typosaurus-Run: 529efb295dd94e799a5e47a9ef0c6c16 Typosaurus-Node: 341a13e1a6b04e838cc1ff6d643aab85 Typosaurus-Agent: @sveta Refs: #13
This commit is contained in:
parent
f06ab4d690
commit
b78ecc077e
@ -3,7 +3,7 @@
|
||||
import math
|
||||
import unittest
|
||||
|
||||
from src.calculator import clamp
|
||||
from src.calculator import clamp, median
|
||||
|
||||
|
||||
class TestClampFunction(unittest.TestCase):
|
||||
@ -61,3 +61,29 @@ class TestClampFunction(unittest.TestCase):
|
||||
def test_nan_returns_nan(self) -> None:
|
||||
result = clamp(math.nan, 0, 10)
|
||||
self.assertTrue(math.isnan(result))
|
||||
|
||||
|
||||
class TestMedianFunction(unittest.TestCase):
|
||||
|
||||
def test_odd_length_returns_middle_element(self) -> None:
|
||||
self.assertEqual(median([1, 3, 5]), 3)
|
||||
|
||||
def test_even_length_returns_float_average_of_two_middle_values(self) -> None:
|
||||
result = median([1, 2, 3, 4])
|
||||
self.assertIsInstance(result, float)
|
||||
self.assertEqual(result, 2.5)
|
||||
|
||||
def test_single_element_returns_that_element(self) -> None:
|
||||
self.assertEqual(median([7]), 7)
|
||||
|
||||
def test_empty_list_raises_value_error(self) -> None:
|
||||
with self.assertRaises(ValueError):
|
||||
median([])
|
||||
|
||||
def test_unsorted_input_sorts_correctly(self) -> None:
|
||||
self.assertEqual(median([3, 1, 2]), 2)
|
||||
|
||||
def test_unsorted_even_length_returns_float_average(self) -> None:
|
||||
result = median([10, 30, 20, 40])
|
||||
self.assertIsInstance(result, float)
|
||||
self.assertEqual(result, 25.0)
|
||||
|
||||
Loading…
Reference in New Issue
Block a user