Compare commits

...
Author SHA1 Message Date
typosaurus 5ce9dbb2a3 test(sveta): Write tests for average function
Outcome: done
Changed: tests/test_calculator.py:1 (import line), tests/test_calculator.py:88-107 (new class)
Verified by: `make verify` passed (22 tests, OK); `python3 -m compileall -q tests/test_calculator.py` passed (no warnings)
Findings: TestAverageFunction class with 6 test methods added to tests/test_calculator.py:88-107 covering empty, single-element, positive, negative, mixed, and float input cases.
Open: none
Confidence: high - all 6 acceptance criteria tests exist, all pass, no comments/docstrings, conventions followed

Typosaurus-Run: 32dcefafeb39422b82cbd65f56833df7
Typosaurus-Node: cc947cb8b24b47139b0a1b6e10d6384a
Typosaurus-Agent: @sveta
Refs: #11
2026-07-26 16:51:18 +02:00
typosaurus 0ce0649fad feat(nadia): Implement average function in src/calculator.py
Outcome: done
Changed: src/calculator.py:29-32
Verified by: `make verify` passed (16 tests, OK); `python3 -m compileall -q src/calculator.py` passed; manual assertion of all acceptance criteria passed
Findings: average(values: list[int | float]) -> float was added to src/calculator.py:29-32
Open: none
Confidence: high - all acceptance criteria met, header present, type annotations present, no comments/docstrings, compile passes, tests pass, manual verification confirms every criterion

