Skip to content

Commit 939befd

Browse files
authoredAug 14, 2020
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
2 parents 6d09e29 + ff45df2 commit 939befd

File tree

9 files changed

+68
-56
lines changed

9 files changed

+68
-56
lines changed
 

Diff for: ‎library/alloc/src/collections/btree/map.rs

+3
Original file line numberDiff line numberDiff line change
@@ -3024,3 +3024,6 @@ impl<K: Ord, V, I: Iterator<Item = (K, V)>> Iterator for MergeIter<K, V, I> {
30243024
}
30253025
}
30263026
}
3027+
3028+
#[cfg(test)]
3029+
mod tests;

Diff for: ‎library/alloc/tests/btree/map.rs renamed to ‎library/alloc/src/collections/btree/map/tests.rs

+9-5
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,20 @@
1-
use std::collections::btree_map::Entry::{Occupied, Vacant};
2-
use std::collections::BTreeMap;
1+
use crate::boxed::Box;
2+
use crate::collections::btree_map::Entry::{Occupied, Vacant};
3+
use crate::collections::BTreeMap;
4+
use crate::fmt::Debug;
5+
use crate::rc::Rc;
6+
use crate::string::String;
7+
use crate::string::ToString;
8+
use crate::vec::Vec;
39
use std::convert::TryFrom;
4-
use std::fmt::Debug;
510
use std::iter::FromIterator;
611
use std::mem;
712
use std::ops::Bound::{self, Excluded, Included, Unbounded};
813
use std::ops::RangeBounds;
914
use std::panic::{catch_unwind, AssertUnwindSafe};
10-
use std::rc::Rc;
1115
use std::sync::atomic::{AtomicUsize, Ordering};
1216

13-
use super::DeterministicRng;
17+
use super::super::DeterministicRng;
1418

1519
// Value of node::CAPACITY, thus capacity of a tree with a single level,
1620
// i.e. a tree who's root is a leaf node at height 0.

Diff for: ‎library/alloc/src/collections/btree/mod.rs

+27
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,30 @@ pub unsafe fn unwrap_unchecked<T>(val: Option<T>) -> T {
2525
}
2626
})
2727
}
28+
29+
#[cfg(test)]
30+
/// XorShiftRng
31+
struct DeterministicRng {
32+
x: u32,
33+
y: u32,
34+
z: u32,
35+
w: u32,
36+
}
37+
38+
#[cfg(test)]
39+
impl DeterministicRng {
40+
fn new() -> Self {
41+
DeterministicRng { x: 0x193a6754, y: 0xa8a7d469, z: 0x97830e05, w: 0x113ba7bb }
42+
}
43+
44+
fn next(&mut self) -> u32 {
45+
let x = self.x;
46+
let t = x ^ (x << 11);
47+
self.x = self.y;
48+
self.y = self.z;
49+
self.z = self.w;
50+
let w_ = self.w;
51+
self.w = w_ ^ (w_ >> 19) ^ (t ^ (t >> 8));
52+
self.w
53+
}
54+
}

Diff for: ‎library/alloc/src/collections/btree/set.rs

+3
Original file line numberDiff line numberDiff line change
@@ -1572,3 +1572,6 @@ impl<'a, T: Ord> Iterator for Union<'a, T> {
15721572

15731573
#[stable(feature = "fused", since = "1.26.0")]
15741574
impl<T: Ord> FusedIterator for Union<'_, T> {}
1575+
1576+
#[cfg(test)]
1577+
mod tests;

Diff for: ‎library/alloc/tests/btree/set.rs renamed to ‎library/alloc/src/collections/btree/set/tests.rs

+3-20
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1-
use std::collections::BTreeSet;
1+
use crate::collections::BTreeSet;
2+
use crate::vec::Vec;
23
use std::iter::FromIterator;
34
use std::panic::{catch_unwind, AssertUnwindSafe};
45
use std::sync::atomic::{AtomicU32, Ordering};
56

6-
use super::DeterministicRng;
7+
use super::super::DeterministicRng;
78

89
#[test]
910
fn test_clone_eq() {
@@ -15,24 +16,6 @@ fn test_clone_eq() {
1516
assert_eq!(m.clone(), m);
1617
}
1718

18-
#[test]
19-
fn test_hash() {
20-
use crate::hash;
21-
22-
let mut x = BTreeSet::new();
23-
let mut y = BTreeSet::new();
24-
25-
x.insert(1);
26-
x.insert(2);
27-
x.insert(3);
28-
29-
y.insert(3);
30-
y.insert(2);
31-
y.insert(1);
32-
33-
assert_eq!(hash(&x), hash(&y));
34-
}
35-
3619
#[test]
3720
fn test_iter_min_max() {
3821
let mut a = BTreeSet::new();

Diff for: ‎library/alloc/src/lib.rs

+3
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@
8080
#![feature(arbitrary_self_types)]
8181
#![feature(box_patterns)]
8282
#![feature(box_syntax)]
83+
#![feature(btree_drain_filter)]
8384
#![feature(cfg_sanitize)]
8485
#![feature(cfg_target_has_atomic)]
8586
#![feature(coerce_unsized)]
@@ -102,6 +103,8 @@
102103
#![feature(lang_items)]
103104
#![feature(layout_for_ptr)]
104105
#![feature(libc)]
106+
#![feature(map_first_last)]
107+
#![feature(map_into_keys_values)]
105108
#![feature(negative_impls)]
106109
#![feature(new_uninit)]
107110
#![feature(nll)]

Diff for: ‎library/alloc/tests/btree/mod.rs

-27
This file was deleted.

Diff for: ‎library/alloc/tests/btree_set_hash.rs

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
use std::collections::BTreeSet;
2+
3+
#[test]
4+
fn test_hash() {
5+
use crate::hash;
6+
7+
let mut x = BTreeSet::new();
8+
let mut y = BTreeSet::new();
9+
10+
x.insert(1);
11+
x.insert(2);
12+
x.insert(3);
13+
14+
y.insert(3);
15+
y.insert(2);
16+
y.insert(1);
17+
18+
assert_eq!(hash(&x), hash(&y));
19+
}

Diff for: ‎library/alloc/tests/lib.rs

+1-4
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
11
#![feature(allocator_api)]
22
#![feature(box_syntax)]
3-
#![feature(btree_drain_filter)]
43
#![feature(drain_filter)]
54
#![feature(exact_size_is_empty)]
6-
#![feature(map_first_last)]
7-
#![feature(map_into_keys_values)]
85
#![feature(new_uninit)]
96
#![feature(pattern)]
107
#![feature(str_split_once)]
@@ -25,7 +22,7 @@ mod arc;
2522
mod binary_heap;
2623
mod borrow;
2724
mod boxed;
28-
mod btree;
25+
mod btree_set_hash;
2926
mod cow_str;
3027
mod fmt;
3128
mod heap;

0 commit comments

Comments
 (0)
Please sign in to comment.