From 70aa87650087362b9d426cc02b8beef8bf9e5c21 Mon Sep 17 00:00:00 2001 From: "Timothy J. Warren" Date: Fri, 13 Mar 2020 23:02:27 -0400 Subject: [PATCH] More test coverage --- src/bigint.rs | 32 +++++++++++++++++++++++++------- src/num.rs | 2 -- 2 files changed, 25 insertions(+), 9 deletions(-) diff --git a/src/bigint.rs b/src/bigint.rs index 336ec7c..1245fcb 100644 --- a/src/bigint.rs +++ b/src/bigint.rs @@ -113,16 +113,14 @@ impl BigInt { let a_digits = a.inner.len(); let b_digits = b.inner.len(); - let digits = if b_digits > a_digits { + if a_digits == 0 && b_digits == 0 { + return 1; + } + + if b_digits > a_digits { b_digits } else { a_digits - }; - - if digits > 0 { - digits - } else { - 1 } } } @@ -610,4 +608,24 @@ mod tests { fn test_from_large_signed() { BigInt::from(128i128); } + + #[test] + #[should_panic] + fn test_from_str() { + let str = "012345"; + BigInt::from(str); + } + + #[test] + #[should_panic] + fn test_from_string() { + let str = String::from("012345"); + BigInt::from(str); + } + + #[test] + #[should_panic] + fn test_from_str_radix() { + BigInt::from_str_radix("123456", 16); + } } diff --git a/src/num.rs b/src/num.rs index 1408486..ff3aeab 100644 --- a/src/num.rs +++ b/src/num.rs @@ -151,7 +151,6 @@ macro_rules! impl_int { self == 0 } - #[cfg_attr(tarpaulin, skip)] fn max_value() -> $type { <$type>::max_value() } @@ -244,7 +243,6 @@ macro_rules! impl_unsigned { let (x, y) = (min(x, y), max(x, y)); Self::stein_gcd((y - x) >> 1, x) } - #[cfg_attr(tarpaulin, skip)] _ => unreachable!(), } }