about summary refs log tree commit diff
path: root/src/liballoc
diff options
context:
space:
mode:
authorvarkor <github@varkor.com>2018-03-19 00:11:47 +0000
committervarkor <github@varkor.com>2018-03-19 00:11:47 +0000
commiteca1e18cd7021f01757640c0c5ef63717870686c (patch)
treefac87195e2b2d01f1719b6301f142ec0e5efd77c /src/liballoc
parent785e3c38fe6c49e39aec145c81e463ceb60d179e (diff)
downloadrust-eca1e18cd7021f01757640c0c5ef63717870686c.tar.gz
rust-eca1e18cd7021f01757640c0c5ef63717870686c.zip
Add stability test for sort_by_cached_key
Diffstat (limited to 'src/liballoc')
-rw-r--r--src/liballoc/tests/slice.rs11
1 files changed, 8 insertions, 3 deletions
diff --git a/src/liballoc/tests/slice.rs b/src/liballoc/tests/slice.rs
index 7d4dac1c5ec..66c7dd75c87 100644
--- a/src/liballoc/tests/slice.rs
+++ b/src/liballoc/tests/slice.rs
@@ -485,7 +485,7 @@ fn test_sort_stability() {
             // the second item represents which occurrence of that
             // number this element is, i.e. the second elements
             // will occur in sorted order.
-            let mut v: Vec<_> = (0..len)
+            let mut orig: Vec<_> = (0..len)
                 .map(|_| {
                     let n = thread_rng().gen::<usize>() % 10;
                     counts[n] += 1;
@@ -493,16 +493,21 @@ fn test_sort_stability() {
                 })
                 .collect();
 
-            // only sort on the first element, so an unstable sort
+            let mut v = orig.clone();
+            // Only sort on the first element, so an unstable sort
             // may mix up the counts.
             v.sort_by(|&(a, _), &(b, _)| a.cmp(&b));
 
-            // this comparison includes the count (the second item
+            // This comparison includes the count (the second item
             // of the tuple), so elements with equal first items
             // will need to be ordered with increasing
             // counts... i.e. exactly asserting that this sort is
             // stable.
             assert!(v.windows(2).all(|w| w[0] <= w[1]));
+
+            let mut v = orig.clone();
+            v.sort_by_cached_key(|&(x, _)| x);
+            assert!(v.windows(2).all(|w| w[0] <= w[1]));
         }
     }
 }