Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create counts method and tests for it #468

Merged
merged 2 commits into from Aug 20, 2020
Merged

Conversation

JarredAllen
Copy link
Contributor

Creates the function described in #467 (I went with the name counts).

It currently uses for_each and makes a HashMap manually because the PR for the into_grouping_map function is still being worked on, but this function could easily be changed to call it once that PR is merged, if desired.

Comment on lines 916 to 928

#[test]
fn counts() {
let a: [usize; 0] = [];
assert_eq!(0, a.iter().counts().len());
let b = [1, 1, 1, 2, 2, 3];
let b_counts = b.iter().counts();
assert_eq!(3, b_counts.len());
assert_eq!(Some(&3), b_counts.get(&1));
assert_eq!(Some(&2), b_counts.get(&2));
assert_eq!(Some(&1), b_counts.get(&3));
assert_eq!(None, b_counts.get(&4));
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn't a quicktest be better? You can probably adapt the test I wrote in my PR for my count method:

https://github.com/rust-itertools/itertools/pull/465/files#diff-934f6ed12102bba0b289ee2855cb9bd1R1306-R1324

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it would, and I've now included that. Thanks for the suggestion.

@jswrenn
Copy link
Member

jswrenn commented Aug 20, 2020

Looks good to me! Thanks for this!

bors r+

@jswrenn jswrenn added this to the next milestone Aug 20, 2020
@bors
Copy link
Contributor

bors bot commented Aug 20, 2020

Build succeeded:

@bors bors bot merged commit 89f3a0d into rust-itertools:master Aug 20, 2020
SkiFire13 added a commit to SkiFire13/itertools that referenced this pull request Aug 20, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants