Skip to content

Commit f4420c9

Browse files
committed
Rename MockAddRng → StepRng and fix test
1 parent ff1b538 commit f4420c9

File tree

5 files changed

+24
-25
lines changed

5 files changed

+24
-25
lines changed

src/distributions/float.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -99,57 +99,57 @@ float_impls! { f32_rand_impls, f32, 23, next_f32 }
9999
#[cfg(test)]
100100
mod tests {
101101
use Rng;
102-
use mock::MockAddRng;
102+
use mock::StepRng;
103103
use distributions::{Open01, Closed01};
104104

105105
const EPSILON32: f32 = ::core::f32::EPSILON;
106106
const EPSILON64: f64 = ::core::f64::EPSILON;
107107

108108
#[test]
109109
fn floating_point_edge_cases() {
110-
let mut zeros = MockAddRng::new(0, 0);
110+
let mut zeros = StepRng::new(0, 0);
111111
assert_eq!(zeros.gen::<f32>(), 0.0);
112112
assert_eq!(zeros.gen::<f64>(), 0.0);
113113

114-
let mut one = MockAddRng::new(1, 0);
114+
let mut one = StepRng::new(1, 0);
115115
assert_eq!(one.gen::<f32>(), EPSILON32);
116116
assert_eq!(one.gen::<f64>(), EPSILON64);
117117

118-
let mut max = MockAddRng::new(!0, 0);
118+
let mut max = StepRng::new(!0, 0);
119119
assert_eq!(max.gen::<f32>(), 1.0 - EPSILON32);
120120
assert_eq!(max.gen::<f64>(), 1.0 - EPSILON64);
121121
}
122122

123123
#[test]
124124
fn fp_closed_edge_cases() {
125-
let mut zeros = MockAddRng::new(0, 0);
125+
let mut zeros = StepRng::new(0, 0);
126126
assert_eq!(zeros.sample::<f32, _>(Closed01), 0.0);
127127
assert_eq!(zeros.sample::<f64, _>(Closed01), 0.0);
128128

129-
let mut one = MockAddRng::new(1, 0);
129+
let mut one = StepRng::new(1, 0);
130130
let one32 = one.sample::<f32, _>(Closed01);
131131
let one64 = one.sample::<f64, _>(Closed01);
132132
assert!(EPSILON32 < one32 && one32 < EPSILON32 * 1.01);
133133
assert!(EPSILON64 < one64 && one64 < EPSILON64 * 1.01);
134134

135-
let mut max = MockAddRng::new(!0, 0);
135+
let mut max = StepRng::new(!0, 0);
136136
assert_eq!(max.sample::<f32, _>(Closed01), 1.0);
137137
assert_eq!(max.sample::<f64, _>(Closed01), 1.0);
138138
}
139139

140140
#[test]
141141
fn fp_open_edge_cases() {
142-
let mut zeros = MockAddRng::new(0, 0);
142+
let mut zeros = StepRng::new(0, 0);
143143
assert_eq!(zeros.sample::<f32, _>(Open01), 0.0 + EPSILON32 / 2.0);
144144
assert_eq!(zeros.sample::<f64, _>(Open01), 0.0 + EPSILON64 / 2.0);
145145

146-
let mut one = MockAddRng::new(1, 0);
146+
let mut one = StepRng::new(1, 0);
147147
let one32 = one.sample::<f32, _>(Open01);
148148
let one64 = one.sample::<f64, _>(Open01);
149149
assert!(EPSILON32 < one32 && one32 < EPSILON32 * 2.0);
150150
assert!(EPSILON64 < one64 && one64 < EPSILON64 * 2.0);
151151

152-
let mut max = MockAddRng::new(!0, 0);
152+
let mut max = StepRng::new(!0, 0);
153153
assert_eq!(max.sample::<f32, _>(Open01), 1.0 - EPSILON32 / 2.0);
154154
assert_eq!(max.sample::<f64, _>(Open01), 1.0 - EPSILON64 / 2.0);
155155
}

src/distributions/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -387,7 +387,7 @@ fn ziggurat<R: Rng + ?Sized, P, Z>(
387387
#[cfg(test)]
388388
mod tests {
389389
use Rng;
390-
use mock::MockAddRng;
390+
use mock::StepRng;
391391
use super::{WeightedChoice, Weighted, Distribution};
392392

393393
#[test]
@@ -403,7 +403,7 @@ mod tests {
403403
let wc = WeightedChoice::new(&mut items);
404404
let expected = $expected;
405405

406-
let mut rng = MockAddRng::new(0, 1);
406+
let mut rng = StepRng::new(0, 1);
407407

408408
for &val in expected.iter() {
409409
assert_eq!(wc.sample(&mut rng), val)

src/lib.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1381,7 +1381,7 @@ pub fn sample<T, I, R>(rng: &mut R, iterable: I, amount: usize) -> Vec<T>
13811381

13821382
#[cfg(test)]
13831383
mod test {
1384-
use mock::MockAddRng;
1384+
use mock::StepRng;
13851385
#[cfg(feature="std")]
13861386
use super::{random, thread_rng, EntropyRng};
13871387
use super::{RngCore, Rng, SeedableRng, StdRng};
@@ -1429,7 +1429,7 @@ mod test {
14291429

14301430
#[test]
14311431
fn test_fill_bytes_default() {
1432-
let mut r = MockAddRng::new(0x11_22_33_44_55_66_77_88, 0);
1432+
let mut r = StepRng::new(0x11_22_33_44_55_66_77_88, 0);
14331433

14341434
// check every remainder mod 8, both in small and big vectors.
14351435
let lengths = [0, 1, 2, 3, 4, 5, 6, 7,
@@ -1451,7 +1451,7 @@ mod test {
14511451
#[test]
14521452
fn test_fill() {
14531453
let x = 9041086907909331047; // a random u64
1454-
let mut rng = MockAddRng::new(x, 0);
1454+
let mut rng = StepRng::new(x, 0);
14551455

14561456
// Convert to byte sequence and back to u64; byte-swap twice if BE.
14571457
let mut array = [0u64; 2];

src/mock.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,27 +20,27 @@ use {RngCore, Error, impls};
2020
///
2121
/// ```rust
2222
/// use rand::Rng;
23-
/// use rand::mock::MockAddRng;
23+
/// use rand::mock::StepRng;
2424
///
25-
/// let mut my_rng = MockAddRng::new(2, 1);
25+
/// let mut my_rng = StepRng::new(2, 1);
2626
/// let sample: [u64; 3] = my_rng.gen();
2727
/// assert_eq!(sample, [2, 3, 4]);
2828
/// ```
2929
#[derive(Debug, Clone)]
30-
pub struct MockAddRng {
30+
pub struct StepRng {
3131
v: u64,
3232
a: u64,
3333
}
3434

35-
impl MockAddRng {
36-
/// Create a `MockAddRng`, yielding an arithmetic sequence starting with
35+
impl StepRng {
36+
/// Create a `StepRng`, yielding an arithmetic sequence starting with
3737
/// `initial` and incremented by `increment` each time.
3838
pub fn new(initial: u64, increment: u64) -> Self {
39-
MockAddRng { v: initial, a: increment }
39+
StepRng { v: initial, a: increment }
4040
}
4141
}
4242

43-
impl RngCore for MockAddRng {
43+
impl RngCore for StepRng {
4444
fn next_u32(&mut self) -> u32 {
4545
self.next_u64() as u32
4646
}

src/reseeding.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -183,12 +183,12 @@ impl<R: RngCore + SeedableRng, Rsdr: RngCore> RngCore for ReseedingRng<R, Rsdr>
183183
#[cfg(test)]
184184
mod test {
185185
use {Rng, SeedableRng, StdRng};
186-
use mock::MockAddRng;
186+
use mock::StepRng;
187187
use super::ReseedingRng;
188188

189189
#[test]
190190
fn test_reseeding() {
191-
let mut zero = MockAddRng::new(0, 0);
191+
let mut zero = StepRng::new(0, 0);
192192
let rng = StdRng::from_rng(&mut zero).unwrap();
193193
let mut reseeding = ReseedingRng::new(rng, 32, zero);
194194

@@ -198,7 +198,6 @@ mod test {
198198
let mut buf = [0u8; 32];
199199
reseeding.fill(&mut buf);
200200
let seq = buf;
201-
println!("buf: {:?}", buf);
202201
for _ in 0..10 {
203202
reseeding.fill(&mut buf);
204203
assert_eq!(buf, seq);

0 commit comments

Comments
 (0)