You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

22 lines
604 B
Rust

use std::fmt::Debug;
use rand::{
seq::SliceRandom,
3 years ago
thread_rng,
};
3 years ago
use sorting;
use test_case::test_case;
use sorting::bubble_sort::sort;
3 years ago
3 years ago
#[test_case((0..20).rev().collect(), (0..20).collect(); "integers")]
#[test_case(vec ! ["c", "b", "a"], vec ! ["a", "b", "c"]; "strings")]
#[test_case(vec ! [6.0, 10.0, 2.0, 4.0, 8.0], vec ! [2.0, 4.0, 6.0, 8.0, 10.0]; "floats")]
fn can_bubble_sort<T: PartialOrd + Copy + Debug>(mut actual: Vec<T>, expected: Vec<T>) {
3 years ago
// Arrange
actual.shuffle(&mut thread_rng());
3 years ago
// Act
sort(&mut actual);
3 years ago
// Assert
assert_eq!(actual, expected);
3 years ago
}