test(sveta): Write tests for variance function
Outcome: done Changed: tests/test_calculator.py:2, tests/test_calculator.py:67-97 Verified by: make verify — exit 0, all 24 tests pass (8 variance tests OK) Findings: Import line updated to include variance from src.calculator at tests/test_calculator.py:4 Findings: TestVarianceFunction class added at tests/test_calculator.py:67-97 with 8 test methods Findings: Empty sequence coverage split into list and tuple cases at lines 69-76 Findings: Single element returns 0.0 at line 78 Findings: Constant values return 0.0 at line 81 Findings: Known set [1,2,3,4,5] yields variance 2.0 at line 84 Findings: Two-element edge case [0,2] yields variance 1.0 at line 87 Findings: Integer inputs produce float result at line 90 Findings: Tuple input accepted as Sequence at line 95 Findings: All patterns match existing test conventions — no comments, no docstrings, full type annotations, proper header Open: none Confidence: high — all acceptance criteria covered, pattern-consistent, verified pass Typosaurus-Run: 918d38b1535b44bea9a86b82deae5233 Typosaurus-Node: 3f6d4a888da94bb99d585efb53106ebd Typosaurus-Agent: @sveta Refs: #19
This commit is contained in:
parent
3c5079a9d8
commit
2f86b1c6cc
@ -3,7 +3,7 @@
|
||||
import math
|
||||
import unittest
|
||||
|
||||
from src.calculator import clamp
|
||||
from src.calculator import clamp, variance
|
||||
|
||||
|
||||
class TestClampFunction(unittest.TestCase):
|
||||
@ -61,3 +61,36 @@ class TestClampFunction(unittest.TestCase):
|
||||
def test_nan_returns_nan(self) -> None:
|
||||
result = clamp(math.nan, 0, 10)
|
||||
self.assertTrue(math.isnan(result))
|
||||
|
||||
|
||||
class TestVarianceFunction(unittest.TestCase):
|
||||
|
||||
def test_empty_list_raises_value_error(self) -> None:
|
||||
with self.assertRaises(ValueError):
|
||||
variance([])
|
||||
|
||||
def test_empty_tuple_raises_value_error(self) -> None:
|
||||
with self.assertRaises(ValueError):
|
||||
variance(())
|
||||
|
||||
def test_single_element_returns_zero(self) -> None:
|
||||
self.assertEqual(variance([42.0]), 0.0)
|
||||
|
||||
def test_constant_values_return_zero_variance(self) -> None:
|
||||
self.assertEqual(variance([1.0, 1.0, 1.0]), 0.0)
|
||||
|
||||
def test_population_variance_of_known_set(self) -> None:
|
||||
self.assertEqual(variance([1, 2, 3, 4, 5]), 2.0)
|
||||
|
||||
def test_two_element_variance(self) -> None:
|
||||
self.assertEqual(variance([0, 2]), 1.0)
|
||||
|
||||
def test_integer_inputs_return_float(self) -> None:
|
||||
result = variance([10, 20, 30])
|
||||
self.assertIsInstance(result, float)
|
||||
self.assertEqual(result, 200.0 / 3.0)
|
||||
|
||||
def test_tuple_input_returns_variance(self) -> None:
|
||||
self.assertEqual(variance((1, 2, 3, 4, 5)), 2.0)
|
||||
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user