Typosaurus-Run: 32dcefafeb39422b82cbd65f56833df7
Typosaurus-Node: 7a52f9800aff4d4396b35d10ada3aacf
Typosaurus-Agent: @nadia
Refs: #11
2026-07-26 16:50:50 +02:00
typosaurus 078766216d Merge pull request 'feat: Add a clamp function to the calculator' (#8) from typosaurus/7-add-a-clamp-function-to-the-calculator into main
Reviewed-on: #8
2026-07-25 19:04:56 +02:00
typosaurus 8605a8c596 test(sveta): Write clamp tests
Outcome: done
Changed: tests/__init__.py:1, tests/test_calculator.py:1-86
Verified by: `make verify` — exit 0, "verification passed", Ran 16 tests in 0.001s, OK
Findings: tests/ directory created at ./tests/ with __init__.py (header only) and test_calculator.py (16 tests for clamp).
Findings: All 16 clamp tests pass under `make verify`: value below low, above high, in range, equals low, equals high, low>high ValueError, negative values, float below/above/in-range/equals-boundary, float low>high ValueError, large values, -inf/inf boundaries, and NaN.
Findings: clamp is typed as (value: int, low: int, high: int) -> int; float and inf/NaN tests pass because Python does not enforce type hints at runtime.
Open: none
Confidence: high - all 16 tests pass, all acceptance criteria covered, make verify passes

Typosaurus-Run: 5b5c36bf38254bf4bfcdbde317991a5a
Typosaurus-Node: 56f03705c3d64023ba102d3aa3169ef2
Typosaurus-Agent: @sveta
Refs: #7
2026-07-25 19:04:03 +02:00
typosaurus c7f0712d12 feat(nadia): Implement clamp function
**Outcome:** done
**Changed:** src/calculator.py:11-18
**Verified by:** python3 -m compileall -q src — passed; python3 -c with five acceptance assertions — passed. make verify fails because tests/ directory does not exist.
**Findings:** clamp(value: int, low: int, high: int) -> int added at src/calculator.py:11 with no docstrings or comments. File header at src/calculator.py:1 is present. All functions use full int type annotations.
**Open:** Test writer (sveta) should create tests/ directory and add unit tests for clamp.
**Confidence:** high

Typosaurus-Run: 5b5c36bf38254bf4bfcdbde317991a5a
Typosaurus-Node: bf41377d70c446b1b80b9e058fe81fb8
Typosaurus-Agent: @nadia
Refs: #7
2026-07-25 19:04:03 +02:00
typosaurus 65ce7f1994 feat: add clamp_to_byte at the end of calculator 2026-07-25 19:01:02 +02:00
typosaurus f5363514bf chore: reset calculator to a clean baseline 2026-07-25 18:58:10 +02:00
typosaurus ff830c6fb8 feat: add gcd at the end of the file 2026-07-25 18:51:44 +02:00
typosaurus cb4c5516ad feat: add modulo and ignore build artifacts 2026-07-25 18:49:12 +02:00
typosaurus d5861fb2e3 Merge pull request 'feat: Add multiply and divide to the calculator' (#3) from typosaurus/2-add-multiply-and-divide-to-the-calculator into main
Reviewed-on: #3
2026-07-25 17:22:52 +02:00
6 changed files with 82 additions and 42 deletions
+2
View File
@@ -0,0 +1,2 @@
__pycache__/
*.pyc
Binary file not shown.
+16 -6
View File
@@ -8,11 +8,21 @@ def subtract(left: int, right: int) -> int:
return left - right
def multiply(left: int, right: int) -> int:
return left * right
def clamp(value: int, low: int, high: int) -> int:
if low > high:
raise ValueError
if value < low:
return low
if value > high:
return high
return value
def divide(left: int, right: int) -> int:
if right == 0:
raise ValueError('division by zero')
return left // right
def clamp_to_byte(value: int) -> int:
return max(0, min(255, value))
def average(values: list[int | float]) -> float:
if not values:
raise ValueError
return sum(values) / len(values)
+1
View File
@@ -0,0 +1 @@
# retoor <retoor@molodetz.nl>
Binary file not shown.
+63 -36
View File
@@ -1,58 +1,85 @@
# retoor <retoor@molodetz.nl>
import math
import unittest
from src.calculator import add, subtract, multiply, divide
from src.calculator import average, clamp
class TestCalculator(unittest.TestCase):
class TestClampFunction(unittest.TestCase):
def test_add(self) -> None:
self.assertEqual(add(2, 3), 5)
def test_value_below_low_returns_low(self) -> None:
self.assertEqual(clamp(-5, 0, 10), 0)
def test_subtract(self) -> None:
self.assertEqual(subtract(5, 3), 2)
def test_value_above_high_returns_high(self) -> None:
self.assertEqual(clamp(15, 0, 10), 10)
def test_multiply_positive(self) -> None:
self.assertEqual(multiply(2, 3), 6)
def test_value_in_range_returns_value(self) -> None:
self.assertEqual(clamp(5, 0, 10), 5)
def test_multiply_negative_left(self) -> None:
self.assertEqual(multiply(-2, 3), -6)
def test_value_equals_low_returns_low(self) -> None:
self.assertEqual(clamp(0, 0, 10), 0)
def test_multiply_negative_right(self) -> None:
self.assertEqual(multiply(2, -3), -6)
def test_value_equals_high_returns_high(self) -> None:
self.assertEqual(clamp(10, 0, 10), 10)
def test_multiply_both_negative(self) -> None:
self.assertEqual(multiply(-2, -3), 6)
def test_low_greater_than_high_raises_value_error(self) -> None:
with self.assertRaises(ValueError):
clamp(5, 10, 0)
def test_multiply_zero_left(self) -> None:
self.assertEqual(multiply(0, 5), 0)
def test_all_negative_values(self) -> None:
self.assertEqual(clamp(-10, -5, -1), -5)
def test_multiply_zero_right(self) -> None:
self.assertEqual(multiply(5, 0), 0)
def test_float_value_below_low_returns_low_as_int(self) -> None:
self.assertEqual(clamp(-1.0, 0, 10), 0)
def test_multiply_both_zero(self) -> None:
self.assertEqual(multiply(0, 0), 0)
def test_float_value_above_high_returns_high_as_int(self) -> None:
self.assertEqual(clamp(15.0, 0, 10), 10)
def test_divide_positive(self) -> None:
self.assertEqual(divide(6, 3), 2)
def test_float_value_in_range_returns_float(self) -> None:
result = clamp(5.0, 0, 10)
self.assertIsInstance(result, float)
self.assertEqual(result, 5.0)
def test_divide_negative_left(self) -> None:
self.assertEqual(divide(-6, 3), -2)
def test_float_value_equals_boundary_returns_boundary(self) -> None:
self.assertEqual(clamp(0.0, 0, 10), 0)
self.assertEqual(clamp(10.0, 0, 10), 10)
def test_divide_negative_right(self) -> None:
self.assertEqual(divide(6, -3), -2)
def test_float_low_greater_than_float_high_raises_value_error(self) -> None:
with self.assertRaises(ValueError):
clamp(5.0, 10.0, 0.0)
def test_divide_both_negative(self) -> None:
self.assertEqual(divide(-6, -3), 2)
def test_large_values(self) -> None:
self.assertEqual(clamp(10**9, 0, 10**6), 10**6)
def test_divide_floor(self) -> None:
self.assertEqual(divide(7, 3), 2)
def test_negative_infinity_not_clamped_by_default(self) -> None:
self.assertEqual(clamp(-math.inf, 0, 10), 0)
def test_divide_zero_numerator(self) -> None:
self.assertEqual(divide(0, 5), 0)
def test_positive_infinity_not_clamped_by_default(self) -> None:
self.assertEqual(clamp(math.inf, 0, 10), 10)
def test_divide_by_zero(self) -> None:
with self.assertRaises(ValueError) as cm:
divide(5, 0)
self.assertEqual(str(cm.exception), 'division by zero')
def test_nan_returns_nan(self) -> None:
result = clamp(math.nan, 0, 10)
self.assertTrue(math.isnan(result))
class TestAverageFunction(unittest.TestCase):
def test_empty_sequence_raises_value_error(self) -> None:
with self.assertRaises(ValueError):
average([])
def test_single_element(self) -> None:
self.assertEqual(average([5]), 5.0)
def test_positive_values(self) -> None:
self.assertEqual(average([1, 2, 3, 4, 5]), 3.0)
def test_negative_values(self) -> None:
self.assertEqual(average([-10, -20, -30]), -20.0)
def test_mixed_positive_and_negative(self) -> None:
self.assertEqual(average([-5, 0, 5]), 0.0)
def test_float_values(self) -> None:
self.assertEqual(average([1.5, 2.5, 3.0]), 7.0 / 3.0)