From 187609af5c0332a7fa027565425fcf0342db86f8 Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Mon, 6 Jul 2015 17:17:32 +0200 Subject: [PATCH] test that subtraction appropriately panics --- solutions/src/bigint.rs | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/solutions/src/bigint.rs b/solutions/src/bigint.rs index 7a61b4b..8d67a78 100644 --- a/solutions/src/bigint.rs +++ b/solutions/src/bigint.rs @@ -320,12 +320,24 @@ mod tests { assert_eq!(&b2 - &b1, BigInt::from_vec(vec![u64::max_value() - (1 << 32) + 1])); assert_eq!(&b3 - &b2, BigInt::from_vec(vec![0, u64::max_value(), 0])); - assert_eq!(&b2 - &b4 - &b4, BigInt::from_vec(vec![0])); + assert_eq!(&b2 - &b4 - &b4, BigInt::new(0)); assert_eq!(&b3 - &b2 - &b4 - &b4, BigInt::from_vec(vec![0, u64::max_value() - 1])); assert_eq!(&b3 - &b4 - &b2 - &b4, BigInt::from_vec(vec![0, u64::max_value() - 1])); assert_eq!(&b3 - &b4 - &b4 - &b2, BigInt::from_vec(vec![0, u64::max_value() - 1])); } + #[test] + #[should_panic(expected = "Wrapping subtraction of BigInt")] + fn test_sub_panic1() { + let _ = BigInt::new(1) - BigInt::new(5); + } + + #[test] + #[should_panic(expected = "Wrapping subtraction of BigInt")] + fn test_sub_panic2() { + let _ = BigInt::from_vec(vec![5,8,3,33,1<<13,46,1<<49, 1, 583,1<<60,2533]) - BigInt::from_vec(vec![5,8,3,33,1<<13,46,1<<49, 5, 583,1<<60,2533]); + } + #[test] fn test_inc1() { let mut b = BigInt::new(0); -- 2.30.2