Skip to content

Commit 7d42916

Browse files
committed
Test insertion_sort.
1 parent 057e035 commit 7d42916

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

src/insertion_sort.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,3 +251,22 @@ where
251251
// Didn't manage to sort the slice in the limited number of steps.
252252
false
253253
}
254+
255+
#[cfg(feature = "std")]
256+
#[cfg(test)]
257+
mod test {
258+
use super::insertion_sort_shift_left;
259+
use ndarray::Array1;
260+
use quickcheck_macros::quickcheck;
261+
262+
#[quickcheck]
263+
fn sorted(xs: Vec<u32>) {
264+
let mut array = Array1::from_vec(xs);
265+
if !array.is_empty() {
266+
insertion_sort_shift_left(array.view_mut(), 1, &mut u32::lt);
267+
}
268+
for i in 1..array.len() {
269+
assert!(array[i - 1] <= array[i]);
270+
}
271+
}
272+
}

0 commit comments

Comments
 (0)