]> git.proxmox.com Git - rustc.git/blobdiff - src/libcore/tests/num/mod.rs
New upstream version 1.28.0~beta.14+dfsg1
[rustc.git] / src / libcore / tests / num / mod.rs
index c7edb55b378c36ce1208c32a96ef6b448f15c778..b5e6a019a228c6b4e87932323fbc0114ccd29631 100644 (file)
@@ -134,6 +134,15 @@ fn test_infallible_try_from_int_error() {
 }
 
 macro_rules! test_impl_from {
+    ($fn_name:ident, bool, $target: ty) => {
+        #[test]
+        fn $fn_name() {
+            let one: $target = 1;
+            let zero: $target = 0;
+            assert_eq!(one, <$target>::from(true));
+            assert_eq!(zero, <$target>::from(false));
+        }
+    };
     ($fn_name: ident, $Small: ty, $Large: ty) => {
         #[test]
         fn $fn_name() {
@@ -173,6 +182,18 @@ test_impl_from! { test_u16i32, u16, i32 }
 test_impl_from! { test_u16i64, u16, i64 }
 test_impl_from! { test_u32i64, u32, i64 }
 
+// Bool -> Integer
+test_impl_from! { test_boolu8, bool, u8 }
+test_impl_from! { test_boolu16, bool, u16 }
+test_impl_from! { test_boolu32, bool, u32 }
+test_impl_from! { test_boolu64, bool, u64 }
+test_impl_from! { test_boolu128, bool, u128 }
+test_impl_from! { test_booli8, bool, i8 }
+test_impl_from! { test_booli16, bool, i16 }
+test_impl_from! { test_booli32, bool, i32 }
+test_impl_from! { test_booli64, bool, i64 }
+test_impl_from! { test_booli128, bool, i128 }
+
 // Signed -> Float
 test_impl_from! { test_i8f32, i8, f32 }
 test_impl_from! { test_i8f64, i8, f64 }
@@ -508,51 +529,50 @@ assume_usize_width! {
 
 macro_rules! test_float {
     ($modname: ident, $fty: ty, $inf: expr, $neginf: expr, $nan: expr) => { mod $modname {
-        use core::num::Float;
         // FIXME(nagisa): these tests should test for sign of -0.0
         #[test]
         fn min() {
-            assert_eq!(0.0.min(0.0), 0.0);
-            assert_eq!((-0.0).min(-0.0), -0.0);
-            assert_eq!(9.0.min(9.0), 9.0);
-            assert_eq!((-9.0).min(0.0), -9.0);
-            assert_eq!(0.0.min(9.0), 0.0);
-            assert_eq!((-0.0).min(-9.0), -9.0);
-            assert_eq!($inf.min(9.0), 9.0);
-            assert_eq!(9.0.min($inf), 9.0);
-            assert_eq!($inf.min(-9.0), -9.0);
-            assert_eq!((-9.0).min($inf), -9.0);
-            assert_eq!($neginf.min(9.0), $neginf);
-            assert_eq!(9.0.min($neginf), $neginf);
-            assert_eq!($neginf.min(-9.0), $neginf);
-            assert_eq!((-9.0).min($neginf), $neginf);
-            assert_eq!($nan.min(9.0), 9.0);
-            assert_eq!($nan.min(-9.0), -9.0);
-            assert_eq!(9.0.min($nan), 9.0);
-            assert_eq!((-9.0).min($nan), -9.0);
-            assert!($nan.min($nan).is_nan());
+            assert_eq!((0.0 as $fty).min(0.0), 0.0);
+            assert_eq!((-0.0 as $fty).min(-0.0), -0.0);
+            assert_eq!((9.0 as $fty).min(9.0), 9.0);
+            assert_eq!((-9.0 as $fty).min(0.0), -9.0);
+            assert_eq!((0.0 as $fty).min(9.0), 0.0);
+            assert_eq!((-0.0 as $fty).min(-9.0), -9.0);
+            assert_eq!(($inf as $fty).min(9.0), 9.0);
+            assert_eq!((9.0 as $fty).min($inf), 9.0);
+            assert_eq!(($inf as $fty).min(-9.0), -9.0);
+            assert_eq!((-9.0 as $fty).min($inf), -9.0);
+            assert_eq!(($neginf as $fty).min(9.0), $neginf);
+            assert_eq!((9.0 as $fty).min($neginf), $neginf);
+            assert_eq!(($neginf as $fty).min(-9.0), $neginf);
+            assert_eq!((-9.0 as $fty).min($neginf), $neginf);
+            assert_eq!(($nan as $fty).min(9.0), 9.0);
+            assert_eq!(($nan as $fty).min(-9.0), -9.0);
+            assert_eq!((9.0 as $fty).min($nan), 9.0);
+            assert_eq!((-9.0 as $fty).min($nan), -9.0);
+            assert!(($nan as $fty).min($nan).is_nan());
         }
         #[test]
         fn max() {
-            assert_eq!(0.0.max(0.0), 0.0);
-            assert_eq!((-0.0).max(-0.0), -0.0);
-            assert_eq!(9.0.max(9.0), 9.0);
-            assert_eq!((-9.0).max(0.0), 0.0);
-            assert_eq!(0.0.max(9.0), 9.0);
-            assert_eq!((-0.0).max(-9.0), -0.0);
-            assert_eq!($inf.max(9.0), $inf);
-            assert_eq!(9.0.max($inf), $inf);
-            assert_eq!($inf.max(-9.0), $inf);
-            assert_eq!((-9.0).max($inf), $inf);
-            assert_eq!($neginf.max(9.0), 9.0);
-            assert_eq!(9.0.max($neginf), 9.0);
-            assert_eq!($neginf.max(-9.0), -9.0);
-            assert_eq!((-9.0).max($neginf), -9.0);
-            assert_eq!($nan.max(9.0), 9.0);
-            assert_eq!($nan.max(-9.0), -9.0);
-            assert_eq!(9.0.max($nan), 9.0);
-            assert_eq!((-9.0).max($nan), -9.0);
-            assert!($nan.max($nan).is_nan());
+            assert_eq!((0.0 as $fty).max(0.0), 0.0);
+            assert_eq!((-0.0 as $fty).max(-0.0), -0.0);
+            assert_eq!((9.0 as $fty).max(9.0), 9.0);
+            assert_eq!((-9.0 as $fty).max(0.0), 0.0);
+            assert_eq!((0.0 as $fty).max(9.0), 9.0);
+            assert_eq!((-0.0 as $fty).max(-9.0), -0.0);
+            assert_eq!(($inf as $fty).max(9.0), $inf);
+            assert_eq!((9.0 as $fty).max($inf), $inf);
+            assert_eq!(($inf as $fty).max(-9.0), $inf);
+            assert_eq!((-9.0 as $fty).max($inf), $inf);
+            assert_eq!(($neginf as $fty).max(9.0), 9.0);
+            assert_eq!((9.0 as $fty).max($neginf), 9.0);
+            assert_eq!(($neginf as $fty).max(-9.0), -9.0);
+            assert_eq!((-9.0 as $fty).max($neginf), -9.0);
+            assert_eq!(($nan as $fty).max(9.0), 9.0);
+            assert_eq!(($nan as $fty).max(-9.0), -9.0);
+            assert_eq!((9.0 as $fty).max($nan), 9.0);
+            assert_eq!((-9.0 as $fty).max($nan), -9.0);
+            assert!(($nan as $fty).max($nan).is_nan());
         }
     } }
 }