Skip to content

Commit be4128d

Browse files
committed
BTreeMap: Add a test for clone
1 parent cd639d8 commit be4128d

File tree

1 file changed

+32
-0
lines changed
  • src/libcollectionstest/btree

1 file changed

+32
-0
lines changed

src/libcollectionstest/btree/map.rs

+32
Original file line numberDiff line numberDiff line change
@@ -346,6 +346,38 @@ fn test_bad_zst() {
346346
}
347347
}
348348

349+
#[test]
350+
fn test_clone() {
351+
let mut map = BTreeMap::new();
352+
let size = 100;
353+
assert_eq!(map.len(), 0);
354+
355+
for i in 0..size {
356+
assert_eq!(map.insert(i, 10*i), None);
357+
assert_eq!(map.len(), i + 1);
358+
assert_eq!(map, map.clone());
359+
}
360+
361+
for i in 0..size {
362+
assert_eq!(map.insert(i, 100*i), Some(10*i));
363+
assert_eq!(map.len(), size);
364+
assert_eq!(map, map.clone());
365+
}
366+
367+
for i in 0..size/2 {
368+
assert_eq!(map.remove(&(i*2)), Some(i*200));
369+
assert_eq!(map.len(), size - i - 1);
370+
assert_eq!(map, map.clone());
371+
}
372+
373+
for i in 0..size/2 {
374+
assert_eq!(map.remove(&(2*i)), None);
375+
assert_eq!(map.remove(&(2*i+1)), Some(i*200 + 100));
376+
assert_eq!(map.len(), size/2 - i - 1);
377+
assert_eq!(map, map.clone());
378+
}
379+
}
380+
349381
mod bench {
350382
use std::collections::BTreeMap;
351383
use std::__rand::{Rng, thread_rng};

0 commit comments

Comments
 (0)