[go: up one dir, main page]

randomize 3.0.1

randomization routines
Documentation
#![allow(clippy::float_cmp)]

use randomize::formulas::*;

// //
// u32
// //

#[test]
#[ignore]
fn test_f32_half_open_right() {
  for u in 0..=core::u32::MAX {
    let f: f32 = f32_half_open_right(u);
    assert!(f >= 0.0);
    assert!(f < 1.0);
  }
  assert_eq!(f32_half_open_right(0), 0.0);
}

#[test]
#[ignore]
fn test_f32_half_open_left() {
  for u in 0..=core::u32::MAX {
    let f: f32 = f32_half_open_left(u);
    assert!(f > 0.0);
    assert!(f <= 1.0);
  }
  assert_eq!(f32_half_open_left(core::u32::MAX), 1.0);
}

#[test]
#[ignore]
fn test_f32_open() {
  for u in 0..=core::u32::MAX {
    let f: f32 = f32_open(u);
    assert!(f > 0.0);
    assert!(f < 1.0);
  }
}

#[test]
#[ignore]
fn test_f32_closed() {
  for u in 0..=core::u32::MAX {
    let f: f32 = f32_closed(u);
    assert!(f >= 0.0);
    assert!(f <= 1.0);
  }
  assert_eq!(f32_closed(0), 0.0);
  assert_eq!(f32_closed(core::u32::MAX), 1.0);
}

#[test]
#[ignore]
fn test_f32_closed_neg_pos() {
  for u in 0..=core::u32::MAX {
    let f: f32 = f32_closed_neg_pos(u);
    assert!(f >= -1.0);
    assert!(f <= 1.0);
  }
  assert_eq!(f32_closed_neg_pos(0), -1.0);
  assert_eq!(f32_closed_neg_pos(core::u32::MAX), 1.0);
}

// //
// u64
// //

#[test]
#[ignore]
fn test_f64_half_open_right() {
  for u in 0..=core::u32::MAX {
    let u: u64 = lcg64(u64::from(u), PCG_MULTIPLIER_64, DEFAULT_PCG_INC as u64);
    let f: f64 = f64_half_open_right(u);
    assert!(f >= 0.0);
    assert!(f < 1.0);
  }
  assert_eq!(f64_half_open_right(0), 0.0);
}

#[test]
#[ignore]
fn test_f64_half_open_left() {
  for u in 0..=core::u32::MAX {
    let u: u64 = lcg64(u64::from(u), PCG_MULTIPLIER_64, DEFAULT_PCG_INC as u64);
    let f: f64 = f64_half_open_left(u);
    assert!(f > 0.0);
    assert!(f <= 1.0);
  }
  assert_eq!(f64_half_open_left(core::u64::MAX), 1.0);
}

#[test]
#[ignore]
fn test_f64_open() {
  for u in 0..=core::u32::MAX {
    let u: u64 = lcg64(u64::from(u), PCG_MULTIPLIER_64, DEFAULT_PCG_INC as u64);
    let f: f64 = f64_open(u);
    assert!(f > 0.0);
    assert!(f < 1.0);
  }
}

#[test]
#[ignore]
fn test_f64_closed() {
  for u in 0..=core::u32::MAX {
    let u: u64 = lcg64(u64::from(u), PCG_MULTIPLIER_64, DEFAULT_PCG_INC as u64);
    let f: f64 = f64_closed(u);
    assert!(f >= 0.0);
    assert!(f <= 1.0);
  }
  assert_eq!(f64_closed(0), 0.0);
  assert_eq!(f64_closed(core::u64::MAX), 1.0);
}

#[test]
#[ignore]
fn test_f64_closed_neg_pos() {
  for u in 0..=core::u32::MAX {
    let u: u64 = lcg64(u64::from(u), PCG_MULTIPLIER_64, DEFAULT_PCG_INC as u64);
    let f: f64 = f64_closed_neg_pos(u);
    assert!(f >= -1.0);
    assert!(f <= 1.0);
  }
  assert_eq!(f64_closed_neg_pos(0), -1.0);
  assert_eq!(f64_closed_neg_pos(core::u64::MAX), 1.0);
}