File tree 1 file changed +8
-3
lines changed
1 file changed +8
-3
lines changed Original file line number Diff line number Diff line change @@ -485,24 +485,29 @@ fn test_sort_stability() {
485
485
// the second item represents which occurrence of that
486
486
// number this element is, i.e. the second elements
487
487
// will occur in sorted order.
488
- let mut v : Vec < _ > = ( 0 ..len)
488
+ let mut orig : Vec < _ > = ( 0 ..len)
489
489
. map ( |_| {
490
490
let n = thread_rng ( ) . gen :: < usize > ( ) % 10 ;
491
491
counts[ n] += 1 ;
492
492
( n, counts[ n] )
493
493
} )
494
494
. collect ( ) ;
495
495
496
- // only sort on the first element, so an unstable sort
496
+ let mut v = orig. clone ( ) ;
497
+ // Only sort on the first element, so an unstable sort
497
498
// may mix up the counts.
498
499
v. sort_by ( |& ( a, _) , & ( b, _) | a. cmp ( & b) ) ;
499
500
500
- // this comparison includes the count (the second item
501
+ // This comparison includes the count (the second item
501
502
// of the tuple), so elements with equal first items
502
503
// will need to be ordered with increasing
503
504
// counts... i.e. exactly asserting that this sort is
504
505
// stable.
505
506
assert ! ( v. windows( 2 ) . all( |w| w[ 0 ] <= w[ 1 ] ) ) ;
507
+
508
+ let mut v = orig. clone ( ) ;
509
+ v. sort_by_cached_key ( |& ( x, _) | x) ;
510
+ assert ! ( v. windows( 2 ) . all( |w| w[ 0 ] <= w[ 1 ] ) ) ;
506
511
}
507
512
}
508
513
}
You can’t perform that action at this time.
0 commit comments