Skip to content

Commit 5989b5f

Browse files
committed
BTreeMap/BTreeSet: separate off code supporting tests
1 parent 9b32429 commit 5989b5f

File tree

6 files changed

+34
-34
lines changed

6 files changed

+34
-34
lines changed

library/alloc/src/collections/btree/map/tests.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
use super::super::{node, DeterministicRng};
1+
use super::super::testing::ord_chaos::{Cyclic3, Governed, Governor};
2+
use super::super::testing::rng::DeterministicRng;
23
use super::Entry::{Occupied, Vacant};
34
use super::*;
45
use crate::boxed::Box;
@@ -15,9 +16,6 @@ use std::ops::RangeBounds;
1516
use std::panic::{catch_unwind, AssertUnwindSafe};
1617
use std::sync::atomic::{AtomicUsize, Ordering::SeqCst};
1718

18-
mod ord_chaos;
19-
use ord_chaos::{Cyclic3, Governed, Governor};
20-
2119
// Capacity of a tree with a single level,
2220
// i.e., a tree who's root is a leaf node at height 0.
2321
const NODE_CAPACITY: usize = node::CAPACITY;

library/alloc/src/collections/btree/mod.rs

+1-29
Original file line numberDiff line numberDiff line change
@@ -36,32 +36,4 @@ pub unsafe fn unwrap_unchecked<T>(val: Option<T>) -> T {
3636
}
3737

3838
#[cfg(test)]
39-
/// XorShiftRng
40-
struct DeterministicRng {
41-
count: usize,
42-
x: u32,
43-
y: u32,
44-
z: u32,
45-
w: u32,
46-
}
47-
48-
#[cfg(test)]
49-
impl DeterministicRng {
50-
fn new() -> Self {
51-
DeterministicRng { count: 0, x: 0x193a6754, y: 0xa8a7d469, z: 0x97830e05, w: 0x113ba7bb }
52-
}
53-
54-
/// Guarantees that each returned number is unique.
55-
fn next(&mut self) -> u32 {
56-
self.count += 1;
57-
assert!(self.count <= 70029);
58-
let x = self.x;
59-
let t = x ^ (x << 11);
60-
self.x = self.y;
61-
self.y = self.z;
62-
self.z = self.w;
63-
let w_ = self.w;
64-
self.w = w_ ^ (w_ >> 19) ^ (t ^ (t >> 8));
65-
self.w
66-
}
67-
}
39+
mod testing;

library/alloc/src/collections/btree/set/tests.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use super::super::DeterministicRng;
1+
use super::super::testing::rng::DeterministicRng;
22
use super::*;
33
use crate::vec::Vec;
44
use std::cmp::Ordering;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
pub mod ord_chaos;
2+
pub mod rng;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/// XorShiftRng
2+
pub struct DeterministicRng {
3+
count: usize,
4+
x: u32,
5+
y: u32,
6+
z: u32,
7+
w: u32,
8+
}
9+
10+
impl DeterministicRng {
11+
pub fn new() -> Self {
12+
DeterministicRng { count: 0, x: 0x193a6754, y: 0xa8a7d469, z: 0x97830e05, w: 0x113ba7bb }
13+
}
14+
15+
/// Guarantees that each returned number is unique.
16+
pub fn next(&mut self) -> u32 {
17+
self.count += 1;
18+
assert!(self.count <= 70029);
19+
let x = self.x;
20+
let t = x ^ (x << 11);
21+
self.x = self.y;
22+
self.y = self.z;
23+
self.z = self.w;
24+
let w_ = self.w;
25+
self.w = w_ ^ (w_ >> 19) ^ (t ^ (t >> 8));
26+
self.w
27+
}
28+
}

0 commit comments

Comments
 (0)