Skip to content

Домашнее задание 6.1. Heap sort. Разгуляева А.И.#7

Open
ada1ra wants to merge 4 commits intomainfrom
hw_6_1_sort_with_test
Open

Домашнее задание 6.1. Heap sort. Разгуляева А.И.#7
ada1ra wants to merge 4 commits intomainfrom
hw_6_1_sort_with_test

Conversation

@ada1ra
Copy link
Owner

@ada1ra ada1ra commented Oct 28, 2025

No description provided.

@ada1ra ada1ra requested a review from chernishev October 28, 2025 23:38

return arr

#
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Чтобы не комментировать такие вещи, оборачивайте то, что должно запускаться только при запуске непосредственно самого файла, в if __name__ == "__main__".

Comment on lines +100 to +116
def test_heap_sort_builtin():
"""Сравнение с встроенной сортировкой"""
n = [1, 2, 10, 1, 100]
assert heap_sort(n) == sorted(n)


def test_compare_with_bubble_sort():
"""Сравнение с пузырьковой сортировкой"""
n = [1, 2, 10, 1, 100]

assert heap_sort(n) == bubble_sort(n)


def test_compare_with_selection_sort():
"""Сравнение с сортировкой выбором"""
n = [1, 2, 10, 1, 100]
assert heap_sort(n) == selection_sort(n)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Нужно использовать .copy() так как вы передаете один и тот же массив.

n = len(arr)

# строим max-heap
for i in range(n, -1, -1):
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Нет смысла начинать с n, эффективнее начинать с последнего родительского узла n // 2 - 1.

Comment on lines +97 to +116
"""Сравнение с другими сортировками"""


def test_heap_sort_builtin():
"""Сравнение с встроенной сортировкой"""
n = [1, 2, 10, 1, 100]
assert heap_sort(n) == sorted(n)


def test_compare_with_bubble_sort():
"""Сравнение с пузырьковой сортировкой"""
n = [1, 2, 10, 1, 100]

assert heap_sort(n) == bubble_sort(n)


def test_compare_with_selection_sort():
"""Сравнение с сортировкой выбором"""
n = [1, 2, 10, 1, 100]
assert heap_sort(n) == selection_sort(n)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Для property based тестов нужно тоже генерировать массивы и сравнивать на них сортировки.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants