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:
commit
0de90c67dc
2 changed files with 6 additions and 2 deletions
|
@ -3138,13 +3138,15 @@ mod test_map {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_from_iter() {
|
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();
|
let map: HashMap<_, _> = xs.iter().cloned().collect();
|
||||||
|
|
||||||
for &(k, v) in &xs {
|
for &(k, v) in &xs {
|
||||||
assert_eq!(map.get(&k), Some(&v));
|
assert_eq!(map.get(&k), Some(&v));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
assert_eq!(map.iter().len(), xs.len() - 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
|
|
@ -1782,13 +1782,15 @@ mod test_set {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_from_iter() {
|
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();
|
let set: HashSet<_> = xs.iter().cloned().collect();
|
||||||
|
|
||||||
for x in &xs {
|
for x in &xs {
|
||||||
assert!(set.contains(x));
|
assert!(set.contains(x));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
assert_eq!(set.iter().len(), xs.len() - 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue