1
Fork 0

Move std float unit tests to integration tests

This commit is contained in:
bjorn3 2025-01-17 09:36:11 +00:00
parent 03d44a641b
commit 29166cd617
12 changed files with 59 additions and 71 deletions

View file

@ -130,6 +130,10 @@ name = "pipe-subprocess"
path = "tests/pipe_subprocess.rs" path = "tests/pipe_subprocess.rs"
harness = false harness = false
[[test]]
name = "floats"
path = "tests/floats/lib.rs"
[[bench]] [[bench]]
name = "stdbenches" name = "stdbenches"
path = "benches/lib.rs" path = "benches/lib.rs"

View file

@ -4,9 +4,6 @@
//! //!
//! Mathematically significant numbers are provided in the `consts` sub-module. //! Mathematically significant numbers are provided in the `consts` sub-module.
#[cfg(test)]
mod tests;
#[unstable(feature = "f128", issue = "116909")] #[unstable(feature = "f128", issue = "116909")]
pub use core::f128::consts; pub use core::f128::consts;

View file

@ -4,9 +4,6 @@
//! //!
//! Mathematically significant numbers are provided in the `consts` sub-module. //! Mathematically significant numbers are provided in the `consts` sub-module.
#[cfg(test)]
mod tests;
#[unstable(feature = "f16", issue = "116909")] #[unstable(feature = "f16", issue = "116909")]
pub use core::f16::consts; pub use core::f16::consts;

View file

