Skip to content

Commit

Permalink
Test reseeding without allocating
Browse files Browse the repository at this point in the history
  • Loading branch information
pitdicker committed Jan 8, 2018
1 parent f895b2c commit 9785074
Showing 1 changed file with 9 additions and 12 deletions.
21 changes: 9 additions & 12 deletions src/reseeding.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,8 +148,7 @@ impl Default for ReseedWithDefault {
#[cfg(test)]
mod test {
use impls;
use std::default::Default;
use std::iter::repeat;
use core::default::Default;
use super::{ReseedingRng, ReseedWithDefault};
use {SeedableRng, Rng};

Expand Down Expand Up @@ -207,25 +206,23 @@ mod test {

#[test]
fn test_rng_reseed() {
let mut r: MyRng = SeedableRng::from_seed((ReseedWithDefault, 3));
let string1: String = r.gen_ascii_chars().take(100).collect();
let mut rng: MyRng = SeedableRng::from_seed((ReseedWithDefault, 3));
let mut results1 = [0u32; 32];
for i in results1.iter_mut() { *i = rng.next_u32(); }

r.reseed((ReseedWithDefault, 3));
rng.reseed((ReseedWithDefault, 3));

let string2: String = r.gen_ascii_chars().take(100).collect();
assert_eq!(string1, string2);
let mut results2 = [0u32; 32];
for i in results2.iter_mut() { *i = rng.next_u32(); }
assert_eq!(results1, results2);
}

const FILL_BYTES_V_LEN: usize = 13579;
#[test]
fn test_rng_fill_bytes() {
let mut v = repeat(0u8).take(FILL_BYTES_V_LEN).collect::<Vec<_>>();
let mut v = [0u8; FILL_BYTES_V_LEN];
::test::rng().fill_bytes(&mut v);

// Sanity test: if we've gotten here, `fill_bytes` has not infinitely
// recursed.
assert_eq!(v.len(), FILL_BYTES_V_LEN);

// To test that `fill_bytes` actually did something, check that the
// average of `v` is not 0.
let mut sum = 0.0;
Expand Down

0 comments on commit 9785074

Please sign in to comment.