1 #[cfg(all(target_family = "wasm", not(target_os = "wasi")))] 2 use wasm_bindgen_test::wasm_bindgen_test as test; 3 4 #[cfg(all(target_family = "wasm", not(target_os = "wasi")))] 5 wasm_bindgen_test::wasm_bindgen_test_configure!(run_in_browser); 6 7 #[test] bool()8fn bool() { 9 for x in &[false, true] { 10 while fastrand::bool() != *x {} 11 } 12 } 13 14 #[test] u8()15fn u8() { 16 for x in 0..10 { 17 while fastrand::u8(..10) != x {} 18 } 19 20 for x in 200..=u8::MAX { 21 while fastrand::u8(200..) != x {} 22 } 23 } 24 25 #[test] i8()26fn i8() { 27 for x in -128..-120 { 28 while fastrand::i8(..-120) != x {} 29 } 30 31 for x in 120..=127 { 32 while fastrand::i8(120..) != x {} 33 } 34 } 35 36 #[test] u32()37fn u32() { 38 for n in 1u32..10_000 { 39 let n = n.wrapping_mul(n); 40 let n = n.wrapping_mul(n); 41 if n != 0 { 42 for _ in 0..1000 { 43 assert!(fastrand::u32(..n) < n); 44 } 45 } 46 } 47 } 48 49 #[test] u64()50fn u64() { 51 for n in 1u64..10_000 { 52 let n = n.wrapping_mul(n); 53 let n = n.wrapping_mul(n); 54 let n = n.wrapping_mul(n); 55 if n != 0 { 56 for _ in 0..1000 { 57 assert!(fastrand::u64(..n) < n); 58 } 59 } 60 } 61 } 62 63 #[test] u128()64fn u128() { 65 for n in 1u128..10_000 { 66 let n = n.wrapping_mul(n); 67 let n = n.wrapping_mul(n); 68 let n = n.wrapping_mul(n); 69 let n = n.wrapping_mul(n); 70 if n != 0 { 71 for _ in 0..1000 { 72 assert!(fastrand::u128(..n) < n); 73 } 74 } 75 } 76 } 77 78 #[test] fill()79fn fill() { 80 let r = fastrand::Rng::new(); 81 let mut a = [0u8; 64]; 82 let mut b = [0u8; 64]; 83 84 r.fill(&mut a); 85 r.fill(&mut b); 86 87 assert_ne!(a, b); 88 } 89 90 #[test] rng()91fn rng() { 92 let r = fastrand::Rng::new(); 93 94 assert_ne!(r.u64(..), r.u64(..)); 95 96 r.seed(7); 97 let a = r.u64(..); 98 r.seed(7); 99 let b = r.u64(..); 100 assert_eq!(a, b); 101 } 102 103 #[test] rng_init()104fn rng_init() { 105 let a = fastrand::Rng::new(); 106 let b = fastrand::Rng::new(); 107 assert_ne!(a.u64(..), b.u64(..)); 108 109 a.seed(7); 110 b.seed(7); 111 assert_eq!(a.u64(..), b.u64(..)); 112 } 113 114 #[test] with_seed()115fn with_seed() { 116 let a = fastrand::Rng::with_seed(7); 117 let b = fastrand::Rng::new(); 118 b.seed(7); 119 assert_eq!(a.u64(..), b.u64(..)); 120 } 121