mirror of
https://github.com/bootandy/dust.git
synced 2026-06-08 11:29:05 +03:00
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:
+10
-1
@@ -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
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user