From a5e4e7ab52a031153ae7cef169ea7fa50cc6ae1c Mon Sep 17 00:00:00 2001 From: Roger Curley Date: Mon, 4 Aug 2025 13:59:47 -0400 Subject: Consolidate clamp tests --- library/coretests/tests/floats/f128.rs | 18 -------------- library/coretests/tests/floats/f16.rs | 18 -------------- library/coretests/tests/floats/f32.rs | 18 -------------- library/coretests/tests/floats/f64.rs | 18 -------------- library/coretests/tests/floats/mod.rs | 45 ++++++++++++++++++++++++++++++++++ 5 files changed, 45 insertions(+), 72 deletions(-) diff --git a/library/coretests/tests/floats/f128.rs b/library/coretests/tests/floats/f128.rs index 43882ad89a2..0ac297d5052 100644 --- a/library/coretests/tests/floats/f128.rs +++ b/library/coretests/tests/floats/f128.rs @@ -132,24 +132,6 @@ fn test_float_bits_conv() { assert_eq!(f128::from_bits(masked_nan2).to_bits(), masked_nan2); } -#[test] -#[should_panic] -fn test_clamp_min_greater_than_max() { - let _ = 1.0f128.clamp(3.0, 1.0); -} - -#[test] -#[should_panic] -fn test_clamp_min_is_nan() { - let _ = 1.0f128.clamp(f128::NAN, 1.0); -} - -#[test] -#[should_panic] -fn test_clamp_max_is_nan() { - let _ = 1.0f128.clamp(3.0, f128::NAN); -} - #[test] fn test_total_cmp() { use core::cmp::Ordering; diff --git a/library/coretests/tests/floats/f16.rs b/library/coretests/tests/floats/f16.rs index c405e4e5c85..4088ed79aaf 100644 --- a/library/coretests/tests/floats/f16.rs +++ b/library/coretests/tests/floats/f16.rs @@ -131,24 +131,6 @@ fn test_float_bits_conv() { assert_eq!(f16::from_bits(masked_nan2).to_bits(), masked_nan2); } -#[test] -#[should_panic] -fn test_clamp_min_greater_than_max() { - let _ = 1.0f16.clamp(3.0, 1.0); -} - -#[test] -#[should_panic] -fn test_clamp_min_is_nan() { - let _ = 1.0f16.clamp(f16::NAN, 1.0); -} - -#[test] -#[should_panic] -fn test_clamp_max_is_nan() { - let _ = 1.0f16.clamp(3.0, f16::NAN); -} - #[test] #[cfg(not(miri))] #[cfg(target_has_reliable_f16_math)] diff --git a/library/coretests/tests/floats/f32.rs b/library/coretests/tests/floats/f32.rs index f08b033fb5e..20d04fcf35a 100644 --- a/library/coretests/tests/floats/f32.rs +++ b/library/coretests/tests/floats/f32.rs @@ -112,24 +112,6 @@ fn test_float_bits_conv() { assert_eq!(f32::from_bits(masked_nan2).to_bits(), masked_nan2); } -#[test] -#[should_panic] -fn test_clamp_min_greater_than_max() { - let _ = 1.0f32.clamp(3.0, 1.0); -} - -#[test] -#[should_panic] -fn test_clamp_min_is_nan() { - let _ = 1.0f32.clamp(f32::NAN, 1.0); -} - -#[test] -#[should_panic] -fn test_clamp_max_is_nan() { - let _ = 1.0f32.clamp(3.0, f32::NAN); -} - #[test] fn test_total_cmp() { use core::cmp::Ordering; diff --git a/library/coretests/tests/floats/f64.rs b/library/coretests/tests/floats/f64.rs index 8d7d31b57c1..9d97a61e762 100644 --- a/library/coretests/tests/floats/f64.rs +++ b/library/coretests/tests/floats/f64.rs @@ -105,24 +105,6 @@ fn test_float_bits_conv() { assert_eq!(f64::from_bits(masked_nan2).to_bits(), masked_nan2); } -#[test] -#[should_panic] -fn test_clamp_min_greater_than_max() { - let _ = 1.0f64.clamp(3.0, 1.0); -} - -#[test] -#[should_panic] -fn test_clamp_min_is_nan() { - let _ = 1.0f64.clamp(f64::NAN, 1.0); -} - -#[test] -#[should_panic] -fn test_clamp_max_is_nan() { - let _ = 1.0f64.clamp(3.0, f64::NAN); -} - #[test] fn test_total_cmp() { use core::cmp::Ordering; diff --git a/library/coretests/tests/floats/mod.rs b/library/coretests/tests/floats/mod.rs index 68ed8d47094..ad25b49d8a3 100644 --- a/library/coretests/tests/floats/mod.rs +++ b/library/coretests/tests/floats/mod.rs @@ -1145,3 +1145,48 @@ float_test! { assert_biteq!(Float::INFINITY.sqrt(), Float::INFINITY); } } + +float_test! { + name: clamp_min_greater_than_max, + attrs: { + const: #[cfg(false)], + f16: #[should_panic, cfg(any(miri, target_has_reliable_f16))], + f32: #[should_panic], + f64: #[should_panic], + f128: #[should_panic, cfg(any(miri, target_has_reliable_f128))], + }, + test { + let one : Float = 1.0; + let _ = one.clamp(3.0, 1.0); + } +} + +float_test! { + name: clamp_min_is_nan, + attrs: { + const: #[cfg(false)], + f16: #[should_panic, cfg(any(miri, target_has_reliable_f16))], + f32: #[should_panic], + f64: #[should_panic], + f128: #[should_panic, cfg(any(miri, target_has_reliable_f128))], + }, + test { + let one : Float = 1.0; + let _ = one.clamp(Float::NAN, 1.0); + } +} + +float_test! { + name: clamp_max_is_nan, + attrs: { + const: #[cfg(false)], + f16: #[should_panic, cfg(any(miri, target_has_reliable_f16))], + f32: #[should_panic], + f64: #[should_panic], + f128: #[should_panic, cfg(any(miri, target_has_reliable_f128))], + }, + test { + let one : Float = 1.0; + let _ = one.clamp(3.0, Float::NAN); + } +} -- cgit 1.4.1-3-g733a5