File tree Expand file tree Collapse file tree 1 file changed +20
-0
lines changed Expand file tree Collapse file tree 1 file changed +20
-0
lines changed Original file line number Diff line number Diff line change @@ -541,6 +541,26 @@ fn into_values() {
541
541
assert ! ( values. contains( & 'c' ) ) ;
542
542
}
543
543
544
+ #[ test]
545
+ fn drain_range ( ) {
546
+ // Test the various heuristics of `erase_indices`
547
+ for range in [
548
+ 0 ..0 , // nothing erased
549
+ 10 ..90 , // reinsert the few kept (..10 and 90..)
550
+ 80 ..90 , // update the few to adjust (80..)
551
+ 20 ..30 , // sweep everything
552
+ ] {
553
+ let mut vec = Vec :: from_iter ( 0 ..100 ) ;
554
+ let mut map: IndexMap < i32 , ( ) > = ( 0 ..100 ) . map ( |i| ( i, ( ) ) ) . collect ( ) ;
555
+ drop ( vec. drain ( range. clone ( ) ) ) ;
556
+ drop ( map. drain ( range) ) ;
557
+ assert ! ( vec. iter( ) . eq( map. keys( ) ) ) ;
558
+ for ( i, x) in vec. iter ( ) . enumerate ( ) {
559
+ assert_eq ! ( map. get_index_of( x) , Some ( i) ) ;
560
+ }
561
+ }
562
+ }
563
+
544
564
#[ test]
545
565
#[ cfg( feature = "std" ) ]
546
566
fn from_array ( ) {
You can’t perform that action at this time.
0 commit comments