Skip to content

Commit 90fdee4

Browse files
authored
Edit testing data for sleep sort (TheAlgorithms#407)
* Edit testing data for sleep sort Reduce testing data and use lower values to spend less time running tests Also increase leniency so the tests don't fail, or at least fail less often * Switch to increasing leniency via a 20ms multiplier Thiis commit puts the test data closer together (and makes them lower values) while increasing the millis multiplier as per @siriak 's recommendation
1 parent b5fe7a3 commit 90fdee4

File tree

1 file changed

+7
-18
lines changed

1 file changed

+7
-18
lines changed

src/sorting/sleep_sort.rs

Lines changed: 7 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ pub fn sleep_sort(vec: &[usize]) -> Vec<usize> {
99
for &x in vec.iter() {
1010
let tx: mpsc::Sender<usize> = tx.clone();
1111
thread::spawn(move || {
12-
thread::sleep(Duration::from_millis((10 * x) as u64));
12+
thread::sleep(Duration::from_millis((20 * x) as u64));
1313
tx.send(x).expect("panic");
1414
});
1515
}
@@ -56,33 +56,22 @@ mod tests {
5656

5757
#[test]
5858
fn odd_number_of_elements() {
59-
let mut arr = vec![3, 4, 2, 1, 7];
59+
let mut arr = vec![3, 1, 7];
6060
let res = sleep_sort(&mut arr);
61-
assert_eq!(res, &[1, 2, 3, 4, 7]);
61+
assert_eq!(res, &[1, 3, 7]);
6262
}
6363

6464
#[test]
6565
fn repeated_elements() {
66-
let mut arr = vec![542, 542, 542, 542];
66+
let mut arr = vec![1, 1, 1, 1];
6767
let res = sleep_sort(&mut arr);
68-
assert_eq!(res, &[542, 542, 542, 542]);
68+
assert_eq!(res, &[1, 1, 1, 1]);
6969
}
7070

7171
#[test]
7272
fn random_elements() {
73-
let mut arr = vec![
74-
52, 958, 385, 130, 687, 86, 480, 329, 269, 648, 112, 286, 222, 844, 463, 982, 571, 104,
75-
491, 223, 791, 90, 43, 884, 518, 680, 347, 822, 505, 778, 62, 743, 775, 8, 357, 532,
76-
53, 680, 32, 271, 267, 306, 20, 915, 374, 477, 272, 638, 18, 299,
77-
];
73+
let mut arr = vec![5, 3, 7, 10, 1, 0, 8];
7874
let res = sleep_sort(&mut arr);
79-
assert_eq!(
80-
res,
81-
&[
82-
8, 18, 20, 32, 43, 52, 53, 62, 86, 90, 104, 112, 130, 222, 223, 267, 269, 271, 272,
83-
286, 299, 306, 329, 347, 357, 374, 385, 463, 477, 480, 491, 505, 518, 532, 571,
84-
638, 648, 680, 680, 687, 743, 775, 778, 791, 822, 844, 884, 915, 958, 982
85-
]
86-
);
75+
assert_eq!(res, &[0, 1, 3, 5, 7, 8, 10]);
8776
}
8877
}

0 commit comments

Comments
 (0)