diff options
| author | Mazdak Farrokhzad <twingoow@gmail.com> | 2019-07-22 15:32:09 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2019-07-22 15:32:09 +0200 |
| commit | 0de90c67dce73694ddd577de67d8352e420bee0c (patch) | |
| tree | 3588f6a94ad061e808dea12d2b71d505804ba871 /src/libstd | |
| parent | 4bc1ce7bdb7f5dc9ea07c0b630c087d8e11140e4 (diff) | |
| parent | 503cedac0c33782ab2ec6765f6b790850d260bd2 (diff) | |
| download | rust-0de90c67dce73694ddd577de67d8352e420bee0c.tar.gz rust-0de90c67dce73694ddd577de67d8352e420bee0c.zip | |
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_).
Diffstat (limited to 'src/libstd')
| -rw-r--r-- | src/libstd/collections/hash/map.rs | 4 | ||||
| -rw-r--r-- | src/libstd/collections/hash/set.rs | 4 |
2 files changed, 6 insertions, 2 deletions
diff --git a/src/libstd/collections/hash/map.rs b/src/libstd/collections/hash/map.rs index 2925d8362c8..1e28ee8da26 100644 --- a/src/libstd/collections/hash/map.rs +++ b/src/libstd/collections/hash/map.rs @@ -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] diff --git a/src/libstd/collections/hash/set.rs b/src/libstd/collections/hash/set.rs index 403914c0707..d243412405a 100644 --- a/src/libstd/collections/hash/set.rs +++ b/src/libstd/collections/hash/set.rs @@ -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] |
