Add unit tests for new HashMap::into_{keys,values} methods

This commit is contained in:
Nazım Can Altınova 2020-08-04 22:04:12 +02:00
parent 13529f22ba
commit 41dd4ee7ff
No known key found for this signature in database
GPG key ID: 722E786F0729647A

View file

@ -3212,6 +3212,30 @@ mod test_map {
assert!(values.contains(&6));
}
#[test]
fn test_into_keys() {
let vec = vec![(1, 'a'), (2, 'b'), (3, 'c')];
let map: HashMap<_, _> = vec.into_iter().collect();
let keys: Vec<_> = map.into_keys().collect();
assert_eq!(keys.len(), 3);
assert!(keys.contains(&1));
assert!(keys.contains(&2));
assert!(keys.contains(&3));
}
#[test]
fn test_into_values() {
let vec = vec![(1, 'a'), (2, 'b'), (3, 'c')];
let map: HashMap<_, _> = vec.into_iter().collect();
let values: Vec<_> = map.into_values().collect();
assert_eq!(values.len(), 3);
assert!(values.contains(&'a'));
assert!(values.contains(&'b'));
assert!(values.contains(&'c'));
}
#[test]
fn test_find() {
let mut m = HashMap::new();