]> git.lizzy.rs Git - rust.git/commitdiff
add BigUint subtraction underflow error message
authorRyan Mulligan <ryan@ryantm.com>
Sun, 27 Apr 2014 15:59:07 +0000 (08:59 -0700)
committerRyan Mulligan <ryan@ryantm.com>
Sun, 27 Apr 2014 17:37:02 +0000 (10:37 -0700)
src/libnum/bigint.rs

index 77c94d0150862fbe17a4a4e13bf0f2adee9e014d..45cd7ee47014b6db365f4fd09a41160e4e757b6a 100644 (file)
@@ -230,7 +230,8 @@ fn sub(&self, other: &BigUint) -> BigUint {
             lo
         }).collect();
 
-        assert_eq!(borrow, 0);     // <=> assert!((self >= other));
+        assert!(borrow == 0,
+                "Cannot subtract other from self because other is larger than self.");
         return BigUint::new(diff);
     }
 }
@@ -1755,6 +1756,13 @@ fn test_sub() {
         }
     }
 
+    #[test]
+    #[should_fail]
+    fn test_sub_fail_on_underflow() {
+        let (a, b) : (BigUint, BigUint) = (Zero::zero(), One::one());
+        a - b;
+    }
+
     static mul_triples: &'static [(&'static [BigDigit],
                                    &'static [BigDigit],
                                    &'static [BigDigit])] = &[