From 4ebac1a63ad3b123b74c31607bbc30a7a3d05d7d Mon Sep 17 00:00:00 2001 From: Nikolay Baboshin <231540704+shknoko@users.noreply.github.com> Date: Fri, 17 Oct 2025 22:45:14 +0300 Subject: [PATCH 01/12] Heap sort implementation --- 09.10/src/heap_sort.py | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 09.10/src/heap_sort.py diff --git a/09.10/src/heap_sort.py b/09.10/src/heap_sort.py new file mode 100644 index 0000000..74cb8ee --- /dev/null +++ b/09.10/src/heap_sort.py @@ -0,0 +1,23 @@ +def heapify(arr: list, n: int, i: int) -> None: + largest = i + left = 2 * i + 1 + right = 2 * i + 2 + + if left < n and arr[i] < arr[left]: + largest = left + + if right < n and arr[largest] < arr[right]: + largest = right + + if largest != i: + arr[i], arr[largest] = arr[largest], arr[i] + heapify(arr, n, largest) + + +def heap_sort(arr: list) -> None: + for i in range(len(arr) - 1, -1, -1): + heapify(arr, len(arr), i) + + for i in range(len(arr) - 1, 0, -1): + arr[i], arr[0] = arr[0], arr[i] + heapify(arr, i, 0) From 7816baa53b91a6b1b5e80b762e27338312c77e06 Mon Sep 17 00:00:00 2001 From: Nikolay Baboshin <231540704+shknoko@users.noreply.github.com> Date: Fri, 17 Oct 2025 23:37:44 +0300 Subject: [PATCH 02/12] Added fixture function --- 09.10/tests/conftest.py | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 09.10/tests/conftest.py diff --git a/09.10/tests/conftest.py b/09.10/tests/conftest.py new file mode 100644 index 0000000..2c96774 --- /dev/null +++ b/09.10/tests/conftest.py @@ -0,0 +1,10 @@ +import random + +import pytest + + +@pytest.fixture +def random_list(): + list_len = random.randint(100, 5000) + random_list = [random.randint(-10**11, 10**11) for _ in range(list_len)] + return random_list From e06e1adaa41e2e85f16967c79c7da376a270f9e9 Mon Sep 17 00:00:00 2001 From: Nikolay Baboshin <231540704+shknoko@users.noreply.github.com> Date: Fri, 17 Oct 2025 23:38:09 +0300 Subject: [PATCH 03/12] Added tests --- 09.10/tests/tests.py | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 09.10/tests/tests.py diff --git a/09.10/tests/tests.py b/09.10/tests/tests.py new file mode 100644 index 0000000..4240ea2 --- /dev/null +++ b/09.10/tests/tests.py @@ -0,0 +1,32 @@ +import sys +from pathlib import Path + +import pytest + +sys.path.append(f"{Path(__file__).parent.parent}") + +from conftest import random_list # noqa: F401 +from src.heap_sort import heap_sort + + +@pytest.mark.parametrize( + ["arr", "expected"], + [([1, 5, 3, 2, 4], [1, 2, 3, 4, 5]), + ([7, 6, 23423524], [6, 7, 23423524]), + ([[], []]), + ([5], [5]), + ([2, 2, 2, 2], [2, 2, 2, 2]), + ([0, 1, 0, 1, 0, 1, 0, 1], [0, 0, 0, 0, 1, 1, 1, 1]), + ([12, -100, 47, -123, -5, 1, 0, -3], [-123, -100, -5, -3, 0, 1, 12, 47])] +) +def test_sort_parametrized(arr, expected): + heap_sort(arr) + assert arr == expected + + +@pytest.mark.repeat(100) +def test_sort_random(random_list): # noqa: F811 + expected = sorted(random_list) + heap_sort(random_list) + + assert random_list == expected From e783597e018861aaea758e08804d49bebee4498d Mon Sep 17 00:00:00 2001 From: Nikolay Baboshin <231540704+shknoko@users.noreply.github.com> Date: Sat, 18 Oct 2025 00:09:14 +0300 Subject: [PATCH 04/12] Separated tests --- 09.10/tests/{tests.py => test_parametrized.py} | 8 -------- 09.10/tests/test_random.py | 17 +++++++++++++++++ 2 files changed, 17 insertions(+), 8 deletions(-) rename 09.10/tests/{tests.py => test_parametrized.py} (77%) create mode 100644 09.10/tests/test_random.py diff --git a/09.10/tests/tests.py b/09.10/tests/test_parametrized.py similarity index 77% rename from 09.10/tests/tests.py rename to 09.10/tests/test_parametrized.py index 4240ea2..d434052 100644 --- a/09.10/tests/tests.py +++ b/09.10/tests/test_parametrized.py @@ -22,11 +22,3 @@ def test_sort_parametrized(arr, expected): heap_sort(arr) assert arr == expected - - -@pytest.mark.repeat(100) -def test_sort_random(random_list): # noqa: F811 - expected = sorted(random_list) - heap_sort(random_list) - - assert random_list == expected diff --git a/09.10/tests/test_random.py b/09.10/tests/test_random.py new file mode 100644 index 0000000..3a2d1f6 --- /dev/null +++ b/09.10/tests/test_random.py @@ -0,0 +1,17 @@ +import sys +from pathlib import Path + +import pytest + +sys.path.append(f"{Path(__file__).parent.parent}") + +from conftest import random_list # noqa: F401 +from src.heap_sort import heap_sort + + +@pytest.mark.repeat(100) +def test_sort_random(random_list): # noqa: F811 + expected = sorted(random_list) + heap_sort(random_list) + + assert random_list == expected From a3655895fe8f7a82e01684d2b370023e3a8fec84 Mon Sep 17 00:00:00 2001 From: Nikolay Baboshin <231540704+shknoko@users.noreply.github.com> Date: Sat, 18 Oct 2025 00:17:47 +0300 Subject: [PATCH 05/12] Added test checker in CI --- .github/workflows/pytest.yml | 22 ++++++++++++++++++++++ 1 file changed, 22 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..aa74d4c --- /dev/null +++ b/.github/workflows/pytest.yml @@ -0,0 +1,22 @@ +name: Run tests with pytest +on: + pull_request: + +jobs: + build: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - name: Install Python + uses: actions/setup-python@v5 + with: + python-version: "3.13" + + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install pytest + pip install pytest-repeat + + - name: Run tests + run: pytest \ No newline at end of file From de075289a806a47d6fd2e346b2808d06ddd85e75 Mon Sep 17 00:00:00 2001 From: Nikolay Baboshin <231540704+shknoko@users.noreply.github.com> Date: Sat, 18 Oct 2025 00:23:16 +0300 Subject: [PATCH 06/12] Fixed codestyle --- 09.10/tests/conftest.py | 2 +- 09.10/tests/test_parametrized.py | 16 +++++++++------- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/09.10/tests/conftest.py b/09.10/tests/conftest.py index 2c96774..afa93c4 100644 --- a/09.10/tests/conftest.py +++ b/09.10/tests/conftest.py @@ -6,5 +6,5 @@ @pytest.fixture def random_list(): list_len = random.randint(100, 5000) - random_list = [random.randint(-10**11, 10**11) for _ in range(list_len)] + random_list = [random.randint(-(10**11), 10**11) for _ in range(list_len)] return random_list diff --git a/09.10/tests/test_parametrized.py b/09.10/tests/test_parametrized.py index d434052..3bb66cc 100644 --- a/09.10/tests/test_parametrized.py +++ b/09.10/tests/test_parametrized.py @@ -11,13 +11,15 @@ @pytest.mark.parametrize( ["arr", "expected"], - [([1, 5, 3, 2, 4], [1, 2, 3, 4, 5]), - ([7, 6, 23423524], [6, 7, 23423524]), - ([[], []]), - ([5], [5]), - ([2, 2, 2, 2], [2, 2, 2, 2]), - ([0, 1, 0, 1, 0, 1, 0, 1], [0, 0, 0, 0, 1, 1, 1, 1]), - ([12, -100, 47, -123, -5, 1, 0, -3], [-123, -100, -5, -3, 0, 1, 12, 47])] + [ + ([1, 5, 3, 2, 4], [1, 2, 3, 4, 5]), + ([7, 6, 23423524], [6, 7, 23423524]), + ([[], []]), + ([5], [5]), + ([2, 2, 2, 2], [2, 2, 2, 2]), + ([0, 1, 0, 1, 0, 1, 0, 1], [0, 0, 0, 0, 1, 1, 1, 1]), + ([12, -100, 47, -123, -5, 1, 0, -3], [-123, -100, -5, -3, 0, 1, 12, 47]), + ], ) def test_sort_parametrized(arr, expected): heap_sort(arr) From a493a10102c7a89ae24ad721d526f6ab1f6d2d43 Mon Sep 17 00:00:00 2001 From: Nikolay Baboshin <231540704+shknoko@users.noreply.github.com> Date: Sat, 18 Oct 2025 00:24:36 +0300 Subject: [PATCH 07/12] Updated config for pytest in CI --- .github/workflows/pytest.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/pytest.yml b/.github/workflows/pytest.yml index aa74d4c..059a0a7 100644 --- a/.github/workflows/pytest.yml +++ b/.github/workflows/pytest.yml @@ -1,5 +1,6 @@ name: Run tests with pytest on: + push: pull_request: jobs: From e336b7fe48cb326881f56dc6fc53915b93e65aba Mon Sep 17 00:00:00 2001 From: Nikolay Baboshin <231540704+shknoko@users.noreply.github.com> Date: Tue, 21 Oct 2025 02:17:21 +0300 Subject: [PATCH 08/12] Remove editing pythonpath in tests --- 09.10/tests/test_parametrized.py | 6 ------ 09.10/tests/test_random.py | 6 ------ 2 files changed, 12 deletions(-) diff --git a/09.10/tests/test_parametrized.py b/09.10/tests/test_parametrized.py index 3bb66cc..3bcb15e 100644 --- a/09.10/tests/test_parametrized.py +++ b/09.10/tests/test_parametrized.py @@ -1,10 +1,4 @@ -import sys -from pathlib import Path - import pytest - -sys.path.append(f"{Path(__file__).parent.parent}") - from conftest import random_list # noqa: F401 from src.heap_sort import heap_sort diff --git a/09.10/tests/test_random.py b/09.10/tests/test_random.py index 3a2d1f6..24651ed 100644 --- a/09.10/tests/test_random.py +++ b/09.10/tests/test_random.py @@ -1,10 +1,4 @@ -import sys -from pathlib import Path - import pytest - -sys.path.append(f"{Path(__file__).parent.parent}") - from conftest import random_list # noqa: F401 from src.heap_sort import heap_sort From c1627842bcc0862a2c8d4c981baa0ffcdc6c0ba2 Mon Sep 17 00:00:00 2001 From: Nikolay Baboshin <231540704+shknoko@users.noreply.github.com> Date: Sun, 9 Nov 2025 16:05:27 +0300 Subject: [PATCH 09/12] Removed unused imports --- 09.10/tests/test_parametrized.py | 1 - 09.10/tests/test_random.py | 1 - 2 files changed, 2 deletions(-) diff --git a/09.10/tests/test_parametrized.py b/09.10/tests/test_parametrized.py index 3bcb15e..6581f96 100644 --- a/09.10/tests/test_parametrized.py +++ b/09.10/tests/test_parametrized.py @@ -1,5 +1,4 @@ import pytest -from conftest import random_list # noqa: F401 from src.heap_sort import heap_sort diff --git a/09.10/tests/test_random.py b/09.10/tests/test_random.py index 24651ed..a41f3ce 100644 --- a/09.10/tests/test_random.py +++ b/09.10/tests/test_random.py @@ -1,5 +1,4 @@ import pytest -from conftest import random_list # noqa: F401 from src.heap_sort import heap_sort From f1eab96a101a2ac2bbd3b5b07d2602797ea6ce2a Mon Sep 17 00:00:00 2001 From: Nikolay Baboshin <231540704+shknoko@users.noreply.github.com> Date: Sun, 9 Nov 2025 16:40:11 +0300 Subject: [PATCH 10/12] Made a package from the directory --- 09.10/__init__.py | 0 09.10/src/__init__.py | 0 09.10/tests/__init__.py | 0 3 files changed, 0 insertions(+), 0 deletions(-) create mode 100644 09.10/__init__.py create mode 100644 09.10/src/__init__.py create mode 100644 09.10/tests/__init__.py diff --git a/09.10/__init__.py b/09.10/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/09.10/src/__init__.py b/09.10/src/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/09.10/tests/__init__.py b/09.10/tests/__init__.py new file mode 100644 index 0000000..e69de29 From e14179feccb3ea21539a19760c96b36735e29b24 Mon Sep 17 00:00:00 2001 From: Nikolay Baboshin <231540704+shknoko@users.noreply.github.com> Date: Sun, 9 Nov 2025 16:45:50 +0300 Subject: [PATCH 11/12] Renamed the directory --- {09.10 => l06_testing}/__init__.py | 0 {09.10 => l06_testing}/src/__init__.py | 0 {09.10 => l06_testing}/src/heap_sort.py | 0 {09.10 => l06_testing}/tests/__init__.py | 0 {09.10 => l06_testing}/tests/conftest.py | 0 {09.10 => l06_testing}/tests/test_parametrized.py | 0 {09.10 => l06_testing}/tests/test_random.py | 0 7 files changed, 0 insertions(+), 0 deletions(-) rename {09.10 => l06_testing}/__init__.py (100%) rename {09.10 => l06_testing}/src/__init__.py (100%) rename {09.10 => l06_testing}/src/heap_sort.py (100%) rename {09.10 => l06_testing}/tests/__init__.py (100%) rename {09.10 => l06_testing}/tests/conftest.py (100%) rename {09.10 => l06_testing}/tests/test_parametrized.py (100%) rename {09.10 => l06_testing}/tests/test_random.py (100%) diff --git a/09.10/__init__.py b/l06_testing/__init__.py similarity index 100% rename from 09.10/__init__.py rename to l06_testing/__init__.py diff --git a/09.10/src/__init__.py b/l06_testing/src/__init__.py similarity index 100% rename from 09.10/src/__init__.py rename to l06_testing/src/__init__.py diff --git a/09.10/src/heap_sort.py b/l06_testing/src/heap_sort.py similarity index 100% rename from 09.10/src/heap_sort.py rename to l06_testing/src/heap_sort.py diff --git a/09.10/tests/__init__.py b/l06_testing/tests/__init__.py similarity index 100% rename from 09.10/tests/__init__.py rename to l06_testing/tests/__init__.py diff --git a/09.10/tests/conftest.py b/l06_testing/tests/conftest.py similarity index 100% rename from 09.10/tests/conftest.py rename to l06_testing/tests/conftest.py diff --git a/09.10/tests/test_parametrized.py b/l06_testing/tests/test_parametrized.py similarity index 100% rename from 09.10/tests/test_parametrized.py rename to l06_testing/tests/test_parametrized.py diff --git a/09.10/tests/test_random.py b/l06_testing/tests/test_random.py similarity index 100% rename from 09.10/tests/test_random.py rename to l06_testing/tests/test_random.py From e6cb6cda3d389d56e329639987998fd1c261ef34 Mon Sep 17 00:00:00 2001 From: Nikolay Baboshin <231540704+shknoko@users.noreply.github.com> Date: Sun, 9 Nov 2025 17:01:45 +0300 Subject: [PATCH 12/12] Fixed imports --- l06_testing/tests/test_parametrized.py | 3 ++- l06_testing/tests/test_random.py | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/l06_testing/tests/test_parametrized.py b/l06_testing/tests/test_parametrized.py index 6581f96..b2c8378 100644 --- a/l06_testing/tests/test_parametrized.py +++ b/l06_testing/tests/test_parametrized.py @@ -1,5 +1,6 @@ import pytest -from src.heap_sort import heap_sort + +from l06_testing.src.heap_sort import heap_sort @pytest.mark.parametrize( diff --git a/l06_testing/tests/test_random.py b/l06_testing/tests/test_random.py index a41f3ce..85cb770 100644 --- a/l06_testing/tests/test_random.py +++ b/l06_testing/tests/test_random.py @@ -1,5 +1,6 @@ import pytest -from src.heap_sort import heap_sort + +from l06_testing.src.heap_sort import heap_sort @pytest.mark.repeat(100)