added proptesting for TandemSort

This commit is contained in:
MaxOhn
2024-02-16 01:33:21 +01:00
parent 05b588a2d1
commit 3f49840ce8
2 changed files with 34 additions and 10 deletions
+9
View File
@@ -10,3 +10,12 @@ tracing = ["rosu-map/tracing"]
[dependencies] [dependencies]
rosu-map = { path = "../rosu-map" } rosu-map = { path = "../rosu-map" }
thiserror = { version = "1.0.50" } thiserror = { version = "1.0.50" }
[dev-dependencies]
proptest = "1.4.0"
[profile.test.package.proptest]
opt-level = 3
[profile.test.package.rand_chacha]
opt-level = 3
+23 -8
View File
@@ -107,18 +107,33 @@ impl TandemSorter {
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use proptest::prelude::*;
use super::TandemSorter; use super::TandemSorter;
proptest! {
#![proptest_config(ProptestConfig::with_cases(10_000))]
#[test] #[test]
fn sort() { fn sort(mut actual in prop::collection::vec(0_u8..100, 0..100)) {
let mut base = vec![9, 7, 8, 1, 4, 3, 5, 2]; let mut expected = actual.clone();
let mut other = "hello World".chars().collect::<Vec<_>>(); expected.sort_unstable();
let mut sorter = TandemSorter::new_stable(&base, u8::cmp);
sorter.sort(&mut base); let mut sorter = TandemSorter::new_unstable(&actual, u8::cmp);
assert_eq!(base, vec![1, 2, 3, 4, 5, 7, 8, 9]); sorter.sort(&mut actual);
sorter.sort(&mut other); assert_eq!(actual, expected);
assert_eq!(other.iter().collect::<String>(), "lo oWelhrld"); }
#[test]
fn unsort(mut actual in prop::collection::vec(0_u8..100, 0..100)) {
let expected = actual.clone();
let mut sorter = TandemSorter::new_unstable(&actual, u8::cmp);
sorter.sort(&mut actual);
sorter.unsort(&mut actual);
assert_eq!(actual, expected);
}
} }
} }