Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 48 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# Git
.git
.gitignore

# Python
__pycache__/
*.py[cod]
*$py.class
*.so
.Python
env/
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
*.egg-info/
.installed.cfg
*.egg
.pytest_cache/
.coverage
htmlcov/

# Logs and Backups
logs/
backups/

# Node
node_modules/
package-lock.json

# Environment
.env
.venv
venv/
ENV/

# IDEs
.vscode/
.idea/
*.swp
*.swo
26 changes: 26 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
FROM python:3.12-slim

# Prevent Python from writing .pyc files and enable unbuffered output
ENV PYTHONDONTWRITEBYTECODE=1 \
PYTHONUNBUFFERED=1

# Set working directory
WORKDIR /app

# Install system dependencies (git is required for the agent to commit/push)
RUN apt-get update && apt-get install -y --no-install-recommends \
git \
&& rm -rf /var/lib/apt/lists/*

# Install python dependencies
COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt

# Copy the rest of the application
COPY . .

# Ensure the entrypoint is executable
RUN chmod +x main.py

# Entry command
ENTRYPOINT ["python", "main.py"]
38 changes: 38 additions & 0 deletions tests/test_utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import pytest
from utils import calculate_average, find_max, normalize, parse_int_list

def test_calculate_average():
assert calculate_average([1, 2, 3, 4, 5]) == 3.0
assert calculate_average([10, 20]) == 15.0
with pytest.raises(ValueError, match="Cannot calculate average of an empty list"):
calculate_average([])

def test_find_max():
assert find_max([1, 5, 3, 9, 2]) == 9
assert find_max([-10, -5, -20]) == -5
with pytest.raises(ValueError, match="Cannot find max of an empty list"):
find_max([])

def test_normalize():
assert normalize([0, 5, 10]) == [0.0, 0.5, 1.0]
assert normalize([10, 20, 30, 40, 50]) == [0.0, 0.25, 0.5, 0.75, 1.0]

with pytest.raises(ValueError, match="Cannot normalize an empty list"):
normalize([])

with pytest.raises(ValueError, match="Cannot normalize a constant list"):
normalize([5, 5, 5])

def test_parse_int_list():
assert parse_int_list("1,2,3,4") == [1, 2, 3, 4]
assert parse_int_list(" 10 , 20, 30 ") == [10, 20, 30]
assert parse_int_list("-5,0,5") == [-5, 0, 5]

with pytest.raises(ValueError, match="Input string is empty"):
parse_int_list("")

with pytest.raises(ValueError, match="Input string is empty"):
parse_int_list(" ")

with pytest.raises(ValueError, match="invalid integer in input"):
parse_int_list("1,2,abc,4")