about summary refs log tree commit diff
path: root/src/libcore/tests
diff options
context:
space:
mode:
authorAaron Kutch <aaronkutch@att.net>2019-08-06 10:42:48 -0500
committerAaron Kutch <aaronkutch@att.net>2019-08-06 10:42:48 -0500
commitad7fdb6859df49da179bfb4402380717aa424b0f (patch)
treec67bd730abe460bb45a802463f7858cfa0236079 /src/libcore/tests
parent890881f8f4c77e8670d4b32104c0325fcfefc90f (diff)
downloadrust-ad7fdb6859df49da179bfb4402380717aa424b0f.tar.gz
rust-ad7fdb6859df49da179bfb4402380717aa424b0f.zip
Improve `ptr_rotate` performance, tests, and benchmarks
Diffstat (limited to 'src/libcore/tests')
-rw-r--r--src/libcore/tests/slice.rs38
1 files changed, 38 insertions, 0 deletions
diff --git a/src/libcore/tests/slice.rs b/src/libcore/tests/slice.rs
index 42ec9d451f7..712109110fd 100644
--- a/src/libcore/tests/slice.rs
+++ b/src/libcore/tests/slice.rs
@@ -1131,6 +1131,44 @@ fn test_rotate_right() {
 }
 
 #[test]
+#[cfg(not(miri))]
+fn brute_force_rotate_test_0() {
+    // In case of edge cases involving multiple algorithms
+    let n = 300;
+    for len in 0..n {
+        for s in 0..len {
+            let mut v = Vec::with_capacity(len);
+            for i in 0..len {
+                v.push(i);
+            }
+            v[..].rotate_right(s);
+            for i in 0..v.len() {
+                assert_eq!(v[i], v.len().wrapping_add(i.wrapping_sub(s)) % v.len());
+            }
+        }
+    }
+}
+
+#[test]
+fn brute_force_rotate_test_1() {
+    // `ptr_rotate` covers so many kinds of pointer usage, that this is just a good test for
+    // pointers in general. This uses a `[usize; 4]` to hit all algorithms without overwhelming miri
+    let n = 30;
+    for len in 0..n {
+        for s in 0..len {
+            let mut v: Vec<[usize; 4]> = Vec::with_capacity(len);
+            for i in 0..len {
+                v.push([i, 0, 0, 0]);
+            }
+            v[..].rotate_right(s);
+            for i in 0..v.len() {
+                assert_eq!(v[i][0], v.len().wrapping_add(i.wrapping_sub(s)) % v.len());
+            }
+        }
+    }
+}
+
+#[test]
 #[cfg(not(target_arch = "wasm32"))]
 fn sort_unstable() {
     use core::cmp::Ordering::{Equal, Greater, Less};