From c7f0712d124623493ea3b1f8f338f381d824508a Mon Sep 17 00:00:00 2001 From: typosaurus Date: Sat, 25 Jul 2026 19:00:59 +0200 Subject: [PATCH 1/2] feat(nadia): Implement clamp function MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit **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 --- src/calculator.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/calculator.py b/src/calculator.py index da4a182..e4e6afd 100644 --- a/src/calculator.py +++ b/src/calculator.py @@ -8,5 +8,15 @@ def subtract(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 clamp_to_byte(value: int) -> int: return max(0, min(255, value)) From 8605a8c5969e6c987c4e70885703f1d784e81cea Mon Sep 17 00:00:00 2001 From: typosaurus Date: Sat, 25 Jul 2026 19:01:51 +0200 Subject: [PATCH 2/2] test(sveta): Write clamp tests MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- tests/__init__.py | 1 + tests/test_calculator.py | 63 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 64 insertions(+) create mode 100644 tests/__init__.py create mode 100644 tests/test_calculator.py diff --git a/tests/__init__.py b/tests/__init__.py new file mode 100644 index 0000000..95ee7c3 --- /dev/null +++ b/tests/__init__.py @@ -0,0 +1 @@ +# retoor diff --git a/tests/test_calculator.py b/tests/test_calculator.py new file mode 100644 index 0000000..48d48d4 --- /dev/null +++ b/tests/test_calculator.py @@ -0,0 +1,63 @@ +# retoor + +import math +import unittest + +from src.calculator import clamp + + +class TestClampFunction(unittest.TestCase): + + def test_value_below_low_returns_low(self) -> None: + self.assertEqual(clamp(-5, 0, 10), 0) + + def test_value_above_high_returns_high(self) -> None: + self.assertEqual(clamp(15, 0, 10), 10) + + def test_value_in_range_returns_value(self) -> None: + self.assertEqual(clamp(5, 0, 10), 5) + + def test_value_equals_low_returns_low(self) -> None: + self.assertEqual(clamp(0, 0, 10), 0) + + def test_value_equals_high_returns_high(self) -> None: + self.assertEqual(clamp(10, 0, 10), 10) + + def test_low_greater_than_high_raises_value_error(self) -> None: + with self.assertRaises(ValueError): + clamp(5, 10, 0) + + def test_all_negative_values(self) -> None: + self.assertEqual(clamp(-10, -5, -1), -5) + + def test_float_value_below_low_returns_low_as_int(self) -> None: + self.assertEqual(clamp(-1.0, 0, 10), 0) + + def test_float_value_above_high_returns_high_as_int(self) -> None: + self.assertEqual(clamp(15.0, 0, 10), 10) + + 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_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_float_low_greater_than_float_high_raises_value_error(self) -> None: + with self.assertRaises(ValueError): + clamp(5.0, 10.0, 0.0) + + def test_large_values(self) -> None: + self.assertEqual(clamp(10**9, 0, 10**6), 10**6) + + def test_negative_infinity_not_clamped_by_default(self) -> None: + self.assertEqual(clamp(-math.inf, 0, 10), 0) + + def test_positive_infinity_not_clamped_by_default(self) -> None: + self.assertEqual(clamp(math.inf, 0, 10), 10) + + def test_nan_returns_nan(self) -> None: + result = clamp(math.nan, 0, 10) + self.assertTrue(math.isnan(result))