More test coverage
All checks were successful
timw4mail/rusty-numbers/pipeline/head This commit looks good

This commit is contained in:
Timothy Warren 2020-03-13 23:02:27 -04:00
parent 547266e97f
commit 70aa876500
2 changed files with 25 additions and 9 deletions

View File

@ -113,16 +113,14 @@ impl BigInt {
let a_digits = a.inner.len(); let a_digits = a.inner.len();
let b_digits = b.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 b_digits
} else { } else {
a_digits a_digits
};
if digits > 0 {
digits
} else {
1
} }
} }
} }
@ -610,4 +608,24 @@ mod tests {
fn test_from_large_signed() { fn test_from_large_signed() {
BigInt::from(128i128); 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);
}
} }

View File

@ -151,7 +151,6 @@ macro_rules! impl_int {
self == 0 self == 0
} }
#[cfg_attr(tarpaulin, skip)]
fn max_value() -> $type { fn max_value() -> $type {
<$type>::max_value() <$type>::max_value()
} }
@ -244,7 +243,6 @@ macro_rules! impl_unsigned {
let (x, y) = (min(x, y), max(x, y)); let (x, y) = (min(x, y), max(x, y));
Self::stein_gcd((y - x) >> 1, x) Self::stein_gcd((y - x) >> 1, x)
} }
#[cfg_attr(tarpaulin, skip)]
_ => unreachable!(), _ => unreachable!(),
} }
} }