@ -12,9 +12,6 @@
#![stable(feature = "rust1", since = "1.0.0")] #![stable(feature = "rust1", since = "1.0.0")]
#![allow(missing_docs)] #![allow(missing_docs)]
#[cfg(test)]
mod tests;
#[stable(feature = "rust1", since = "1.0.0")] #[stable(feature = "rust1", since = "1.0.0")]
#[allow(deprecated, deprecated_in_future)] #[allow(deprecated, deprecated_in_future)]
pub use core::f32::{ pub use core::f32::{

View file

@ -12,9 +12,6 @@
#![stable(feature = "rust1", since = "1.0.0")] #![stable(feature = "rust1", since = "1.0.0")]
#![allow(missing_docs)] #![allow(missing_docs)]
#[cfg(test)]
mod tests;
#[stable(feature = "rust1", since = "1.0.0")] #[stable(feature = "rust1", since = "1.0.0")]
#[allow(deprecated, deprecated_in_future)] #[allow(deprecated, deprecated_in_future)]
pub use core::f64::{ pub use core::f64::{

View file

@ -372,18 +372,3 @@ macro_rules! dbg {
($($crate::dbg!($val)),+,) ($($crate::dbg!($val)),+,)
}; };
} }
/// Verify that floats are within a tolerance of each other, 1.0e-6 by default.
#[cfg(test)]
macro_rules! assert_approx_eq {
($a:expr, $b:expr) => {{ assert_approx_eq!($a, $b, 1.0e-6) }};
($a:expr, $b:expr, $lim:expr) => {{
let (a, b) = (&$a, &$b);
let diff = (*a - *b).abs();
assert!(
diff < $lim,
"{a:?} is not approximately equal to {b:?} (threshold {lim:?}, difference {diff:?})",
lim = $lim
);
}};
}

View file

@ -29,28 +29,3 @@ pub use core::num::{FpCategory, ParseFloatError, ParseIntError, TryFromIntError}
pub use core::num::{NonZeroI8, NonZeroI16, NonZeroI32, NonZeroI64, NonZeroI128, NonZeroIsize}; pub use core::num::{NonZeroI8, NonZeroI16, NonZeroI32, NonZeroI64, NonZeroI128, NonZeroIsize};
#[stable(feature = "nonzero", since = "1.28.0")] #[stable(feature = "nonzero", since = "1.28.0")]
pub use core::num::{NonZeroU8, NonZeroU16, NonZeroU32, NonZeroU64, NonZeroU128, NonZeroUsize}; pub use core::num::{NonZeroU8, NonZeroU16, NonZeroU32, NonZeroU64, NonZeroU128, NonZeroUsize};
#[cfg(test)]
use crate::fmt;
#[cfg(test)]
use crate::ops::{Add, Div, Mul, Rem, Sub};
/// Helper function for testing numeric operations
#[cfg(test)]
pub fn test_num<T>(ten: T, two: T)
where
T: PartialEq
+ Add<Output = T>
+ Sub<Output = T>
+ Mul<Output = T>
+ Div<Output = T>
+ Rem<Output = T>
+ fmt::Debug
+ Copy,
{
assert_eq!(ten.add(two), ten + two);
assert_eq!(ten.sub(two), ten - two);
assert_eq!(ten.mul(two), ten * two);
assert_eq!(ten.div(two), ten / two);
assert_eq!(ten.rem(two), ten % two);
}

View file

@ -1,11 +1,11 @@
// FIXME(f16_f128): only tested on platforms that have symbols and aren't buggy // FIXME(f16_f128): only tested on platforms that have symbols and aren't buggy
#![cfg(reliable_f128)] #![cfg(reliable_f128)]
use crate::f128::consts; use std::f128::consts;
use crate::num::FpCategory as Fp; use std::num::FpCategory as Fp;
#[cfg(reliable_f128_math)] #[cfg(reliable_f128_math)]
use crate::ops::Rem; use std::ops::Rem;
use crate::ops::{Add, Div, Mul, Sub}; use std::ops::{Add, Div, Mul, Sub};
// Note these tolerances make sense around zero, but not for more extreme exponents. // Note these tolerances make sense around zero, but not for more extreme exponents.
@ -762,8 +762,6 @@ fn test_ln_gamma() {
#[test] #[test]
fn test_real_consts() { fn test_real_consts() {
use super::consts;
let pi: f128 = consts::PI; let pi: f128 = consts::PI;
let frac_pi_2: f128 = consts::FRAC_PI_2; let frac_pi_2: f128 = consts::FRAC_PI_2;
let frac_pi_3: f128 = consts::FRAC_PI_3; let frac_pi_3: f128 = consts::FRAC_PI_3;

View file

@ -1,8 +1,8 @@
// FIXME(f16_f128): only tested on platforms that have symbols and aren't buggy // FIXME(f16_f128): only tested on platforms that have symbols and aren't buggy
#![cfg(reliable_f16)] #![cfg(reliable_f16)]
use crate::f16::consts; use std::f16::consts;
use crate::num::{FpCategory as Fp, *}; use std::num::FpCategory as Fp;
/// Tolerance for results on the order of 10.0e-2 /// Tolerance for results on the order of 10.0e-2
#[allow(unused)] #[allow(unused)]
@ -54,7 +54,7 @@ macro_rules! assert_f16_biteq {
#[test] #[test]
fn test_num_f16() { fn test_num_f16() {
test_num(10f16, 2f16); crate::test_num(10f16, 2f16);
} }
#[test] #[test]
@ -734,7 +734,6 @@ fn test_ln_gamma() {
#[test] #[test]
fn test_real_consts() { fn test_real_consts() {
// FIXME(f16_f128): add math tests when available // FIXME(f16_f128): add math tests when available
use super::consts;
let pi: f16 = consts::PI; let pi: f16 = consts::PI;
let frac_pi_2: f16 = consts::FRAC_PI_2; let frac_pi_2: f16 = consts::FRAC_PI_2;

View file

@ -1,5 +1,5 @@
use crate::f32::consts; use std::f32::consts;
use crate::num::{FpCategory as Fp, *}; use std::num::FpCategory as Fp;
/// Smallest number /// Smallest number
const TINY_BITS: u32 = 0x1; const TINY_BITS: u32 = 0x1;
@ -35,7 +35,7 @@ macro_rules! assert_f32_biteq {
#[test] #[test]
fn test_num_f32() { fn test_num_f32() {
test_num(10f32, 2f32); crate::test_num(10f32, 2f32);
} }
#[test] #[test]
@ -700,8 +700,6 @@ fn test_ln_gamma() {
#[test] #[test]
fn test_real_consts() { fn test_real_consts() {
use super::consts;
let pi: f32 = consts::PI; let pi: f32 = consts::PI;
let frac_pi_2: f32 = consts::FRAC_PI_2; let frac_pi_2: f32 = consts::FRAC_PI_2;
let frac_pi_3: f32 = consts::FRAC_PI_3; let frac_pi_3: f32 = consts::FRAC_PI_3;

View file

@ -1,5 +1,5 @@
use crate::f64::consts; use std::f64::consts;
use crate::num::{FpCategory as Fp, *}; use std::num::FpCategory as Fp;
/// Smallest number /// Smallest number
const TINY_BITS: u64 = 0x1; const TINY_BITS: u64 = 0x1;
@ -35,7 +35,7 @@ macro_rules! assert_f64_biteq {
#[test] #[test]
fn test_num_f64() { fn test_num_f64() {
test_num(10f64, 2f64); crate::test_num(10f64, 2f64);
} }
#[test] #[test]
@ -680,7 +680,6 @@ fn test_ln_gamma() {
#[test] #[test]
fn test_real_consts() { fn test_real_consts() {
use super::consts;
let pi: f64 = consts::PI; let pi: f64 = consts::PI;
let frac_pi_2: f64 = consts::FRAC_PI_2; let frac_pi_2: f64 = consts::FRAC_PI_2;
let frac_pi_3: f64 = consts::FRAC_PI_3; let frac_pi_3: f64 = consts::FRAC_PI_3;

View file

@ -0,0 +1,42 @@
#![feature(f16, f128, float_gamma, float_next_up_down, float_minimum_maximum)]
use std::fmt;
use std::ops::{Add, Div, Mul, Rem, Sub};
/// Verify that floats are within a tolerance of each other, 1.0e-6 by default.
macro_rules! assert_approx_eq {
($a:expr, $b:expr) => {{ assert_approx_eq!($a, $b, 1.0e-6) }};
($a:expr, $b:expr, $lim:expr) => {{
let (a, b) = (&$a, &$b);
let diff = (*a - *b).abs();
assert!(
diff < $lim,
"{a:?} is not approximately equal to {b:?} (threshold {lim:?}, difference {diff:?})",
lim = $lim
);
}};
}
/// Helper function for testing numeric operations
pub fn test_num<T>(ten: T, two: T)
where
T: PartialEq
+ Add<Output = T>
+ Sub<Output = T>
+ Mul<Output = T>
+ Div<Output = T>
+ Rem<Output = T>
+ fmt::Debug
+ Copy,
{
assert_eq!(ten.add(two), ten + two);
assert_eq!(ten.sub(two), ten - two);
assert_eq!(ten.mul(two), ten * two);
assert_eq!(ten.div(two), ten / two);
assert_eq!(ten.rem(two), ten % two);
}
mod f128;
mod f16;
mod f32;
mod f64;