about summary refs log tree commit diff
diff options
context:
space:
mode:
authorTyler Mandry <tmandry@gmail.com>2020-08-14 14:47:04 -0700
committerGitHub <noreply@github.com>2020-08-14 14:47:04 -0700
commit939befd65e17432b3bdee6b48d7858b608e962c5 (patch)
tree069f45ea63dbee1f560f9e418ede75b2554d9ee2
parent6d09e29f5e977d7d6da612d94e9a78afd83fa104 (diff)
parentff45df2acf8cb31e50930840d48d5285b67b23ec (diff)
downloadrust-939befd65e17432b3bdee6b48d7858b608e962c5.tar.gz
rust-939befd65e17432b3bdee6b48d7858b608e962c5.zip
Rollup merge of #75531 - ssomers:btree_tests_migration, r=Mark-Simulacrum
Migrate unit tests of btree collections to their native breeding ground

There's one BTreeSet test case that I couldn't easily convince to come along, maybe because it truly is an integration test. But leaving it in place would mean git wouldn't see the move so I also moved it to a new file.

r? @Mark-Simulacrum
-rw-r--r--library/alloc/src/collections/btree/map.rs3
-rw-r--r--library/alloc/src/collections/btree/map/tests.rs (renamed from library/alloc/tests/btree/map.rs)14
-rw-r--r--library/alloc/src/collections/btree/mod.rs27
-rw-r--r--library/alloc/src/collections/btree/set.rs3
-rw-r--r--library/alloc/src/collections/btree/set/tests.rs (renamed from library/alloc/tests/btree/set.rs)23
-rw-r--r--library/alloc/src/lib.rs3
-rw-r--r--library/alloc/tests/btree/mod.rs27
-rw-r--r--library/alloc/tests/btree_set_hash.rs19
-rw-r--r--library/alloc/tests/lib.rs5
9 files changed, 68 insertions, 56 deletions
diff --git a/library/alloc/src/collections/btree/map.rs b/library/alloc/src/collections/btree/map.rs
index 8e800f48c69..b22eb1ff635 100644
--- a/library/alloc/src/collections/btree/map.rs
+++ b/library/alloc/src/collections/btree/map.rs
@@ -3024,3 +3024,6 @@ impl<K: Ord, V, I: Iterator<Item = (K, V)>> Iterator for MergeIter<K, V, I> {
         }
     }
 }
+
+#[cfg(test)]
+mod tests;
diff --git a/library/alloc/tests/btree/map.rs b/library/alloc/src/collections/btree/map/tests.rs
index 5777bd60907..910e7043092 100644
--- a/library/alloc/tests/btree/map.rs
+++ b/library/alloc/src/collections/btree/map/tests.rs
@@ -1,16 +1,20 @@
-use std::collections::btree_map::Entry::{Occupied, Vacant};
-use std::collections::BTreeMap;
+use crate::boxed::Box;
+use crate::collections::btree_map::Entry::{Occupied, Vacant};
+use crate::collections::BTreeMap;
+use crate::fmt::Debug;
+use crate::rc::Rc;
+use crate::string::String;
+use crate::string::ToString;
+use crate::vec::Vec;
 use std::convert::TryFrom;
-use std::fmt::Debug;
 use std::iter::FromIterator;
 use std::mem;
 use std::ops::Bound::{self, Excluded, Included, Unbounded};
 use std::ops::RangeBounds;
 use std::panic::{catch_unwind, AssertUnwindSafe};
-use std::rc::Rc;
 use std::sync::atomic::{AtomicUsize, Ordering};
 
-use super::DeterministicRng;
+use super::super::DeterministicRng;
 
 // Value of node::CAPACITY, thus capacity of a tree with a single level,
 // i.e. a tree who's root is a leaf node at height 0.
diff --git a/library/alloc/src/collections/btree/mod.rs b/library/alloc/src/collections/btree/mod.rs
index 543ff41a4d4..6c8a588eb58 100644
--- a/library/alloc/src/collections/btree/mod.rs
+++ b/library/alloc/src/collections/btree/mod.rs
@@ -25,3 +25,30 @@ pub unsafe fn unwrap_unchecked<T>(val: Option<T>) -> T {
         }
     })
 }
