From c974ef41d8f2d08158a1b183c10e92644dce3565 Mon Sep 17 00:00:00 2001 From: Nicholay Shestakov Date: Fri, 17 Oct 2025 22:42:11 +0300 Subject: [PATCH 1/5] Add heap sort algorithm --- .../heap_sort/heap_sort.py | 31 +++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 src/testing_pytest_base/heap_sort/heap_sort.py diff --git a/src/testing_pytest_base/heap_sort/heap_sort.py b/src/testing_pytest_base/heap_sort/heap_sort.py new file mode 100644 index 0000000..58140e0 --- /dev/null +++ b/src/testing_pytest_base/heap_sort/heap_sort.py @@ -0,0 +1,31 @@ +def _heapify(lst, index): + while index > 0: + if lst[index] > lst[(index - 1) // 2]: + temp = lst[index] + lst[index] = lst[(index - 1) // 2] + lst[(index - 1) // 2] = temp + else: + break + index = (index - 1) // 2 + + +def _list_to_heap(lst, unsorted_size): + for i in range(unsorted_size): + if lst[i] > lst[(i - 1) // 2]: + _heapify(lst, i) + + +def heap_sort(lst): + """Standart heap sorting algorithm. Takes list and sorts it.""" + size = len(lst) + for i in range(size): + _list_to_heap(lst, size - i) + temp = lst[0] + lst[0] = lst[size - i - 1] + lst[size - i - 1] = temp + + +if __name__ == "__main__": + lst = list(map(int, input("Input list: ").split())) + heap_sort(lst) + print(lst) From ebf5e0edfcee6f84ef6dd90ff265419098bfb863 Mon Sep 17 00:00:00 2001 From: Nicholay Shestakov Date: Fri, 17 Oct 2025 23:31:47 +0300 Subject: [PATCH 2/5] Add pytest.ini for configure pytest --- pytest.ini | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 pytest.ini diff --git a/pytest.ini b/pytest.ini new file mode 100644 index 0000000..fcccae1 --- /dev/null +++ b/pytest.ini @@ -0,0 +1,2 @@ +[pytest] +pythonpath = src From 64f9a0262adb0b9d3fe87b5a538eace9549e3e02 Mon Sep 17 00:00:00 2001 From: Nicholay Shestakov Date: Fri, 17 Oct 2025 23:32:11 +0300 Subject: [PATCH 3/5] Add test for heap sort --- tests/heap_sort_test.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 tests/heap_sort_test.py diff --git a/tests/heap_sort_test.py b/tests/heap_sort_test.py new file mode 100644 index 0000000..e4ba69f --- /dev/null +++ b/tests/heap_sort_test.py @@ -0,0 +1,21 @@ +from testing_pytest_base.heap_sort.heap_sort import heap_sort +import random + + +def test_common(): + lst = [3, 1, 2] + heap_sort(lst) + assert lst == [1, 2, 3] + + +def test_empty(): + lst = [] + heap_sort(lst) + assert lst == [] + + +def test_another_sort(): + lst = [random.randint(-1000000, 1000000) for _ in range(10000)] + sorted_with_another = sorted(lst) + heap_sort(lst) + assert lst == sorted_with_another From e56c80d4d82fdf3e89707b629aac5cd694904d6d Mon Sep 17 00:00:00 2001 From: Nicholay Shestakov Date: Fri, 17 Oct 2025 23:39:07 +0300 Subject: [PATCH 4/5] Add pytest action --- .github/workflows/pytest.yml | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 .github/workflows/pytest.yml diff --git a/.github/workflows/pytest.yml b/.github/workflows/pytest.yml new file mode 100644 index 0000000..27a3a64 --- /dev/null +++ b/.github/workflows/pytest.yml @@ -0,0 +1,30 @@ +name: Python tests + +on: + push: + branches: [main] + pull_request: + branches: [main] + +jobs: + test: + + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v3 + + - name: Set up Python + uses: actions/setup-python@v4 + with: + python-version: '3.10' # или нужная версия + + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install pytest + # pip install -r requirements.txt # если есть зависимости + + - name: Run tests + run: | + pytest -v From d30976c08640a7709a23af24d332c39f62cc5b24 Mon Sep 17 00:00:00 2001 From: Nicholay Shestakov Date: Thu, 23 Oct 2025 13:29:51 +0300 Subject: [PATCH 5/5] Add check for all branches in pytest.yml --- .github/workflows/pytest.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/pytest.yml b/.github/workflows/pytest.yml index 27a3a64..5e9923c 100644 --- a/.github/workflows/pytest.yml +++ b/.github/workflows/pytest.yml @@ -2,9 +2,9 @@ name: Python tests on: push: - branches: [main] + branches: ["*"] pull_request: - branches: [main] + branches: ["*"] jobs: test: