Skip to content

Commit df99531

Browse files
bjorn3gitbot
authored and
gitbot
committed
Move std float unit tests to integration tests
1 parent cb75c03 commit df99531

File tree

12 files changed

+59
-71
lines changed

12 files changed

+59
-71
lines changed

std/Cargo.toml

+4
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,10 @@ name = "pipe-subprocess"
130130
path = "tests/pipe_subprocess.rs"
131131
harness = false
132132

133+
[[test]]
134+
name = "floats"
135+
path = "tests/floats/lib.rs"
136+
133137
[[bench]]
134138
name = "stdbenches"
135139
path = "benches/lib.rs"

std/src/f128.rs

-3
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,6 @@
44
//!
55
//! Mathematically significant numbers are provided in the `consts` sub-module.
66
7-
#[cfg(test)]
8-
mod tests;
9-
107
#[unstable(feature = "f128", issue = "116909")]
118
pub use core::f128::consts;
129

std/src/f16.rs

-3
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,6 @@
44
//!
55
//! Mathematically significant numbers are provided in the `consts` sub-module.
66
7-
#[cfg(test)]
8-
mod tests;
9-
107
#[unstable(feature = "f16", issue = "116909")]
118
pub use core::f16::consts;
129

std/src/f32.rs

-3
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,6 @@
1212
#![stable(feature = "rust1", since = "1.0.0")]
1313
#![allow(missing_docs)]
1414

