Skip to content

Commit

Permalink
ready for review, removed unnecessary comments
Browse files Browse the repository at this point in the history
  • Loading branch information
oleksandr-maksymikhin committed Jan 3, 2025
1 parent 5818073 commit fb2f5f6
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 19 deletions.
8 changes: 4 additions & 4 deletions solutions/bubble_sort.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@ def bubble_sort(input_collection: list[any]) -> list[any]:
AssertionError: if collection contains elements of different data types (non-homogeneous).
Examples:
>>> bubble_sort(1)
>>> bubble_sort([1])
[1]
>>> bubble_sort([1, 3, 2]])
>>> bubble_sort([1, 3, 2])
[1, 2, 3]
>>> bubble_sort([3, 2, 100500, 1]])
>>> bubble_sort([3, 2, 100500, 1])
[1, 2, 3, 100500]
"""

Expand All @@ -41,7 +41,7 @@ def bubble_sort(input_collection: list[any]) -> list[any]:
# defensive assertion to check that collection is homogeneous
assert all(
isinstance(item, type(input_collection[0])) for item in input_collection
), "Collection is not homogeneous"
), "Input collection is not homogeneous"

# copy collection to avoid side effect
collection = input_collection.copy()
Expand Down
17 changes: 2 additions & 15 deletions solutions/tests/test_bubble_sort.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
Test categories:
- Standard cases: lists of type int with different lengths
- Edge cases: empty lists, single element
- Different data type: char, string, bool
- Different data types: char, string, bool
- Defensive tests:
- side effects protection
- input is not a collection
Expand All @@ -24,18 +24,6 @@
class TestBubbleSort(unittest.TestCase):
"""Test the bubble_sort function."""

# Uncomment for predictive stepping
# test_1 = bubble_sort([])
# test_2 = bubble_sort([1])
# test_3 = bubble_sort([2, 1])
# test_4 = bubble_sort([3, 2, 1])
# test_5 = bubble_sort([2, 3, 100500, 1])
# test_6 = bubble_sort(["b", "a", "c"])
# test_7 = bubble_sort(["cabbage", "banana", "apple"])
# test_8 = bubble_sort([True, False, True, False])
# test_10 = bubble_sort("apple")
# test_11 = bubble_sort([3, "two", 1])

def test_1_empty_list(self):
"""It should return [] for input []"""
actual = bubble_sort([])
Expand Down Expand Up @@ -87,8 +75,7 @@ def test_8_bool_elements_list(self):
def test_9_side_effect_protection(self):
"""It should return [3, 2, 1] of initial input"""
input_list = [3, 2, 1]
copy_for_sorting = input_list.copy()
bubble_sort(copy_for_sorting)
bubble_sort(input_list)
self.assertEqual(input_list, [3, 2, 1])

def test_10_non_collection_input(self):
Expand Down

0 comments on commit fb2f5f6

Please sign in to comment.