2019-02-07 06:00:42 -06:00
|
|
|
extern crate rand;
|
|
|
|
|
2019-04-16 12:12:56 -05:00
|
|
|
use rand::{SeedableRng, FromEntropy, Rng, rngs::SmallRng};
|
2019-02-07 06:00:42 -06:00
|
|
|
|
2017-01-24 10:55:42 -06:00
|
|
|
#[test]
|
2019-02-07 06:00:42 -06:00
|
|
|
fn simple() {
|
2017-01-24 10:55:42 -06:00
|
|
|
assert_eq!(4, 4);
|
|
|
|
}
|
2018-11-27 08:06:51 -06:00
|
|
|
|
|
|
|
// 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]
|
2019-02-07 06:00:42 -06:00
|
|
|
fn 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);
|
2018-11-27 08:06:51 -06:00
|
|
|
}
|
2018-12-19 04:11:01 -06:00
|
|
|
|
2019-04-16 12:12:56 -05:00
|
|
|
#[test]
|
|
|
|
#[cfg(not(target_os="macos"))] // FIXME entropy does not work on macOS
|
|
|
|
fn seeded_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>();
|
2019-04-16 12:49:36 -05:00
|
|
|
|
|
|
|
// Also try per-thread RNG.
|
|
|
|
let mut rng = rand::thread_rng();
|
|
|
|
let _val = rng.gen::<i32>();
|
2019-04-16 12:12:56 -05:00
|
|
|
}
|
|
|
|
|
2018-12-19 04:11:01 -06:00
|
|
|
// A test that won't work on miri
|
2019-02-07 06:00:42 -06:00
|
|
|
#[cfg(not(miri))]
|
2018-12-19 04:11:01 -06:00
|
|
|
#[test]
|
|
|
|
fn does_not_work_on_miri() {
|
|
|
|
let x = 0u8;
|
|
|
|
assert!(&x as *const _ as usize % 4 < 4);
|
|
|
|
}
|