15-
#[cfg(test)]
16-
mod tests;
17-
1815
#[stable(feature = "rust1", since = "1.0.0")]
1916
#[allow(deprecated, deprecated_in_future)]
2017
pub use core::f32::{

std/src/f64.rs

-3
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,6 @@
1212
#![stable(feature = "rust1", since = "1.0.0")]
1313
#![allow(missing_docs)]
1414

15-
#[cfg(test)]
16-
mod tests;
17-
1815
#[stable(feature = "rust1", since = "1.0.0")]
1916
#[allow(deprecated, deprecated_in_future)]
2017
pub use core::f64::{

std/src/macros.rs

-15
Original file line numberDiff line numberDiff line change
@@ -372,18 +372,3 @@ macro_rules! dbg {
372372
($($crate::dbg!($val)),+,)
373373
};
374374
}
375-
376-
/// Verify that floats are within a tolerance of each other, 1.0e-6 by default.
377-
#[cfg(test)]
378-
macro_rules! assert_approx_eq {
379-
($a:expr, $b:expr) => {{ assert_approx_eq!($a, $b, 1.0e-6) }};
380-
($a:expr, $b:expr, $lim:expr) => {{
381-
let (a, b) = (&$a, &$b);
382-
let diff = (*a - *b).abs();
383-
assert!(
384-
diff < $lim,
385-
"{a:?} is not approximately equal to {b:?} (threshold {lim:?}, difference {diff:?})",
386-
lim = $lim
387-
);
388-
}};
389-
}

std/src/num.rs

-25
Original file line numberDiff line numberDiff line change
@@ -29,28 +29,3 @@ pub use core::num::{FpCategory, ParseFloatError, ParseIntError, TryFromIntError}
2929
pub use core::num::{NonZeroI8, NonZeroI16, NonZeroI32, NonZeroI64, NonZeroI128, NonZeroIsize};
3030
#[stable(feature = "nonzero", since = "1.28.0")]
3131
pub use core::num::{NonZeroU8, NonZeroU16, NonZeroU32, NonZeroU64, NonZeroU128, NonZeroUsize};
32-
33-
#[cfg(test)]
34-
use crate::fmt;
35-
#[cfg(test)]
36-
use crate::ops::{Add, Div, Mul, Rem, Sub};
37-
38-
/// Helper function for testing numeric operations
39-
#[cfg(test)]
40-
pub fn test_num<T>(ten: T, two: T)
41-
where
42-
T: PartialEq
43-
+ Add<Output = T>
44-
+ Sub<Output = T>
45-
+ Mul<Output = T>
46-
+ Div<Output = T>
47-
+ Rem<Output = T>
48-
+ fmt::Debug
49-
+ Copy,
50-
{
51-
assert_eq!(ten.add(two), ten + two);
52-
assert_eq!(ten.sub(two), ten - two);
53-
assert_eq!(ten.mul(two), ten * two);
54-
assert_eq!(ten.div(two), ten / two);
55-
assert_eq!(ten.rem(two), ten % two);
56-
}

std/src/f128/tests.rs renamed to std/tests/floats/f128.rs

+4-6
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
// FIXME(f16_f128): only tested on platforms that have symbols and aren't buggy
22
#![cfg(reliable_f128)]
33

4-
use crate::f128::consts;
5-
use crate::num::FpCategory as Fp;
4+
use std::f128::consts;
5+
use std::num::FpCategory as Fp;
66
#[cfg(reliable_f128_math)]
7-
use crate::ops::Rem;
8-
use crate::ops::{Add, Div, Mul, Sub};
7+
use std::ops::Rem;
8+
use std::ops::{Add, Div, Mul, Sub};
99

1010
// Note these tolerances make sense around zero, but not for more extreme exponents.
1111

@@ -762,8 +762,6 @@ fn test_ln_gamma() {
762762

763763
#[test]
764764
fn test_real_consts() {
765-
use super::consts;
766-
767765
let pi: f128 = consts::PI;
768766
let frac_pi_2: f128 = consts::FRAC_PI_2;
769767
let frac_pi_3: f128 = consts::FRAC_PI_3;

std/src/f16/tests.rs renamed to std/tests/floats/f16.rs

+3-4
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
// FIXME(f16_f128): only tested on platforms that have symbols and aren't buggy
22
#![cfg(reliable_f16)]
33

4-
use crate::f16::consts;
5-
use crate::num::{FpCategory as Fp, *};
4+
use std::f16::consts;
5+
use std::num::FpCategory as Fp;
66

77
/// Tolerance for results on the order of 10.0e-2
88
#[allow(unused)]
@@ -54,7 +54,7 @@ macro_rules! assert_f16_biteq {
5454

5555
#[test]
5656
fn test_num_f16() {
57-
test_num(10f16, 2f16);
57+
crate::test_num(10f16, 2f16);
5858
}
5959

6060
#[test]
@@ -734,7 +734,6 @@ fn test_ln_gamma() {
734734
#[test]
735735
fn test_real_consts() {
736736
// FIXME(f16_f128): add math tests when available
737-
use super::consts;
738737

739738
let pi: f16 = consts::PI;
740739
let frac_pi_2: f16 = consts::FRAC_PI_2;

std/src/f32/tests.rs renamed to std/tests/floats/f32.rs

+3-5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
use crate::f32::consts;
2-
use crate::num::{FpCategory as Fp, *};
1+
use std::f32::consts;
2+
use std::num::FpCategory as Fp;
33

44
/// Smallest number
55
const TINY_BITS: u32 = 0x1;
@@ -35,7 +35,7 @@ macro_rules! assert_f32_biteq {
3535

3636
#[test]
3737
fn test_num_f32() {
38-
test_num(10f32, 2f32);
38+
crate::test_num(10f32, 2f32);
3939
}
4040

4141
#[test]
@@ -700,8 +700,6 @@ fn test_ln_gamma() {
700700

701701
#[test]
702702
fn test_real_consts() {
703-
use super::consts;
704-
705703
let pi: f32 = consts::PI;
706704
let frac_pi_2: f32 = consts::FRAC_PI_2;
707705
let frac_pi_3: f32 = consts::FRAC_PI_3;

std/src/f64/tests.rs renamed to std/tests/floats/f64.rs

+3-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
use crate::f64::consts;
2-
use crate::num::{FpCategory as Fp, *};
1+
use std::f64::consts;
2+
use std::num::FpCategory as Fp;
33

44
/// Smallest number
55
const TINY_BITS: u64 = 0x1;
@@ -35,7 +35,7 @@ macro_rules! assert_f64_biteq {
3535

3636
#[test]
3737
fn test_num_f64() {
38-
test_num(10f64, 2f64);
38+
crate::test_num(10f64, 2f64);
3939
}
4040

4141
#[test]
@@ -680,7 +680,6 @@ fn test_ln_gamma() {
680680

681681
#[test]
682682
fn test_real_consts() {
683-
use super::consts;
684683
let pi: f64 = consts::PI;
685684
let frac_pi_2: f64 = consts::FRAC_PI_2;
686685
let frac_pi_3: f64 = consts::FRAC_PI_3;

std/tests/floats/lib.rs

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
#![feature(f16, f128, float_gamma, float_next_up_down, float_minimum_maximum)]
2+
3+
use std::fmt;
4+
use std::ops::{Add, Div, Mul, Rem, Sub};
5+
6+
/// Verify that floats are within a tolerance of each other, 1.0e-6 by default.
7+
macro_rules! assert_approx_eq {
8+
($a:expr, $b:expr) => {{ assert_approx_eq!($a, $b, 1.0e-6) }};
9+
($a:expr, $b:expr, $lim:expr) => {{
10+
let (a, b) = (&$a, &$b);
11+
let diff = (*a - *b).abs();
12+
assert!(
13+
diff < $lim,
14+
"{a:?} is not approximately equal to {b:?} (threshold {lim:?}, difference {diff:?})",
15+
lim = $lim
16+
);
17+
}};
18+
}
19+
20+
/// Helper function for testing numeric operations
21+
pub fn test_num<T>(ten: T, two: T)
22+
where
23+
T: PartialEq
24+
+ Add<Output = T>
25+
+ Sub<Output = T>
26+
+ Mul<Output = T>
27+
+ Div<Output = T>
28+
+ Rem<Output = T>
29+
+ fmt::Debug
30+
+ Copy,
31+
{
32+
assert_eq!(ten.add(two), ten + two);
33+
assert_eq!(ten.sub(two), ten - two);
34+
assert_eq!(ten.mul(two), ten * two);
35+
assert_eq!(ten.div(two), ten / two);
36+
assert_eq!(ten.rem(two), ten % two);
37+
}
38+
39+
mod f128;
40+
mod f16;
41+
mod f32;
42+
mod f64;

0 commit comments

Comments
 (0)