From 96f52b00d59f7e7ff19dd4a0d66b1c74ad20130d Mon Sep 17 00:00:00 2001 From: D V <144282650+dabevlohn@users.noreply.github.com> Date: Thu, 26 Jun 2025 11:58:16 +0300 Subject: [PATCH 1/2] Update bubble_sort.rs some tests added --- src/sorting/bubble_sort.rs | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/src/sorting/bubble_sort.rs b/src/sorting/bubble_sort.rs index 0df7cec07a1..303c3c8843d 100644 --- a/src/sorting/bubble_sort.rs +++ b/src/sorting/bubble_sort.rs @@ -1,3 +1,5 @@ +/// This function works only with integers +/// For ordering float values use https://crates.io/crates/float-ord pub fn bubble_sort(arr: &mut [T]) { if arr.is_empty() { return; @@ -21,6 +23,8 @@ mod tests { use super::*; use crate::sorting::have_same_elements; use crate::sorting::is_sorted; + use rand::rng; + use rand::seq::SliceRandom; #[test] fn descending() { @@ -46,4 +50,34 @@ mod tests { bubble_sort(&mut ve3); assert!(is_sorted(&ve3) && have_same_elements(&ve3, &cloned)); } + #[test] + fn duplicate() { + let mut ve3: Vec = vec![2, 3, 3, 5, 7, 1, 1]; + let cloned = ve3.clone(); + bubble_sort(&mut ve3); + assert!(is_sorted(&ve3) && have_same_elements(&ve3, &cloned)); + } + #[test] + fn negative() { + let mut ve3: Vec = (-10..-1).rev().collect(); + let cloned = ve3.clone(); + bubble_sort(&mut ve3); + assert!(is_sorted(&ve3) && have_same_elements(&ve3, &cloned)); + } + #[test] + fn withnull() { + let mut ve3 = vec![2, 3, -3, 5, 7, 0, 1]; + let cloned = ve3.clone(); + bubble_sort(&mut ve3); + assert!(is_sorted(&ve3) && have_same_elements(&ve3, &cloned)); + } + /// Takes much time + #[test] + fn long() { + let mut ve3: Vec = (10..39000).collect(); + ve3.shuffle(&mut rng()); + let cloned = ve3.clone(); + bubble_sort(&mut ve3); + assert!(is_sorted(&ve3) && have_same_elements(&ve3, &cloned)); + } } From 5500fd27799159d76ee4476c5de2cfd2b26a86f3 Mon Sep 17 00:00:00 2001 From: D V <144282650+dabevlohn@users.noreply.github.com> Date: Thu, 26 Jun 2025 12:07:59 +0300 Subject: [PATCH 2/2] Update bubble_sort.rs --- src/sorting/bubble_sort.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/src/sorting/bubble_sort.rs b/src/sorting/bubble_sort.rs index 303c3c8843d..3532a259b50 100644 --- a/src/sorting/bubble_sort.rs +++ b/src/sorting/bubble_sort.rs @@ -71,7 +71,6 @@ mod tests { bubble_sort(&mut ve3); assert!(is_sorted(&ve3) && have_same_elements(&ve3, &cloned)); } - /// Takes much time #[test] fn long() { let mut ve3: Vec = (10..39000).collect();