smoke.rs 2.4 KB

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