Skip to content

Commit

Permalink
Fix benchmarks and no_std
Browse files Browse the repository at this point in the history
  • Loading branch information
pitdicker committed Jan 14, 2018
1 parent 14f27db commit 449cb38
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 23 deletions.
2 changes: 1 addition & 1 deletion benches/bench.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ mod distributions;

use std::mem::size_of;
use test::{black_box, Bencher};
use rand::{StdRng, Rng};
use rand::{StdRng, Rng, NewSeeded};

#[bench]
fn rand_f32(b: &mut Bencher) {
Expand Down
2 changes: 1 addition & 1 deletion benches/generators.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const BYTES_LEN: usize = 1024;
use std::mem::size_of;
use test::{black_box, Bencher};

use rand::{Rng, StdRng, OsRng, JitterRng};
use rand::{Rng, NewSeeded, StdRng, OsRng, JitterRng};
use rand::{XorShiftRng, Hc128Rng, IsaacRng, Isaac64Rng, ChaChaRng};

macro_rules! gen_bytes {
Expand Down
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ use prng::Isaac64Rng as IsaacWordRng;

use distributions::{Range, IndependentSample};
use distributions::range::SampleRange;
use reseeding::{ReseedingRng, ReseedWithNew};
#[cfg(feature="std")]use reseeding::{ReseedingRng, ReseedWithNew};

// public modules
pub mod distributions;
Expand Down
32 changes: 12 additions & 20 deletions src/reseeding.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,9 +108,8 @@ impl<R: Rng + NewSeeded> Reseeder<R> for ReseedWithNew {
#[cfg(test)]
mod test {
use {impls, le};
use core::default::Default;
use super::{ReseedingRng, ReseedWithNew};
use {SeedableRng, Rng};
use super::{ReseedingRng, Reseeder};
use {SeedableRng, Rng, Error};

struct Counter {
i: u32
Expand All @@ -130,11 +129,6 @@ mod test {
impls::fill_bytes_via_u64(self, dest)
}
}
impl Default for Counter {
fn default() -> Counter {
Counter { i: 0 }
}
}
impl SeedableRng for Counter {
type Seed = [u8; 4];
fn from_seed(seed: Self::Seed) -> Self {
Expand All @@ -144,25 +138,23 @@ mod test {
}
}

#[derive(Debug, Clone)]
struct ReseedCounter;
impl Reseeder<Counter> for ReseedCounter {
fn reseed(&mut self, rng: &mut Counter) -> Result<(), Error> {
*rng = Counter { i: 0 };
Ok(())
}
}

#[test]
fn test_reseeding() {
let mut rs = ReseedingRng::new(Counter {i:0}, 400, ReseedWithNew);
let mut rs = ReseedingRng::new(Counter {i:0}, 400, ReseedCounter);

let mut i = 0;
for _ in 0..1000 {
assert_eq!(rs.next_u32(), i % 100);
i += 1;
}
}

const FILL_BYTES_V_LEN: usize = 13579;
#[test]
fn test_rng_fill_bytes() {
let mut v = [0u8; FILL_BYTES_V_LEN];
::test::rng(321).fill_bytes(&mut v);

// To test that `fill_bytes` actually did something, check that not all
// bytes are zero.
assert!(!v.iter().all(|&x| x == 0));
}
}

0 comments on commit 449cb38

Please sign in to comment.