From 1e87c7b151f8b9ef9e8205d35a711aa471463c1f Mon Sep 17 00:00:00 2001 From: Piotr <272503@student.pwr.edu.pl> Date: Wed, 14 May 2025 15:55:07 +0200 Subject: [PATCH 1/4] testy --- .github/workflows/python-app.yml | 38 ++++++++++++++++++++++++++++ test_utils.py | 43 ++++++++++++++++++++++++++++++++ utils.py | 13 ++++++++++ 3 files changed, 94 insertions(+) create mode 100644 .github/workflows/python-app.yml create mode 100644 test_utils.py create mode 100644 utils.py 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/test_utils.py b/test_utils.py new file mode 100644 index 0000000..bd58f39 --- /dev/null +++ b/test_utils.py @@ -0,0 +1,43 @@ +# 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..c9dbc43 --- /dev/null +++ b/utils.py @@ -0,0 +1,13 @@ +# Exemplary calculator functions + +def add (a: int , b: int) -> int : + return a + b + +def subtract (a: int , b: int) -> int : + return a - b + +def multiply (a: int , b: int) -> int : + return a * b + +def divide ( a: int , b : int ) -> float : + return a / b \ No newline at end of file From a193ad2faa61d86426974d57ae7e1519ddd06eab Mon Sep 17 00:00:00 2001 From: Piotr <272503@student.pwr.edu.pl> Date: Wed, 14 May 2025 16:09:18 +0200 Subject: [PATCH 2/4] poprawki --- test_utils.py | 35 ++++++++++++----------------------- utils.py | 18 ++++++++++++------ 2 files changed, 24 insertions(+), 29 deletions(-) diff --git a/test_utils.py b/test_utils.py index bd58f39..5a264b2 100644 --- a/test_utils.py +++ b/test_utils.py @@ -3,41 +3,30 @@ import pytest import utils -@pytest.mark.parametrize("a, b, expected", [ - (1, 2, 3), - (2, 3, 5), - (3, 4, 7), - (4, 5, 9) -]) + +@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) -]) + +@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) -]) + +@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) -]) + +@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 index c9dbc43..a751741 100644 --- a/utils.py +++ b/utils.py @@ -1,13 +1,19 @@ -# Exemplary calculator functions +"""Exemplary calculator functions module. +Provides basic arithmetic operations: add, subtract, multiply, divide. +""" -def add (a: int , b: int) -> int : +def add(a: int, b: int) -> int: + """Add two integers and return the result.""" return a + b -def subtract (a: int , b: int) -> int : +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 : +def multiply(a: int, b: int) -> int: + """Multiply two integers and return the result.""" return a * b -def divide ( a: int , b : int ) -> float : - return a / b \ No newline at end of file +def divide(a: int, b: int) -> float: + """Divide the first integer by the second and return the result as a float.""" + return a / b From 5eaf41e44061ca3b348abadfd863d9b01ee31dad Mon Sep 17 00:00:00 2001 From: Piotr <272503@student.pwr.edu.pl> Date: Wed, 14 May 2025 16:11:54 +0200 Subject: [PATCH 3/4] poprawki --- requirements.txt | Bin 0 -> 532 bytes 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 requirements.txt diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000000000000000000000000000000000000..8b9541d10e524863c8e66ae0f2910fbd3f49af98 GIT binary patch literal 532 zcmYk3+fIXE5QOL2#8)u|?cv5}F_a!8?JqNY3AEH2yr42#gElj|e;i1edJ6Xle+5^sT2EdNT2<@6K{SO>D~E*%bASc qjgu_BMsVlIlRqxDow#F6do48{g=zw>EeSx2GU!;hRGCJ;ni%fz5 literal 0 HcmV?d00001 From ae6a7094f952d199ec2389436ca6249cb01f78d3 Mon Sep 17 00:00:00 2001 From: Piotr <272503@student.pwr.edu.pl> Date: Wed, 14 May 2025 16:15:09 +0200 Subject: [PATCH 4/4] poprawki --- utils.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/utils.py b/utils.py index a751741..4a1de3e 100644 --- a/utils.py +++ b/utils.py @@ -2,18 +2,22 @@ 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