Compare commits

...
3 Commits
Author SHA1 Message Date
typosaurus 2ee246fad6 Merge pull request 'feat: Add a percentage function to the calculator' (#18) from typosaurus/16-add-a-percentage-function-to-the-calculator into main
Reviewed-on: #18
2026-07-26 21:51:01 +02:00
typosaurus c6ff93c764 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
2026-07-26 17:45:06 +00:00
typosaurus e11ca4b376 feat(nadia): Implement percentage function in calculator.py
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
2026-07-26 17:44:38 +00:00
2 changed files with 35 additions and 2 deletions
+8 -1
View File
@@ -1,6 +1,6 @@
# retoor <retoor@molodetz.nl>
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
+27 -1
View File
@@ -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)