Compare commits
6
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a4ee545314 | ||
|
|
888abecd7f | ||
|
|
4940dfeffd | ||
|
|
c5999afcad | ||
|
|
3ad3dc517f | ||
|
|
0b77019f6c |
@@ -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`
|
||||
|
||||
|
||||
|
||||
+6
-2
@@ -25,6 +25,12 @@ def clamp_to_byte(value: int) -> int:
|
||||
return max(0, min(255, value))
|
||||
|
||||
|
||||
def average(values: list[int | float]) -> float:
|
||||
if not values:
|
||||
raise ValueError
|
||||
return sum(values) / len(values)
|
||||
|
||||
|
||||
def variance(values: Sequence[float]) -> float:
|
||||
if not values:
|
||||
raise ValueError
|
||||
@@ -37,5 +43,3 @@ def percentage(value: Union[int, float], total: Union[int, float]) -> float:
|
||||
raise ValueError
|
||||
return (value / total) * 100
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
# retoor <retoor@molodetz.nl>
|
||||
|
||||
from typosaurus_sandbox.domain.calculator.operations import add, clamp, clamp_to_byte, 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", "subtract", "clamp", "clamp_to_byte", "variance"]
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
# retoor <retoor@molodetz.nl>
|
||||
|
||||
from typing import Sequence
|
||||
from typing import Sequence, Union
|
||||
|
||||
|
||||
def add(left: int, right: int) -> int:
|
||||
@@ -25,9 +25,21 @@ def clamp_to_byte(value: int) -> int:
|
||||
return max(0, min(255, value))
|
||||
|
||||
|
||||
def average(values: list[int | float]) -> float:
|
||||
if not values:
|
||||
raise ValueError
|
||||
return sum(values) / len(values)
|
||||
|
||||
|
||||
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)
|
||||
|
||||
|
||||
def percentage(value: Union[int, float], total: Union[int, float]) -> float:
|
||||
if total == 0:
|
||||
raise ValueError
|
||||
return (value / total) * 100
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
import math
|
||||
import unittest
|
||||
|
||||
from typosaurus_sandbox.domain.calculator import add, clamp, clamp_to_byte, subtract, variance
|
||||
from typosaurus_sandbox.domain.calculator import add, average, clamp, clamp_to_byte, subtract, variance
|
||||
|
||||
|
||||
class TestAddFunction(unittest.TestCase):
|
||||
@@ -18,6 +18,28 @@ class TestAddFunction(unittest.TestCase):
|
||||
self.assertEqual(add(-3, 5), 2)
|
||||
|
||||
|
||||
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)
|
||||
|
||||
|
||||
class TestSubtractFunction(unittest.TestCase):
|
||||
|
||||
def test_subtract_positive(self) -> None:
|
||||
|
||||
Reference in New Issue
Block a user