From c6ff93c764a8bc28dac32f75e97a8fac4eecee53 Mon Sep 17 00:00:00 2001 From: typosaurus Date: Sun, 26 Jul 2026 17:00:26 +0000 Subject: [PATCH] test(sveta): Write tests for percentage function MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- tests/test_calculator.py | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/tests/test_calculator.py b/tests/test_calculator.py index 21de386..86d3387 100644 --- a/tests/test_calculator.py +++ b/tests/test_calculator.py @@ -3,7 +3,7 @@ import math import unittest -from src.calculator import clamp, variance +from src.calculator import clamp, percentage, variance class TestClampFunction(unittest.TestCase): @@ -63,6 +63,31 @@ class TestClampFunction(unittest.TestCase): 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): 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) +