1
Fork 0

Rollup merge of #62709 - nhynes:test-maplike-fromiter, r=cuviper

Test that maplike FromIter satisfies uniqueness

This PR adds a simple assertion to the `HashMap` and `HashSet` tests to ensure that uniqueness is satisfied when `FromIter`ing. This is useful for people who want to test their custom type against the Map/Set interfaces since they'll copy the tests wholesale but possibly miss this bug (where _they_ = _me_).
This commit is contained in:
Mazdak Farrokhzad 2019-07-22 15:32:09 +02:00 committed by GitHub
commit 0de90c67dc
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 6 additions and 2 deletions

View file

@ -3138,13 +3138,15 @@ mod test_map {
#[test]
fn test_from_iter() {
let xs = [(1, 1), (2, 2), (3, 3), (4, 4), (5, 5), (6, 6)];
let xs = [(1, 1), (2, 2), (2, 2), (3, 3), (4, 4), (5, 5), (6, 6)];
let map: HashMap<_, _> = xs.iter().cloned().collect();
for &(k, v) in &xs {
assert_eq!(map.get(&k), Some(&v));
}
assert_eq!(map.iter().len(), xs.len() - 1);
}
#[test]

View file

@ -1782,13 +1782,15 @@ mod test_set {
#[test]
fn test_from_iter() {
let xs = [1, 2, 3, 4, 5, 6, 7, 8, 9];
let xs = [1, 2, 2, 3, 4, 5, 6, 7, 8, 9];
let set: HashSet<_> = xs.iter().cloned().collect();
for x in &xs {
assert!(set.contains(x));
}
assert_eq!(set.iter().len(), xs.len() - 1);
}
#[test]