From 550c87e17dff0ff7f87a2b4c33fe25b16707e4f6 Mon Sep 17 00:00:00 2001 From: Ryan Mulligan Date: Sun, 27 Apr 2014 08:59:07 -0700 Subject: [PATCH] add BigUint subtraction underflow error message --- src/libnum/bigint.rs | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/libnum/bigint.rs b/src/libnum/bigint.rs index 77c94d0150862..45cd7ee47014b 100644 --- a/src/libnum/bigint.rs +++ b/src/libnum/bigint.rs @@ -230,7 +230,8 @@ impl Sub for 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 @@ mod biguint_tests { } } + #[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])] = &[