test rand a bit more

This commit is contained in:
Ralf Jung 2019-06-12 18:19:50 +02:00
parent deb0ff46eb
commit 8f670e6b8b
2 changed files with 8 additions and 4 deletions

View file

@ -19,7 +19,9 @@ mod test {
fn rng() {
let mut rng = rand::rngs::StdRng::seed_from_u64(0xcafebeef);
let x: u32 = rng.gen();
let y: u32 = rng.gen();
assert_ne!(x, y);
let y: usize = rng.gen();
let z: u128 = rng.gen();
assert_ne!(x as usize, y);
assert_ne!(y as u128, z);
}
}

View file

@ -7,17 +7,19 @@ fn simple() {
assert_eq!(4, 4);
}
// Having more than 1 test does seem to make a difference
// (i.e., this calls ptr::swap which having just one test does not).
#[test]
fn entropy_rng() {
// Use this opportunity to test querying the RNG (needs an external crate, hence tested here and not in the compiletest suite)
let mut rng = SmallRng::from_entropy();
let _val = rng.gen::<i32>();
let _val = rng.gen::<isize>();
let _val = rng.gen::<i128>();
// Also try per-thread RNG.
let mut rng = rand::thread_rng();
let _val = rng.gen::<i32>();
let _val = rng.gen::<isize>();
let _val = rng.gen::<i128>();
}
// A test that won't work on miri