Compare commits
2
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a4ee545314 | ||
|
|
888abecd7f |
@@ -0,0 +1,21 @@
|
||||
# retoor <retoor@molodetz.nl>
|
||||
name: CI
|
||||
on:
|
||||
push:
|
||||
branches: [main, master]
|
||||
jobs:
|
||||
test:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- name: Set up Python 3.12
|
||||
uses: actions/setup-python@v5
|
||||
with:
|
||||
python-version: "3.12"
|
||||
- name: Install dependencies
|
||||
run: |
|
||||
python -m pip install --upgrade pip
|
||||
pip install -e .
|
||||
- name: Run tests
|
||||
run: make verify
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
# retoor <retoor@molodetz.nl>
|
||||
# typosaurus-sandbox
|
||||
|
||||
A minimal Python calculator used to verify the Typosaurus agent system.
|
||||
@@ -26,3 +27,11 @@ A minimal Python calculator used to verify the Typosaurus agent system.
|
||||
```
|
||||
make verify
|
||||
```
|
||||
|
||||
## CI
|
||||
|
||||
- Workflow file: `.gitea/workflows/ci.yml`
|
||||
- Trigger: push to `main` or `master` branches
|
||||
- Steps: checkout, Python 3.12 setup, dependency install, `make verify`
|
||||
|
||||
|
||||
|
||||
+3
-14
@@ -31,15 +31,11 @@ def average(values: list[int | float]) -> float:
|
||||
return sum(values) / len(values)
|
||||
|
||||
|
||||
def median(values: list[float]) -> float:
|
||||
def variance(values: Sequence[float]) -> float:
|
||||
if not values:
|
||||
raise ValueError
|
||||
sorted_values = sorted(values)
|
||||
n = len(sorted_values)
|
||||
mid = n // 2
|
||||
if n % 2 == 1:
|
||||
return sorted_values[mid]
|
||||
return (sorted_values[mid - 1] + sorted_values[mid]) / 2.0
|
||||
mean = sum(values) / len(values)
|
||||
return sum((x - mean) ** 2 for x in values) / len(values)
|
||||
|
||||
|
||||
def percentage(value: Union[int, float], total: Union[int, float]) -> float:
|
||||
@@ -47,10 +43,3 @@ def percentage(value: Union[int, float], total: Union[int, float]) -> float:
|
||||
raise ValueError
|
||||
return (value / total) * 100
|
||||
|
||||
|
||||
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)
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
# retoor <retoor@molodetz.nl>
|
||||
|
||||
from typosaurus_sandbox.domain.calculator.operations import add, average, clamp, clamp_to_byte, median, percentage, subtract, variance
|
||||
from typosaurus_sandbox.domain.calculator.operations import add, average, clamp, clamp_to_byte, percentage, subtract, variance
|
||||
|
||||
__all__ = ["add", "average", "clamp", "clamp_to_byte", "percentage", "subtract", "variance"]
|
||||
|
||||
__all__ = ["add", "average", "clamp", "clamp_to_byte", "median", "percentage", "subtract", "variance"]
|
||||
|
||||
|
||||
@@ -31,17 +31,6 @@ def average(values: list[int | float]) -> float:
|
||||
return sum(values) / len(values)
|
||||
|
||||
|
||||
def median(values: list[float]) -> float:
|
||||
if not values:
|
||||
raise ValueError
|
||||
sorted_values = sorted(values)
|
||||
n = len(sorted_values)
|
||||
mid = n // 2
|
||||
if n % 2 == 1:
|
||||
return sorted_values[mid]
|
||||
return (sorted_values[mid - 1] + sorted_values[mid]) / 2.0
|
||||
|
||||
|
||||
def variance(values: Sequence[float]) -> float:
|
||||
if not values:
|
||||
raise ValueError
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
import math
|
||||
import unittest
|
||||
|
||||
from typosaurus_sandbox.domain.calculator import add, average, clamp, clamp_to_byte, median, subtract, variance
|
||||
from typosaurus_sandbox.domain.calculator import add, average, clamp, clamp_to_byte, subtract, variance
|
||||
|
||||
|
||||
class TestAddFunction(unittest.TestCase):
|
||||
@@ -125,32 +125,6 @@ class TestClampFunction(unittest.TestCase):
|
||||
self.assertTrue(math.isnan(result))
|
||||
|
||||
|
||||
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)
|
||||
|
||||
|
||||
class TestVarianceFunction(unittest.TestCase):
|
||||
|
||||
def test_empty_list_raises_value_error(self) -> None:
|
||||
|
||||
Reference in New Issue
Block a user