From e6f6d26d131e3a3ee89248c1fdaba22d8d1d79e2 Mon Sep 17 00:00:00 2001 From: mo8it Date: Fri, 5 Jul 2024 11:49:56 +0200 Subject: [PATCH] Import enum variants in all tests --- solutions/18_iterators/iterators5.rs | 43 +++++++++------------------- 1 file changed, 14 insertions(+), 29 deletions(-) diff --git a/solutions/18_iterators/iterators5.rs b/solutions/18_iterators/iterators5.rs index 85d9a4f9..067a117b 100644 --- a/solutions/18_iterators/iterators5.rs +++ b/solutions/18_iterators/iterators5.rs @@ -47,8 +47,8 @@ fn count_collection_iterator(collection: &[HashMap], value: Pr .sum() } -// Equivalent to `count_collection_iterator`+`count_iterator`, iterating as if -// the collection was a single container instead of a container of containers +// Equivalent to `count_collection_iterator` and `count_iterator`, iterating as +// if the collection was a single container instead of a container of containers // (and more accurately, a single iterator instead of an iterator of iterators). fn count_collection_iterator_flat( collection: &[HashMap], @@ -71,10 +71,9 @@ fn main() { #[cfg(test)] mod tests { use super::*; + use Progress::*; fn get_map() -> HashMap { - use Progress::*; - let mut map = HashMap::new(); map.insert(String::from("variables1"), Complete); map.insert(String::from("functions1"), Complete); @@ -87,8 +86,6 @@ mod tests { } fn get_vec_map() -> Vec> { - use Progress::*; - let map = get_map(); let mut other = HashMap::new(); @@ -104,25 +101,25 @@ mod tests { #[test] fn count_complete() { let map = get_map(); - assert_eq!(count_iterator(&map, Progress::Complete), 3); + assert_eq!(count_iterator(&map, Complete), 3); } #[test] fn count_some() { let map = get_map(); - assert_eq!(count_iterator(&map, Progress::Some), 1); + assert_eq!(count_iterator(&map, Some), 1); } #[test] fn count_none() { let map = get_map(); - assert_eq!(count_iterator(&map, Progress::None), 2); + assert_eq!(count_iterator(&map, None), 2); } #[test] fn count_complete_equals_for() { let map = get_map(); - let progress_states = [Progress::Complete, Progress::Some, Progress::None]; + let progress_states = [Complete, Some, None]; for progress_state in progress_states { assert_eq!( count_for(&map, progress_state), @@ -134,40 +131,28 @@ mod tests { #[test] fn count_collection_complete() { let collection = get_vec_map(); - assert_eq!( - count_collection_iterator(&collection, Progress::Complete), - 6, - ); - assert_eq!( - count_collection_iterator_flat(&collection, Progress::Complete), - 6, - ); + assert_eq!(count_collection_iterator(&collection, Complete), 6); + assert_eq!(count_collection_iterator_flat(&collection, Complete), 6); } #[test] fn count_collection_some() { let collection = get_vec_map(); - assert_eq!(count_collection_iterator(&collection, Progress::Some), 1); - assert_eq!( - count_collection_iterator_flat(&collection, Progress::Some), - 1 - ); + assert_eq!(count_collection_iterator(&collection, Some), 1); + assert_eq!(count_collection_iterator_flat(&collection, Some), 1); } #[test] fn count_collection_none() { let collection = get_vec_map(); - assert_eq!(count_collection_iterator(&collection, Progress::None), 4); - assert_eq!( - count_collection_iterator_flat(&collection, Progress::None), - 4 - ); + assert_eq!(count_collection_iterator(&collection, None), 4); + assert_eq!(count_collection_iterator_flat(&collection, None), 4); } #[test] fn count_collection_equals_for() { let collection = get_vec_map(); - let progress_states = [Progress::Complete, Progress::Some, Progress::None]; + let progress_states = [Complete, Some, None]; for progress_state in progress_states { assert_eq!(