Fix formatting and add unit tests for panic cases
This commit is contained in:
parent
2f8d9a23ee
commit
e2b5a0334d
2 changed files with 38 additions and 2 deletions
|
|
@ -970,7 +970,7 @@ impl f32 {
|
|||
/// assert!((-3.0f32).clamp(-2.0f32, 1.0f32) == -2.0f32);
|
||||
/// assert!((0.0f32).clamp(-2.0f32, 1.0f32) == 0.0f32);
|
||||
/// assert!((2.0f32).clamp(-2.0f32, 1.0f32) == 1.0f32);
|
||||
/// assert!((std::f32::NAN).clamp(-2.0f32, 1.0f32).is_nan());
|
||||
/// assert!((std::f32::NAN).clamp(-2.0f32, 1.0f32).is_nan());
|
||||
/// ```
|
||||
#[unstable(feature = "clamp", issue = "44095")]
|
||||
#[inline]
|
||||
|
|
@ -1582,4 +1582,22 @@ mod tests {
|
|||
assert_eq!(f32::from_bits(masked_nan1).to_bits(), masked_nan1);
|
||||
assert_eq!(f32::from_bits(masked_nan2).to_bits(), masked_nan2);
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[should_panic]
|
||||
fn test_clamp_min_greater_than_max() {
|
||||
1.0f32.clamp(3.0, 1.0);
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[should_panic]
|
||||
fn test_clamp_min_is_nan() {
|
||||
1.0f32.clamp(NAN, 1.0);
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[should_panic]
|
||||
fn test_clamp_max_is_nan() {
|
||||
1.0f32.clamp(3.0, NAN);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -892,7 +892,7 @@ impl f64 {
|
|||
/// assert!((-3.0f64).clamp(-2.0f64, 1.0f64) == -2.0f64);
|
||||
/// assert!((0.0f64).clamp(-2.0f64, 1.0f64) == 0.0f64);
|
||||
/// assert!((2.0f64).clamp(-2.0f64, 1.0f64) == 1.0f64);
|
||||
/// assert!((std::f64::NAN).clamp(-2.0f32, 1.0f32).is_nan());
|
||||
/// assert!((std::f64::NAN).clamp(-2.0f32, 1.0f32).is_nan());
|
||||
/// ```
|
||||
#[unstable(feature = "clamp", issue = "44095")]
|
||||
#[inline]
|
||||
|
|
@ -1523,4 +1523,22 @@ mod tests {
|
|||
assert_eq!(f64::from_bits(masked_nan1).to_bits(), masked_nan1);
|
||||
assert_eq!(f64::from_bits(masked_nan2).to_bits(), masked_nan2);
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[should_panic]
|
||||
fn test_clamp_min_greater_than_max() {
|
||||
1.0f64.clamp(3.0, 1.0);
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[should_panic]
|
||||
fn test_clamp_min_is_nan() {
|
||||
1.0f64.clamp(NAN, 1.0);
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[should_panic]
|
||||
fn test_clamp_max_is_nan() {
|
||||
1.0f64.clamp(3.0, NAN);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue