Skip to content

Update bubble_sort.rs #894

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

Conversation

dabevlohn
Copy link

Sorting function

The file implements the bubble_sort function for sorting using the bubble sort algorithm.

The function takes a modifiable reference to a slice of elements and sorts it in ascending order.

If the array is empty, the function returns control immediately.

Inside the loop, the array is traversed, neighboring elements are compared, and if the current one is larger than the next, they are swapped.

If there were no permutations during the pass, the array is considered sorted and the loop is terminated.

After each complete pass, the range for the next iteration is decreased by 1 because the last element is already in its place.

Tests

The tests module implements tests for various cases:

  • Array sorted descending (descending)
  • Already sorted array (ascending)
  • Empty array (empty)
  • Long array of random numbers (long) - takes much time(!)
  • Array with negative numbers (negative)
  • Array with zero and negative numbers (withnull)
  • Array with duplicates (duplicate)

For each test it is checked that the result is really sorted and contains the same elements as the initial array (using the auxiliary functions is_sorted and have_same_elements).

some tests added
@dabevlohn dabevlohn requested review from imp2002 and vil02 as code owners June 26, 2025 09:03
@codecov-commenter
Copy link

codecov-commenter commented Jun 26, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 95.52%. Comparing base (ff55eda) to head (5500fd2).

Additional details and impacted files
@@           Coverage Diff           @@
##           master     #894   +/-   ##
=======================================
  Coverage   95.52%   95.52%           
=======================================
  Files         319      319           
  Lines       23014    23039   +25     
=======================================
+ Hits        21984    22009   +25     
  Misses       1030     1030           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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