From fb03704345792cf8e790388500375f23eaeabb1b Mon Sep 17 00:00:00 2001 From: "gru-agent[bot]" <185149714+gru-agent[bot]@users.noreply.github.com> Date: Tue, 18 Feb 2025 02:17:51 +0000 Subject: [PATCH] Add unit tests for bubble sort function in test_sort.py --- src/test_sort.py | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 src/test_sort.py diff --git a/src/test_sort.py b/src/test_sort.py new file mode 100644 index 0000000..2e140b5 --- /dev/null +++ b/src/test_sort.py @@ -0,0 +1,35 @@ +import pytest +from src.sort import bubble_sort + +def test_bubble_sort_empty_list(): + assert bubble_sort([]) == [] + +def test_bubble_sort_single_element(): + assert bubble_sort([1]) == [1] + +def test_bubble_sort_sorted_list(): + assert bubble_sort([1, 2, 3, 4, 5]) == [1, 2, 3, 4, 5] + +def test_bubble_sort_reverse_sorted(): + assert bubble_sort([5, 4, 3, 2, 1]) == [1, 2, 3, 4, 5] + +def test_bubble_sort_random_list(): + assert bubble_sort([3, 1, 4, 1, 5, 9, 2, 6, 5, 3, 5]) == [1, 1, 2, 3, 3, 4, 5, 5, 5, 6, 9] + +def test_bubble_sort_duplicate_elements(): + assert bubble_sort([3, 3, 3, 1, 1, 2, 2]) == [1, 1, 2, 2, 3, 3, 3] + +def test_bubble_sort_negative_numbers(): + assert bubble_sort([-5, -10, 0, -3, 8, -1]) == [-10, -5, -3, -1, 0, 8] + +def test_bubble_sort_floating_numbers(): + assert bubble_sort([3.14, 1.41, 2.71, 0.58]) == [0.58, 1.41, 2.71, 3.14] + +def test_bubble_sort_mixed_numbers(): + assert bubble_sort([1, -2, 3.14, -4.5, 0, 2.5]) == [-4.5, -2, 0, 1, 2.5, 3.14] + +def test_bubble_sort_large_numbers(): + assert bubble_sort([1000000, 999999, 1000001]) == [999999, 1000000, 1000001] + +def test_bubble_sort_small_numbers(): + assert bubble_sort([0.0001, 0.0002, 0.0003]) == [0.0001, 0.0002, 0.0003]