From faa1f548a051b84ff34ed989bc9ab6b3e0beaef5 Mon Sep 17 00:00:00 2001 From: Timothy Warren Date: Thu, 26 Mar 2020 11:40:14 -0400 Subject: [PATCH] Some test coverage for sign handling --- src/bigint.rs | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/src/bigint.rs b/src/bigint.rs index e496912..d43024b 100644 --- a/src/bigint.rs +++ b/src/bigint.rs @@ -479,6 +479,18 @@ mod tests { let sum = a + b; assert_eq!(sum.inner[0], 0usize); assert_eq!(sum.inner[1], 1usize); + + let a = BigInt::from(10); + let b = -BigInt::from(5); + let sum = a + b; + assert_eq!(sum.inner[0], 5usize); + assert_eq!(sum.sign, Positive); + + let a = -BigInt::from(5); + let b = BigInt::from(10); + let sum = a + b; + assert_eq!(sum.inner[0], 5usize); + assert_eq!(sum.sign, Positive); } #[test] @@ -507,6 +519,18 @@ mod tests { core::usize::MAX - core::u16::MAX as usize ); assert_eq!(diff.inner.len(), 1); + + let a = BigInt::from(5); + let b = -BigInt::from(3); + let diff = a - b; + assert_eq!(diff.sign, Positive); + assert_eq!(diff.inner[0], 8usize); + + let a = -BigInt::from(5); + let b = BigInt::from(3); + let diff = a - b; + assert_eq!(diff.sign, Negative); + assert_eq!(diff.inner[0], 8usize); } #[test]