mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-22 14:55:26 +00:00
add tests for div_duration_* functions
This commit is contained in:
parent
a2112fcb0a
commit
9fd744b3e3
@ -173,6 +173,32 @@ fn div() {
|
||||
assert_eq!(Duration::new(99, 999_999_000) / 100, Duration::new(0, 999_999_990));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn div_duration_f32() {
|
||||
assert_eq!(Duration::ZERO.div_duration_f32(Duration::MAX), 0.0);
|
||||
assert_eq!(Duration::MAX.div_duration_f32(Duration::ZERO), f32::INFINITY);
|
||||
assert_eq!((Duration::SECOND * 2).div_duration_f32(Duration::SECOND), 2.0);
|
||||
assert!(Duration::ZERO.div_duration_f32(Duration::ZERO).is_nan());
|
||||
// These tests demonstrate it doesn't panic with extreme values.
|
||||
// Accuracy of the computed value is not a huge concern, we know floats don't work well
|
||||
// at these extremes.
|
||||
assert!((Duration::MAX).div_duration_f32(Duration::NANOSECOND) > 10.0f32.powf(28.0));
|
||||
assert!((Duration::NANOSECOND).div_duration_f32(Duration::MAX) < 0.1);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn div_duration_f64() {
|
||||
assert_eq!(Duration::ZERO.div_duration_f64(Duration::MAX), 0.0);
|
||||
assert_eq!(Duration::MAX.div_duration_f64(Duration::ZERO), f64::INFINITY);
|
||||
assert_eq!((Duration::SECOND * 2).div_duration_f64(Duration::SECOND), 2.0);
|
||||
assert!(Duration::ZERO.div_duration_f64(Duration::ZERO).is_nan());
|
||||
// These tests demonstrate it doesn't panic with extreme values.
|
||||
// Accuracy of the computed value is not a huge concern, we know floats don't work well
|
||||
// at these extremes.
|
||||
assert!((Duration::MAX).div_duration_f64(Duration::NANOSECOND) > 10.0f64.powf(28.0));
|
||||
assert!((Duration::NANOSECOND).div_duration_f64(Duration::MAX) < 0.1);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn checked_div() {
|
||||
assert_eq!(Duration::new(2, 0).checked_div(2), Some(Duration::new(1, 0)));
|
||||
|
Loading…
Reference in New Issue
Block a user