+
+#[cfg(test)]
+/// XorShiftRng
+struct DeterministicRng {
+    x: u32,
+    y: u32,
+    z: u32,
+    w: u32,
+}
+
+#[cfg(test)]
+impl DeterministicRng {
+    fn new() -> Self {
+        DeterministicRng { x: 0x193a6754, y: 0xa8a7d469, z: 0x97830e05, w: 0x113ba7bb }
+    }
+
+    fn next(&mut self) -> u32 {
+        let x = self.x;
+        let t = x ^ (x << 11);
+        self.x = self.y;
+        self.y = self.z;
+        self.z = self.w;
+        let w_ = self.w;
+        self.w = w_ ^ (w_ >> 19) ^ (t ^ (t >> 8));
+        self.w
+    }
+}
diff --git a/library/alloc/src/collections/btree/set.rs b/library/alloc/src/collections/btree/set.rs
index 35f4ef1d9b4..a559e87e4e2 100644
--- a/library/alloc/src/collections/btree/set.rs
+++ b/library/alloc/src/collections/btree/set.rs
@@ -1572,3 +1572,6 @@ impl<'a, T: Ord> Iterator for Union<'a, T> {
 
 #[stable(feature = "fused", since = "1.26.0")]
 impl<T: Ord> FusedIterator for Union<'_, T> {}
+
+#[cfg(test)]
+mod tests;
diff --git a/library/alloc/tests/btree/set.rs b/library/alloc/src/collections/btree/set/tests.rs
index b6c34b7c6c3..f4e957e22fe 100644
--- a/library/alloc/tests/btree/set.rs
+++ b/library/alloc/src/collections/btree/set/tests.rs
@@ -1,9 +1,10 @@
-use std::collections::BTreeSet;
+use crate::collections::BTreeSet;
+use crate::vec::Vec;
 use std::iter::FromIterator;
 use std::panic::{catch_unwind, AssertUnwindSafe};
 use std::sync::atomic::{AtomicU32, Ordering};
 
-use super::DeterministicRng;
+use super::super::DeterministicRng;
 
 #[test]
 fn test_clone_eq() {
@@ -16,24 +17,6 @@ fn test_clone_eq() {
 }
 
 #[test]
-fn test_hash() {
-    use crate::hash;
-
-    let mut x = BTreeSet::new();
-    let mut y = BTreeSet::new();
-
-    x.insert(1);
-    x.insert(2);
-    x.insert(3);
-
-    y.insert(3);
-    y.insert(2);
-    y.insert(1);
-
-    assert_eq!(hash(&x), hash(&y));
-}
-
-#[test]
 fn test_iter_min_max() {
     let mut a = BTreeSet::new();
     assert_eq!(a.iter().min(), None);
diff --git a/library/alloc/src/lib.rs b/library/alloc/src/lib.rs
index 75a2c6be41c..2d25941a524 100644
--- a/library/alloc/src/lib.rs
+++ b/library/alloc/src/lib.rs
@@ -80,6 +80,7 @@
 #![feature(arbitrary_self_types)]
 #![feature(box_patterns)]
 #![feature(box_syntax)]
+#![feature(btree_drain_filter)]
 #![feature(cfg_sanitize)]
 #![feature(cfg_target_has_atomic)]
 #![feature(coerce_unsized)]
@@ -102,6 +103,8 @@
 #![feature(lang_items)]
 #![feature(layout_for_ptr)]
 #![feature(libc)]
+#![feature(map_first_last)]
+#![feature(map_into_keys_values)]
 #![feature(negative_impls)]
 #![feature(new_uninit)]
 #![feature(nll)]
diff --git a/library/alloc/tests/btree/mod.rs b/library/alloc/tests/btree/mod.rs
deleted file mode 100644
index 1d08ae13e05..00000000000
--- a/library/alloc/tests/btree/mod.rs
+++ /dev/null
@@ -1,27 +0,0 @@
-mod map;
-mod set;
-
-/// XorShiftRng
-struct DeterministicRng {
-    x: u32,
-    y: u32,
-    z: u32,
-    w: u32,
-}
-
-impl DeterministicRng {
-    fn new() -> Self {
-        DeterministicRng { x: 0x193a6754, y: 0xa8a7d469, z: 0x97830e05, w: 0x113ba7bb }
-    }
-
-    fn next(&mut self) -> u32 {
-        let x = self.x;
-        let t = x ^ (x << 11);
-        self.x = self.y;
-        self.y = self.z;
-        self.z = self.w;
-        let w_ = self.w;
-        self.w = w_ ^ (w_ >> 19) ^ (t ^ (t >> 8));
-        self.w
-    }
-}
diff --git a/library/alloc/tests/btree_set_hash.rs b/library/alloc/tests/btree_set_hash.rs
new file mode 100644
index 00000000000..e06a95ded94
--- /dev/null
+++ b/library/alloc/tests/btree_set_hash.rs
@@ -0,0 +1,19 @@
+use std::collections::BTreeSet;
+
+#[test]
+fn test_hash() {
+    use crate::hash;
+
+    let mut x = BTreeSet::new();
+    let mut y = BTreeSet::new();
+
+    x.insert(1);
+    x.insert(2);
+    x.insert(3);
+
+    y.insert(3);
+    y.insert(2);
+    y.insert(1);
+
+    assert_eq!(hash(&x), hash(&y));
+}
diff --git a/library/alloc/tests/lib.rs b/library/alloc/tests/lib.rs
index 3aacd4a687e..f2ba1ab6481 100644
--- a/library/alloc/tests/lib.rs
+++ b/library/alloc/tests/lib.rs
@@ -1,10 +1,7 @@
 #![feature(allocator_api)]
 #![feature(box_syntax)]
-#![feature(btree_drain_filter)]
 #![feature(drain_filter)]
 #![feature(exact_size_is_empty)]
-#![feature(map_first_last)]
-#![feature(map_into_keys_values)]
 #![feature(new_uninit)]
 #![feature(pattern)]
 #![feature(str_split_once)]
@@ -25,7 +22,7 @@ mod arc;
 mod binary_heap;
 mod borrow;
 mod boxed;
-mod btree;
+mod btree_set_hash;
 mod cow_str;
 mod fmt;
 mod heap;