diff --git a/.github/workflows/python-app.yml b/.github/workflows/python-app.yml new file mode 100644 index 0000000..55f9433 --- /dev/null +++ b/.github/workflows/python-app.yml @@ -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 . diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..8b9541d Binary files /dev/null and b/requirements.txt differ diff --git a/test_utils.py b/test_utils.py new file mode 100644 index 0000000..5a264b2 --- /dev/null +++ b/test_utils.py @@ -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 diff --git a/utils.py b/utils.py new file mode 100644 index 0000000..4a1de3e --- /dev/null +++ b/utils.py @@ -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