Skip to content

Commit

Permalink
test rand a bit more
Browse files Browse the repository at this point in the history
  • Loading branch information
RalfJung committed Apr 19, 2019
1 parent f26c2cb commit 7ebf417
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions test-cargo-miri/tests/test.rs
@@ -1,8 +1,4 @@
#![allow(unused_imports)] // FIXME for macOS

extern crate rand;

use rand::{SeedableRng, FromEntropy, Rng, rngs::SmallRng};
use rand::{Rng, SeedableRng};

#[test]
fn simple() {
Expand All @@ -15,22 +11,30 @@ fn simple() {
fn fixed_rng() {
let mut rng = rand::rngs::StdRng::seed_from_u64(0xdeadcafe);
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);
}

#[test]
fn entropy_rng() {
#[cfg(not(target_os="macos"))] // FIXME entropy does not work on macOS
// (Not disabling the entire test as that would change the output.)
{
use rand::{FromEntropy, rngs::SmallRng};

// 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>();
}
}

Expand Down

0 comments on commit 7ebf417

Please sign in to comment.