]> git.lizzy.rs Git - rust.git/commitdiff
Add panic unit tests
authorJacob Kiesel <kieseljake@gmail.com>
Tue, 5 Sep 2017 02:49:46 +0000 (20:49 -0600)
committerJacob Kiesel <kieseljake@gmail.com>
Tue, 5 Sep 2017 03:39:46 +0000 (21:39 -0600)
src/libstd/f32.rs
src/libstd/f64.rs
src/libstd/lib.rs

index aaeac06535ee6c32300dcb81d3f285c6d260fee2..69ca77f54b44aa70b33e2bd33952f91fabb0826d 100644 (file)
@@ -1777,4 +1777,22 @@ fn test_snan_masking() {
         assert_ne!(nan_masked & QNAN_MASK, 0);
         assert!(nan_masked_fl.is_nan());
     }
+
+    #[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);
+    }
 }
index 4ab319c3cf10069e889e07071ea4b2ceb27cf0e9..6ec633bfaaac1be5dcfa5f7110ddb0671db6c3a3 100644 (file)
@@ -1668,4 +1668,22 @@ fn test_float_bits_conv() {
         assert_approx_eq!(f64::from_bits(0x4094e40000000000), 1337.0);
         assert_approx_eq!(f64::from_bits(0xc02c800000000000), -14.25);
     }
+
+    #[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);
+    }
 }
index cf1eb5cd52ea476a373460ac89b2f9145c168f9b..191f7fe648ed29013a478b161e42e75c64a4d712 100644 (file)
 #![feature(cfg_target_vendor)]
 #![feature(char_error_internals)]
 #![feature(char_internals)]
+#![feature(clamp)]
 #![feature(collections_range)]
 #![feature(compiler_builtins_lib)]
 #![feature(const_fn)]