feat: Please review the whole project and add optimizations #29

Open
typosaurus wants to merge 6 commits from typosaurus/28-please-review-the-whole-project-and-add-optimizations into main
2 changed files with 89 additions and 0 deletions
Showing only changes of commit 475a6003f4 - Show all commits

View File

@ -113,6 +113,90 @@ Response:
{"result": 255}
```
### POST /api/v1/calculator/average
Compute the arithmetic mean of a list of values.
Request:
```json
{"values": [1, 2, 3, 4, 5]}
```
Response:
```json
{"result": 3.0}
```
An empty list produces a 422 validation response.
### POST /api/v1/calculator/median
Compute the median of a list of values. Values are sorted internally; an even-length list returns the average of the two middle values as a float.
Request:
```json
{"values": [1, 3, 5]}
```
Response:
```json
{"result": 3.0}
```
Request (even length):
```json
{"values": [1, 2, 3, 4]}
```
Response:
```json
{"result": 2.5}
```
An empty list produces a 422 validation response.
### POST /api/v1/calculator/variance
Compute the population variance of a list of values.
Request:
```json
{"values": [1, 2, 3, 4, 5]}
```
Response:
```json
{"result": 2.0}
```
An empty list produces a 422 validation response.
### POST /api/v1/calculator/percentage
Compute what percentage `value` is of `total`.
Request:
```json
{"value": 50, "total": 100}
```
Response:
```json
{"result": 50.0}
```
A zero `total` produces a 422 validation response.
## Verification
```sh
@ -121,3 +205,4 @@ make verify
Runs compile-all checks against all source and test files, then executes the full test suite.
Zero warnings are tolerated.

View File

@ -1,6 +1,9 @@
# retoor <retoor@molodetz.nl>
import unittest
import warnings
warnings.filterwarnings("ignore", category=DeprecationWarning, module="starlette")
from fastapi.testclient import TestClient
@ -248,3 +251,4 @@ class TestCalculatorPercentageEndpoint(unittest.TestCase):
self.assertEqual(response.status_code, 422)