Skip to content
Merged
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
38 changes: 38 additions & 0 deletions .github/workflows/python-app.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
name: Python application

on:
push:
pull_request:

jobs:
build:
runs-on: ubuntu-latest

strategy:
matrix:
python-version: ["3.11", "3.12"]

steps:
- uses: actions/checkout@v3

- name: Set up Python
uses: actions/setup-python@v3
with:
python-version: ${{ matrix.python-version }}

- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt

- name: Test with Pytest
run: |
pytest

- name: Lint with Pylint
run: |
pylint ./utils.py

- name: Format with Black
run: |
black --check .
Binary file added requirements.txt
Binary file not shown.
32 changes: 32 additions & 0 deletions test_utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Exemplary calculator tests

import pytest
import utils


@pytest.mark.parametrize("a, b, expected", [(1, 2, 3), (2, 3, 5), (3, 4, 7), (4, 5, 9)])
def test_add(a, b, expected):
result = utils.add(a, b)
assert result == expected


@pytest.mark.parametrize(
"a, b, expected", [(1, 2, -1), (2, 3, -1), (3, 4, -1), (4, 5, -1)]
)
def test_subtract(a, b, expected):
result = utils.subtract(a, b)
assert result == expected


@pytest.mark.parametrize(
"a, b, expected", [(1, 2, 2), (2, 3, 6), (3, 4, 12), (4, 5, 20)]
)
def test_multiply(a, b, expected):
result = utils.multiply(a, b)
assert result == expected


@pytest.mark.parametrize("a, b, expected", [(1, 2, 0.5), (3, 4, 0.75), (4, 5, 0.8)])
def test_divide(a, b, expected):
result = utils.divide(a, b)
assert result == expected
23 changes: 23 additions & 0 deletions utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
"""Exemplary calculator functions module.
Provides basic arithmetic operations: add, subtract, multiply, divide.
"""


def add(a: int, b: int) -> int:
"""Add two integers and return the result."""
return a + b


def subtract(a: int, b: int) -> int:
"""Subtract the second integer from the first and return the result."""
return a - b


def multiply(a: int, b: int) -> int:
"""Multiply two integers and return the result."""
return a * b


def divide(a: int, b: int) -> float:
"""Divide the first integer by the second and return the result as a float."""
return a / b