From 8be9300e130e21dffcd1a5ad89b0b38c8d683b71 Mon Sep 17 00:00:00 2001 From: Giacomo Stevanato Date: Thu, 20 Aug 2020 21:26:26 +0200 Subject: [PATCH] Removed GroupingMap::count and related tests, has been replaced by Itertools::counts in #468 --- src/grouping_map.rs | 27 --------------------------- tests/quick.rs | 20 -------------------- 2 files changed, 47 deletions(-) diff --git a/src/grouping_map.rs b/src/grouping_map.rs index 997ad4d0e..5232f5d6d 100644 --- a/src/grouping_map.rs +++ b/src/grouping_map.rs @@ -215,33 +215,6 @@ impl GroupingMap destination_map } - /// Groups elements from the `GroupingMap` source by key and counts them. - /// - /// Return a `HashMap` associating the key of each group with the number of that group's elements. - /// - /// ``` - /// use itertools::Itertools; - /// - /// let lookup = "This is a string".chars() - /// .into_grouping_map_by(|&c| c) - /// .count(); - /// - /// assert_eq!(lookup[&'T'], 1); - /// assert_eq!(lookup[&'h'], 1); - /// assert_eq!(lookup[&'i'], 3); - /// assert_eq!(lookup[&'s'], 3); - /// assert_eq!(lookup[&' '], 3); - /// assert_eq!(lookup[&'a'], 1); - /// assert_eq!(lookup[&'t'], 1); - /// assert_eq!(lookup[&'r'], 1); - /// assert_eq!(lookup[&'n'], 1); - /// assert_eq!(lookup[&'g'], 1); - /// assert_eq!(lookup.len(), 10); - /// ``` - pub fn count(self) -> HashMap { - self.fold(0, |acc, _, _| acc + 1) - } - /// Groups elements from the `GroupingMap` source by key and finds the maximum of each group. /// /// If several elements are equally maximum, the last element is picked. diff --git a/tests/quick.rs b/tests/quick.rs index 09bfa588f..54ba818ce 100644 --- a/tests/quick.rs +++ b/tests/quick.rs @@ -1303,26 +1303,6 @@ quickcheck! { assert_eq!(lookup_grouping_map, lookup_group_map); } - fn correct_grouping_map_by_count_modulo_key(a: Vec, modulo: u8) -> () { - let modulo = if modulo == 0 { 1 } else { modulo }; // Avoid `% 0` - let count = a.len(); - let lookup = a.iter().copied().into_grouping_map_by(|i| i % modulo).count(); - - let group_map_lookup = a.iter().copied() - .map(|i| (i % modulo, i)) - .into_group_map() - .into_iter() - .map(|(key, vals)| (key, vals.len())) - .collect::>(); - assert_eq!(lookup, group_map_lookup); - - assert_eq!(lookup.values().sum::(), count); - - for (&key, &count) in lookup.iter() { - assert_eq!(count, a.iter().filter(|&val| val % modulo == key).count()); - } - } - fn correct_grouping_map_by_max_modulo_key(a: Vec, modulo: u8) -> () { let modulo = if modulo == 0 { 1 } else { modulo }; // Avoid `% 0` let lookup = a.iter().copied().into_grouping_map_by(|i| i % modulo).max();