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:01:51 +02:00
|
|
|
# retoor <retoor@molodetz.nl>
|
|
|
|
|
|
|
|
|
|
import math
|
|
|
|
|
import unittest
|
|
|
|
|
|
test(sveta): Write tests for median function
Outcome: done
Changed: tests/test_calculator.py:3, tests/test_calculator.py:68-90
Verified by: make verify — exit code 0, 22 tests passed, verification passed.
Findings:
- tests/test_calculator.py:3 — `median` imported alongside `clamp`.
- tests/test_calculator.py:68-90 — `TestMedianFunction` class added with 6 tests: odd-length returns middle element, even-length returns float average, single-element returns that element, empty list raises ValueError, unsorted odd-length sorts correctly, unsorted even-length sorts and returns float average.
- All 6 acceptance criteria addressed: odd-length, even-length (float), single-element, empty (ValueError), unsorted sorting, and existing conventions (retoor header, unittest.TestCase, full type annotations).
Open: none
Confidence: high — verification passed with all 22 tests, coverage confirmed against every acceptance criterion.
Typosaurus-Run: 529efb295dd94e799a5e47a9ef0c6c16
Typosaurus-Node: 341a13e1a6b04e838cc1ff6d643aab85
Typosaurus-Agent: @sveta
Refs: #13
2026-07-26 17:09:37 +02:00
|
|
|
from typosaurus_sandbox.domain.calculator import add, average, clamp, clamp_to_byte, median, subtract, variance
|
feat(nadia): Implement FastAPI application with calculator endpoints
```yaml
Outcome: done
Changed:
- pyproject.toml:1-18
- src/typosaurus_sandbox/__init__.py:1-4
- src/typosaurus_sandbox/__main__.py:1-8
- src/typosaurus_sandbox/app.py:1-18
- src/typosaurus_sandbox/domain/__init__.py:1-1
- src/typosaurus_sandbox/domain/calculator/__init__.py:1-6
- src/typosaurus_sandbox/domain/calculator/operations.py:1-23
- src/typosaurus_sandbox/presentation/__init__.py:1-1
- src/typosaurus_sandbox/presentation/api/__init__.py:1-1
- src/typosaurus_sandbox/presentation/api/v1/__init__.py:1-1
- src/typosaurus_sandbox/presentation/api/v1/calculator.py:1-63
- tests/__init__.py (unchanged)
- tests/test_calculator.py:1-95
- tests/test_api.py:1-120
- Makefile:2
- CLAUDE.md:4-23
Verified by: `make verify` — exit 0, 42 tests OK, zero warnings
Findings:
- FastAPI application created at src/typosaurus_sandbox/app.py with App importable as `from typosaurus_sandbox import App`.
- Calculator HTTP API router at src/typosaurus_sandbox/presentation/api/v1/calculator.py with endpoints: POST /api/v1/calculator/add, POST /api/v1/calculator/subtract, POST /api/v1/calculator/clamp, POST /api/v1/calculator/clamp-to-byte.
- Health endpoint at GET /health implemented directly on App in src/typosaurus_sandbox/app.py.
- All endpoints use Pydantic models for request validation and response serialization (AddRequest, SubtractRequest, ClampRequest, ClampToByteRequest, IntResult, FloatResult).
- 42 tests pass (16 unit tests for calculator function
Typosaurus-Run: d4f7c095ea9d49c69663ae6d01a21513
Typosaurus-Node: d0f507214bf6453cab8f8d19b8fd2040
Typosaurus-Agent: @nadia
Refs: #15
2026-07-26 18:38:43 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
class TestAddFunction(unittest.TestCase):
|
|
|
|
|
|
|
|
|
|
def test_add_positive_integers(self) -> None:
|
|
|
|
|
self.assertEqual(add(3, 5), 8)
|
|
|
|
|
|
|
|
|
|
def test_add_negative_integers(self) -> None:
|
|
|
|
|
self.assertEqual(add(-3, -5), -8)
|
|
|
|
|
|
|
|
|
|
def test_add_mixed_sign(self) -> None:
|
|
|
|
|
self.assertEqual(add(-3, 5), 2)
|
|
|
|
|
|
|
|
|
|
|
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
|
|
|
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)
|
|
|
|
|
|
|
|
|
|
|
feat(nadia): Implement FastAPI application with calculator endpoints
```yaml
Outcome: done
Changed:
- pyproject.toml:1-18
- src/typosaurus_sandbox/__init__.py:1-4
- src/typosaurus_sandbox/__main__.py:1-8
- src/typosaurus_sandbox/app.py:1-18
- src/typosaurus_sandbox/domain/__init__.py:1-1
- src/typosaurus_sandbox/domain/calculator/__init__.py:1-6
- src/typosaurus_sandbox/domain/calculator/operations.py:1-23
- src/typosaurus_sandbox/presentation/__init__.py:1-1
- src/typosaurus_sandbox/presentation/api/__init__.py:1-1
- src/typosaurus_sandbox/presentation/api/v1/__init__.py:1-1
- src/typosaurus_sandbox/presentation/api/v1/calculator.py:1-63
- tests/__init__.py (unchanged)
- tests/test_calculator.py:1-95
- tests/test_api.py:1-120
- Makefile:2
- CLAUDE.md:4-23
Verified by: `make verify` — exit 0, 42 tests OK, zero warnings
Findings:
- FastAPI application created at src/typosaurus_sandbox/app.py with App importable as `from typosaurus_sandbox import App`.
- Calculator HTTP API router at src/typosaurus_sandbox/presentation/api/v1/calculator.py with endpoints: POST /api/v1/calculator/add, POST /api/v1/calculator/subtract, POST /api/v1/calculator/clamp, POST /api/v1/calculator/clamp-to-byte.
- Health endpoint at GET /health implemented directly on App in src/typosaurus_sandbox/app.py.
- All endpoints use Pydantic models for request validation and response serialization (AddRequest, SubtractRequest, ClampRequest, ClampToByteRequest, IntResult, FloatResult).
- 42 tests pass (16 unit tests for calculator function
Typosaurus-Run: d4f7c095ea9d49c69663ae6d01a21513
Typosaurus-Node: d0f507214bf6453cab8f8d19b8fd2040
Typosaurus-Agent: @nadia
Refs: #15
2026-07-26 18:38:43 +02:00
|
|
|
class TestSubtractFunction(unittest.TestCase):
|
|
|
|
|
|
|
|
|
|
def test_subtract_positive(self) -> None:
|
|
|
|
|
self.assertEqual(subtract(10, 3), 7)
|
|
|
|
|
|
|
|
|
|
def test_subtract_negative_result(self) -> None:
|
|
|
|
|
self.assertEqual(subtract(3, 10), -7)
|
|
|
|
|
|
|
|
|
|
def test_subtract_negative_numbers(self) -> None:
|
|
|
|
|
self.assertEqual(subtract(-5, -3), -2)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class TestClampToByteFunction(unittest.TestCase):
|
|
|
|
|
|
|
|
|
|
def test_clamp_to_byte_within_range(self) -> None:
|
|
|
|
|
self.assertEqual(clamp_to_byte(128), 128)
|
|
|
|
|
|
|
|
|
|
def test_clamp_to_byte_below_zero(self) -> None:
|
|
|
|
|
self.assertEqual(clamp_to_byte(-10), 0)
|
|
|
|
|
|
|
|
|
|
def test_clamp_to_byte_above_255(self) -> None:
|
|
|
|
|
self.assertEqual(clamp_to_byte(300), 255)
|
|
|
|
|
|
|
|
|
|
def test_clamp_to_byte_boundaries(self) -> None:
|
|
|
|
|
self.assertEqual(clamp_to_byte(0), 0)
|
|
|
|
|
self.assertEqual(clamp_to_byte(255), 255)
|
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:01:51 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
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))
|
test(sveta): Write tests for variance function
Outcome: done
Changed: tests/test_calculator.py:2, tests/test_calculator.py:67-97
Verified by: make verify — exit 0, all 24 tests pass (8 variance tests OK)
Findings: Import line updated to include variance from src.calculator at tests/test_calculator.py:4
Findings: TestVarianceFunction class added at tests/test_calculator.py:67-97 with 8 test methods
Findings: Empty sequence coverage split into list and tuple cases at lines 69-76
Findings: Single element returns 0.0 at line 78
Findings: Constant values return 0.0 at line 81
Findings: Known set [1,2,3,4,5] yields variance 2.0 at line 84
Findings: Two-element edge case [0,2] yields variance 1.0 at line 87
Findings: Integer inputs produce float result at line 90
Findings: Tuple input accepted as Sequence at line 95
Findings: All patterns match existing test conventions — no comments, no docstrings, full type annotations, proper header
Open: none
Confidence: high — all acceptance criteria covered, pattern-consistent, verified pass
Typosaurus-Run: 918d38b1535b44bea9a86b82deae5233
Typosaurus-Node: 3f6d4a888da94bb99d585efb53106ebd
Typosaurus-Agent: @sveta
Refs: #19
2026-07-26 19:07:10 +02:00
|
|
|
|
|
|
|
|
|
test(sveta): Write tests for median function
Outcome: done
Changed: tests/test_calculator.py:3, tests/test_calculator.py:68-90
Verified by: make verify — exit code 0, 22 tests passed, verification passed.
Findings:
- tests/test_calculator.py:3 — `median` imported alongside `clamp`.
- tests/test_calculator.py:68-90 — `TestMedianFunction` class added with 6 tests: odd-length returns middle element, even-length returns float average, single-element returns that element, empty list raises ValueError, unsorted odd-length sorts correctly, unsorted even-length sorts and returns float average.
- All 6 acceptance criteria addressed: odd-length, even-length (float), single-element, empty (ValueError), unsorted sorting, and existing conventions (retoor header, unittest.TestCase, full type annotations).
Open: none
Confidence: high — verification passed with all 22 tests, coverage confirmed against every acceptance criterion.
Typosaurus-Run: 529efb295dd94e799a5e47a9ef0c6c16
Typosaurus-Node: 341a13e1a6b04e838cc1ff6d643aab85
Typosaurus-Agent: @sveta
Refs: #13
2026-07-26 17:09:37 +02:00
|
|
|
class TestMedianFunction(unittest.TestCase):
|
|
|
|
|
|
|
|
|
|
def test_odd_length_returns_middle_element(self) -> None:
|
|
|
|
|
self.assertEqual(median([1, 3, 5]), 3)
|
|
|
|
|
|
|
|
|
|
def test_even_length_returns_float_average_of_two_middle_values(self) -> None:
|
|
|
|
|
result = median([1, 2, 3, 4])
|
|
|
|
|
self.assertIsInstance(result, float)
|
|
|
|
|
self.assertEqual(result, 2.5)
|
|
|
|
|
|
|
|
|
|
def test_single_element_returns_that_element(self) -> None:
|
|
|
|
|
self.assertEqual(median([7]), 7)
|
|
|
|
|
|
|
|
|
|
def test_empty_list_raises_value_error(self) -> None:
|
|
|
|
|
with self.assertRaises(ValueError):
|
|
|
|
|
median([])
|
|
|
|
|
|
|
|
|
|
def test_unsorted_input_sorts_correctly(self) -> None:
|
|
|
|
|
self.assertEqual(median([3, 1, 2]), 2)
|
|
|
|
|
|
|
|
|
|
def test_unsorted_even_length_returns_float_average(self) -> None:
|
|
|
|
|
result = median([10, 30, 20, 40])
|
|
|
|
|
self.assertIsInstance(result, float)
|
|
|
|
|
self.assertEqual(result, 25.0)
|
|
|
|
|
|
|
|
|
|
|
test(sveta): Write tests for variance function
Outcome: done
Changed: tests/test_calculator.py:2, tests/test_calculator.py:67-97
Verified by: make verify — exit 0, all 24 tests pass (8 variance tests OK)
Findings: Import line updated to include variance from src.calculator at tests/test_calculator.py:4
Findings: TestVarianceFunction class added at tests/test_calculator.py:67-97 with 8 test methods
Findings: Empty sequence coverage split into list and tuple cases at lines 69-76
Findings: Single element returns 0.0 at line 78
Findings: Constant values return 0.0 at line 81
Findings: Known set [1,2,3,4,5] yields variance 2.0 at line 84
Findings: Two-element edge case [0,2] yields variance 1.0 at line 87
Findings: Integer inputs produce float result at line 90
Findings: Tuple input accepted as Sequence at line 95
Findings: All patterns match existing test conventions — no comments, no docstrings, full type annotations, proper header
Open: none
Confidence: high — all acceptance criteria covered, pattern-consistent, verified pass
Typosaurus-Run: 918d38b1535b44bea9a86b82deae5233
Typosaurus-Node: 3f6d4a888da94bb99d585efb53106ebd
Typosaurus-Agent: @sveta
Refs: #19
2026-07-26 19:07:10 +02:00
|
|
|
class TestVarianceFunction(unittest.TestCase):
|
|
|
|
|
|
|
|
|
|
def test_empty_list_raises_value_error(self) -> None:
|
|
|
|
|
with self.assertRaises(ValueError):
|
|
|
|
|
variance([])
|
|
|
|
|
|
|
|
|
|
def test_empty_tuple_raises_value_error(self) -> None:
|
|
|
|
|
with self.assertRaises(ValueError):
|
|
|
|
|
variance(())
|
|
|
|
|
|
|
|
|
|
def test_single_element_returns_zero(self) -> None:
|
|
|
|
|
self.assertEqual(variance([42.0]), 0.0)
|
|
|
|
|
|
|
|
|
|
def test_constant_values_return_zero_variance(self) -> None:
|
|
|
|
|
self.assertEqual(variance([1.0, 1.0, 1.0]), 0.0)
|
|
|
|
|
|
|
|
|
|
def test_population_variance_of_known_set(self) -> None:
|
|
|
|
|
self.assertEqual(variance([1, 2, 3, 4, 5]), 2.0)
|
|
|
|
|
|
|
|
|
|
def test_two_element_variance(self) -> None:
|
|
|
|
|
self.assertEqual(variance([0, 2]), 1.0)
|
|
|
|
|
|
|
|
|
|
def test_integer_inputs_return_float(self) -> None:
|
|
|
|
|
result = variance([10, 20, 30])
|
|
|
|
|
self.assertIsInstance(result, float)
|
|
|
|
|
self.assertEqual(result, 200.0 / 3.0)
|
|
|
|
|
|
|
|
|
|
def test_tuple_input_returns_variance(self) -> None:
|
|
|
|
|
self.assertEqual(variance((1, 2, 3, 4, 5)), 2.0)
|
|
|
|
|
|