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
This commit is contained in:
@@ -0,0 +1 @@
|
||||
# retoor <retoor@molodetz.nl>
|
||||
@@ -0,0 +1,6 @@
|
||||
# retoor <retoor@molodetz.nl>
|
||||
|
||||
from typosaurus_sandbox.domain.calculator.operations import add, clamp, clamp_to_byte, subtract, variance
|
||||
|
||||
__all__ = ["add", "subtract", "clamp", "clamp_to_byte", "variance"]
|
||||
|
||||
@@ -0,0 +1,33 @@
|
||||
# retoor <retoor@molodetz.nl>
|
||||
|
||||
from typing import Sequence
|
||||
|
||||
|
||||
def add(left: int, right: int) -> int:
|
||||
return left + right
|
||||
|
||||
|
||||
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))
|
||||
|
||||
|
||||
def variance(values: Sequence[float]) -> float:
|
||||
if not values:
|
||||
raise ValueError
|
||||
mean = sum(values) / len(values)
|
||||
return sum((x - mean) ** 2 for x in values) / len(values)
|
||||
|
||||
Reference in New Issue
Block a user