test(sveta): Add tests for new endpoints and missing unit test coverage
Outcome: done Changed: tests/test_calculator.py:5, tests/test_calculator.py:213-260 Verified by: `make verify` — passed, 104 tests, 0 failures Findings: - tests/test_calculator.py:5 — added `percentage` to the import from `typosaurus_sandbox.domain.calculator` - tests/test_calculator.py:212-260 — added `TestPercentageFunction` class with 11 unit tests covering: success cases (half, quarter, zero, exceeds total), negative inputs (negative value, negative total, both negative), float inputs, total-zero error paths (integer and float zero), and return type verification (integer inputs yield float result) - All 104 tests pass under `make verify` with zero failures (93 existing + 11 new percentage unit tests) Open: none Confidence: high — all acceptance criteria met; API tests were already completed by sibling node (expose-missing-operations); percentage unit tests now complete unit test coverage; verification passed Typosaurus-Run: 34b5946ec981488091bee588eb919ff2 Typosaurus-Node: f085f049a7424a628ea68af395e24072 Typosaurus-Agent: @sveta Refs: #28
This commit is contained in:
parent
41bad19a76
commit
b862242418
@ -3,7 +3,7 @@
|
||||
import math
|
||||
import unittest
|
||||
|
||||
from typosaurus_sandbox.domain.calculator import add, average, clamp, clamp_to_byte, median, subtract, variance
|
||||
from typosaurus_sandbox.domain.calculator import add, average, clamp, clamp_to_byte, median, percentage, subtract, variance
|
||||
|
||||
|
||||
class TestAddFunction(unittest.TestCase):
|
||||
@ -181,3 +181,46 @@ class TestVarianceFunction(unittest.TestCase):
|
||||
def test_tuple_input_returns_variance(self) -> None:
|
||||
self.assertEqual(variance((1, 2, 3, 4, 5)), 2.0)
|
||||
|
||||
|
||||
class TestPercentageFunction(unittest.TestCase):
|
||||
|
||||
def test_half_returns_50(self) -> None:
|
||||
self.assertEqual(percentage(50, 100), 50.0)
|
||||
|
||||
def test_quarter_returns_25(self) -> None:
|
||||
self.assertEqual(percentage(25, 100), 25.0)
|
||||
|
||||
def test_zero_value_returns_zero(self) -> None:
|
||||
self.assertEqual(percentage(0, 100), 0.0)
|
||||
|
||||
def test_value_exceeds_total(self) -> None:
|
||||
self.assertEqual(percentage(150, 100), 150.0)
|
||||
|
||||
def test_negative_value(self) -> None:
|
||||
self.assertEqual(percentage(-50, 100), -50.0)
|
||||
|
||||
def test_negative_total(self) -> None:
|
||||
self.assertEqual(percentage(50, -100), -50.0)
|
||||
|
||||
def test_both_negative(self) -> None:
|
||||
self.assertEqual(percentage(-50, -100), 50.0)
|
||||
|
||||
def test_float_inputs(self) -> None:
|
||||
result = percentage(33.0, 100.0)
|
||||
self.assertAlmostEqual(result, 33.0)
|
||||
|
||||
def test_total_zero_raises_value_error(self) -> None:
|
||||
with self.assertRaises(ValueError):
|
||||
percentage(50, 0)
|
||||
|
||||
def test_total_zero_float_raises_value_error(self) -> None:
|
||||
with self.assertRaises(ValueError):
|
||||
percentage(50.0, 0.0)
|
||||
|
||||
def test_integer_inputs_return_float(self) -> None:
|
||||
result = percentage(1, 4)
|
||||
self.assertIsInstance(result, float)
|
||||
self.assertEqual(result, 25.0)
|
||||
|
||||
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user