summaryrefslogtreecommitdiff
path: root/vendor/num-integer/tests/average.rs
diff options
context:
space:
mode:
authorValentin Popov <valentin@popov.link>2024-01-08 00:21:28 +0300
committerValentin Popov <valentin@popov.link>2024-01-08 00:21:28 +0300
commit1b6a04ca5504955c571d1c97504fb45ea0befee4 (patch)
tree7579f518b23313e8a9748a88ab6173d5e030b227 /vendor/num-integer/tests/average.rs
parent5ecd8cf2cba827454317368b68571df0d13d7842 (diff)
downloadfparkan-1b6a04ca5504955c571d1c97504fb45ea0befee4.tar.xz
fparkan-1b6a04ca5504955c571d1c97504fb45ea0befee4.zip
Initial vendor packages
Signed-off-by: Valentin Popov <valentin@popov.link>
Diffstat (limited to 'vendor/num-integer/tests/average.rs')
-rw-r--r--vendor/num-integer/tests/average.rs100
1 files changed, 100 insertions, 0 deletions
diff --git a/vendor/num-integer/tests/average.rs b/vendor/num-integer/tests/average.rs
new file mode 100644
index 0000000..9fd8cf1
--- /dev/null
+++ b/vendor/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);