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