#[cfg(test)]
-use std::collections::HashMap;
+use std::collections::{HashMap, HashSet};
#[cfg(test)]
use std::io::BufRead;
#[cfg(test)]
#[cfg(test)]
fn column_counts(rows: &[RowInput]) -> HashMap<String, usize> {
rows.iter()
- .flat_map(|r| r.entries.iter())
+ .flat_map(|r| r.entries.iter().collect::<HashSet<_>>().into_iter())
.fold(HashMap::new(), |mut counts, e| {
counts
.entry(String::from(e))
),
HashMap::from([(String::from("bar"), 1), (String::from("baz"), 2)])
);
+ assert_eq!(
+ column_counts(
+ &read_rows(&b"foo\n bar\n bar\n baz\n bar\nquux\n baz"[..])
+ .collect::<Result<Vec<_>, _>>()
+ .unwrap()
+ ),
+ HashMap::from([(String::from("bar"), 1), (String::from("baz"), 2)])
+ );
}
}