test(sveta): Write tests for percentage function
Outcome: done Changed: tests/test_calculator.py:1 (import), tests/test_calculator.py:66-96 (new TestPercentageFunction class) Verified by: `make verify` — exit 0, Ran 23 tests, OK Findings: tests/test_calculator.py:66-96 — TestPercentageFunction class added with 7 test methods (valid_percentage, zero_value, full_value, fractional, total_zero, float_arguments, negative_value). All 23 tests pass. Open: none Confidence: high — all acceptance criteria met, verification passed Typosaurus-Run: ff52a86851934fd293e2f4493c5a9a46 Typosaurus-Node: 7edce3239d434d36aed06535aae0d0ad Typosaurus-Agent: @sveta Refs: #16
This commit is contained in:
parent
e11ca4b376
commit
c6ff93c764
@ -3,7 +3,7 @@
|
|||||||
import math
|
import math
|
||||||
import unittest
|
import unittest
|
||||||
|
|
||||||
from src.calculator import clamp, variance
|
from src.calculator import clamp, percentage, variance
|
||||||
|
|
||||||
|
|
||||||
class TestClampFunction(unittest.TestCase):
|
class TestClampFunction(unittest.TestCase):
|
||||||
@ -63,6 +63,31 @@ class TestClampFunction(unittest.TestCase):
|
|||||||
self.assertTrue(math.isnan(result))
|
self.assertTrue(math.isnan(result))
|
||||||
|
|
||||||
|
|
||||||
|
class TestPercentageFunction(unittest.TestCase):
|
||||||
|
|
||||||
|
def test_valid_percentage(self) -> None:
|
||||||
|
self.assertEqual(percentage(50, 200), 25.0)
|
||||||
|
|
||||||
|
def test_zero_value(self) -> None:
|
||||||
|
self.assertEqual(percentage(0, 100), 0.0)
|
||||||
|
|
||||||
|
def test_full_value(self) -> None:
|
||||||
|
self.assertEqual(percentage(200, 100), 200.0)
|
||||||
|
|
||||||
|
def test_fractional(self) -> None:
|
||||||
|
self.assertAlmostEqual(percentage(1, 3), 33.333333333333336)
|
||||||
|
|
||||||
|
def test_total_zero(self) -> None:
|
||||||
|
with self.assertRaises(ValueError):
|
||||||
|
percentage(50, 0)
|
||||||
|
|
||||||
|
def test_float_arguments(self) -> None:
|
||||||
|
self.assertEqual(percentage(25.5, 100.0), 25.5)
|
||||||
|
|
||||||
|
def test_negative_value(self) -> None:
|
||||||
|
self.assertEqual(percentage(-50, 200), -25.0)
|
||||||
|
|
||||||
|
|
||||||
class TestVarianceFunction(unittest.TestCase):
|
class TestVarianceFunction(unittest.TestCase):
|
||||||
|
|
||||||
def test_empty_list_raises_value_error(self) -> None:
|
def test_empty_list_raises_value_error(self) -> None:
|
||||||
@ -94,3 +119,4 @@ class TestVarianceFunction(unittest.TestCase):
|
|||||||
self.assertEqual(variance((1, 2, 3, 4, 5)), 2.0)
|
self.assertEqual(variance((1, 2, 3, 4, 5)), 2.0)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user