Simplify tests

dust sort is now more predictable as it orders first by size and second
by name.

Walkdir still gives different iteration orders on different systems so
all output is not entirely predictable
This commit is contained in:
andy.boot
2018-04-27 11:07:10 +01:00
parent 8170a07886
commit 4ac85d7dc9
2 changed files with 22 additions and 34 deletions
+10 -1
View File
@@ -1,5 +1,6 @@
use std::collections::HashMap;
use std::collections::HashSet;
use std::cmp::Ordering;
use walkdir::WalkDir;
@@ -80,10 +81,18 @@ fn examine_dir(
}
}
}
pub fn compare_tuple(a :&(String, u64), b: &(String, u64)) -> Ordering {
let result = b.1.cmp(&a.1);
if result == Ordering::Equal {
a.0.cmp(&b.0)
} else {
result
}
}
pub fn sort<'a>(data: HashMap<String, u64>) -> Vec<(String, u64)> {
let mut new_l: Vec<(String, u64)> = data.iter().map(|(a, b)| (a.clone(), *b)).collect();
new_l.sort_by(|a, b| b.1.cmp(&a.1));
new_l.sort_by(|a, b| compare_tuple(&a, &b));
new_l
}