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
Conversation
tests/test_std.rs
Outdated
|
||
#[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)); | ||
} |
There was a problem hiding this comment.
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:
There was a problem hiding this comment.
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.
Looks good to me! Thanks for this! bors r+ |
Build succeeded: |
Creates the function described in #467 (I went with the name
counts
).It currently uses
for_each
and makes aHashMap
manually because the PR for theinto_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.