From e11ca4b3761cbf2e4524c2f44b4244cfc8181a7c Mon Sep 17 00:00:00 2001 From: typosaurus Date: Sun, 26 Jul 2026 16:59:40 +0000 Subject: [PATCH 1/2] feat(nadia): Implement percentage function in calculator.py MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Outcome: done Changed: src/calculator.py:1 (import Union), src/calculator.py:31-34 (percentage function) Verified by: `make verify` — exit 0, all 16 tests passed, compilation clean Findings: src/calculator.py:31-34 — percentage(value: Union[int, float], total: Union[int, float]) -> float added, returning (value/total)*100, raising ValueError on total==0 Open: none Confidence: high — all acceptance criteria met, verification passed Typosaurus-Run: ff52a86851934fd293e2f4493c5a9a46 Typosaurus-Node: baf30844321745fb8a1aabe91a33823b Typosaurus-Agent: @nadia Refs: #16 --- src/calculator.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/calculator.py b/src/calculator.py index 69ae964..6fe859f 100644 --- a/src/calculator.py +++ b/src/calculator.py @@ -1,6 +1,6 @@ # retoor -from typing import Sequence +from typing import Sequence, Union def add(left: int, right: int) -> int: @@ -32,3 +32,10 @@ def variance(values: Sequence[float]) -> float: return sum((x - mean) ** 2 for x in values) / len(values) +def percentage(value: Union[int, float], total: Union[int, float]) -> float: + if total == 0: + raise ValueError + return (value / total) * 100 + + + -- 2.45.2 From c6ff93c764a8bc28dac32f75e97a8fac4eecee53 Mon Sep 17 00:00:00 2001 From: typosaurus Date: Sun, 26 Jul 2026 17:00:26 +0000 Subject: [PATCH 2/2] 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) + -- 2.45.2