Skip to content

Commit

Permalink
updated the test case code using pytest.mark.parametrize()
Browse files Browse the repository at this point in the history
  • Loading branch information
Shree7676 committed Aug 29, 2024
1 parent 4c7fea5 commit e9dc4f4
Showing 1 changed file with 15 additions and 35 deletions.
50 changes: 15 additions & 35 deletions tests/test_sorting.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,41 +20,21 @@ def test_mergesort_empty():
pass


def test_bubble_sort():
# Test even-sized list:
l = [3, 2, 1, 5, 4, 6]
res = lws.bubble_sort(l)
assert res == [1, 2, 3, 4, 5, 6]

# Test odd-sized list:
l = [5, 4, 3, 2, 1]
res = lws.bubble_sort(l)
assert res == [1, 2, 3, 4, 5]

# Test already sorted list:
l = [1, 2, 3, 4, 5]
res = lws.bubble_sort(l)
assert res == [1, 2, 3, 4, 5]

# Test list with duplicate elements:
l = [4, 2, 3, 2, 1, 3]
res = lws.bubble_sort(l)
assert res == [1, 2, 2, 3, 3, 4]

# Test list with all identical elements:
l = [7, 7, 7, 7]
res = lws.bubble_sort(l)
assert res == [7, 7, 7, 7]

# Test empty list:
l = []
res = lws.bubble_sort(l)
assert res == []

# Test single-element list:
l = [1]
res = lws.bubble_sort(l)
assert res == [1]
@pytest.mark.parametrize(
"input_list, expected",
[
([3, 2, 1, 5, 4, 6], [1, 2, 3, 4, 5, 6]), # Test even-sized list
([5, 4, 3, 2, 1], [1, 2, 3, 4, 5]), # Test odd-sized list
([1, 2, 3, 4, 5], [1, 2, 3, 4, 5]), # Test already sorted list
([4, 2, 3, 2, 1, 3], [1, 2, 2, 3, 3, 4]), # Test list with duplicate elements
([7, 7, 7, 7], [7, 7, 7, 7]), # Test list with all identical elements
([], []), # Test empty list
([1], [1]), # Test single-element list
],
)
def test_bubble_sort(input_list, expected):
res = lws.bubble_sort(input_list)
assert res == expected


def test_selection_sort():
Expand Down

0 comments on commit e9dc4f4

Please sign in to comment.