From 36d22d82aa202bb199967e9512281e9a53db42c9 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 7 Apr 2024 21:33:14 +0200 Subject: Adding upstream version 115.7.0esr. Signed-off-by: Daniel Baumann --- third_party/rust/num-integer/tests/average.rs | 100 ++++++++++++++++++++++++++ 1 file changed, 100 insertions(+) create mode 100644 third_party/rust/num-integer/tests/average.rs (limited to 'third_party/rust/num-integer/tests/average.rs') diff --git a/third_party/rust/num-integer/tests/average.rs b/third_party/rust/num-integer/tests/average.rs new file mode 100644 index 0000000000..9fd8cf18f4 --- /dev/null +++ b/third_party/rust/num-integer/tests/average.rs @@ -0,0 +1,100 @@ +extern crate num_integer; +extern crate num_traits; + +macro_rules! test_average { + ($I:ident, $U:ident) => { + mod $I { + mod ceil { + use num_integer::Average; + + #[test] + fn same_sign() { + assert_eq!((14 as $I).average_ceil(&16), 15 as $I); + assert_eq!((14 as $I).average_ceil(&17), 16 as $I); + + let max = $crate::std::$I::MAX; + assert_eq!((max - 3).average_ceil(&(max - 1)), max - 2); + assert_eq!((max - 3).average_ceil(&(max - 2)), max - 2); + } + + #[test] + fn different_sign() { + assert_eq!((14 as $I).average_ceil(&-4), 5 as $I); + assert_eq!((14 as $I).average_ceil(&-5), 5 as $I); + + let min = $crate::std::$I::MIN; + let max = $crate::std::$I::MAX; + assert_eq!(min.average_ceil(&max), 0 as $I); + } + } + + mod floor { + use num_integer::Average; + + #[test] + fn same_sign() { + assert_eq!((14 as $I).average_floor(&16), 15 as $I); + assert_eq!((14 as $I).average_floor(&17), 15 as $I); + + let max = $crate::std::$I::MAX; + assert_eq!((max - 3).average_floor(&(max - 1)), max - 2); + assert_eq!((max - 3).average_floor(&(max - 2)), max - 3); + } + + #[test] + fn different_sign() { + assert_eq!((14 as $I).average_floor(&-4), 5 as $I); + assert_eq!((14 as $I).average_floor(&-5), 4 as $I); + + let min = $crate::std::$I::MIN; + let max = $crate::std::$I::MAX; + assert_eq!(min.average_floor(&max), -1 as $I); + } + } + } + + mod $U { + mod ceil { + use num_integer::Average; + + #[test] + fn bounded() { + assert_eq!((14 as $U).average_ceil(&16), 15 as $U); + assert_eq!((14 as $U).average_ceil(&17), 16 as $U); + } + + #[test] + fn overflow() { + let max = $crate::std::$U::MAX; + assert_eq!((max - 3).average_ceil(&(max - 1)), max - 2); + assert_eq!((max - 3).average_ceil(&(max - 2)), max - 2); + } + } + + mod floor { + use num_integer::Average; + + #[test] + fn bounded() { + assert_eq!((14 as $U).average_floor(&16), 15 as $U); + assert_eq!((14 as $U).average_floor(&17), 15 as $U); + } + + #[test] + fn overflow() { + let max = $crate::std::$U::MAX; + assert_eq!((max - 3).average_floor(&(max - 1)), max - 2); + assert_eq!((max - 3).average_floor(&(max - 2)), max - 3); + } + } + } + }; +} + +test_average!(i8, u8); +test_average!(i16, u16); +test_average!(i32, u32); +test_average!(i64, u64); +#[cfg(has_i128)] +test_average!(i128, u128); +test_average!(isize, usize); -- cgit v1.2.3