Add some more tests to bigint module
All checks were successful
timw4mail/rusty-numbers/pipeline/head This commit looks good

This commit is contained in:
Timothy Warren 2021-12-08 14:14:50 -05:00
parent 541859bccf
commit 1f15ff93f5

View File

@ -887,7 +887,7 @@ mod tests {
#[test]
fn test_not() {
let a = BigInt::from(0u8);
let a = BigInt::from(0_u8);
let b = !a;
assert_eq!(b.inner[0], core::usize::MAX);
@ -895,7 +895,7 @@ mod tests {
#[test]
fn test_partial_eq() {
let a = 12345u16;
let a = 12345_u16;
let b = BigInt::from(a);
assert!(a.eq(&b));
@ -904,9 +904,9 @@ mod tests {
#[test]
fn test_partial_ord() {
let a = 12345u32;
let a = 12345_u32;
let b = BigInt::from(a);
let c = 3u8;
let c = 3_u8;
assert_eq!(a.partial_cmp(&b), Some(Ordering::Equal));
assert_eq!(c.partial_cmp(&b), Some(Ordering::Less));
@ -924,7 +924,7 @@ mod tests {
assert_eq!(-BigInt::from(2), BigInt::from(-2));
// Larger than usize
assert_eq!(BigInt::from(45u128), BigInt::from(45usize));
assert_eq!(BigInt::from(45_u128), BigInt::from(45_usize));
}
#[test]
@ -933,8 +933,8 @@ mod tests {
let res = BigInt::from(big_num);
assert_eq!(res.sign, Sign::Positive, "{:#?}", res);
assert_eq!(res.inner[0], 8usize, "{:#?}", res);
assert_eq!(res.inner[1], 9usize, "{:#?}", res);
assert_eq!(res.inner[0], 8_usize, "{:#?}", res);
assert_eq!(res.inner[1], 9_usize, "{:#?}", res);
}
#[test]
@ -943,8 +943,8 @@ mod tests {
let res = BigInt::from(-big_num);
assert_eq!(res.sign, Sign::Negative, "{:#?}", res);
assert_eq!(res.inner[0], 3usize, "{:#?}", res);
assert_eq!(res.inner[1], 2usize, "{:#?}", res);
assert_eq!(res.inner[0], 3_usize, "{:#?}", res);
assert_eq!(res.inner[1], 2_usize, "{:#?}", res);
}
#[test]
@ -958,7 +958,7 @@ mod tests {
fn test_from_str_small() {
let str = "012345";
let num = BigInt::from(str);
assert_eq!(num.inner[0], 12345usize);
assert_eq!(num.inner[0], 12345_usize);
}
#[test]
@ -972,20 +972,36 @@ mod tests {
fn test_from_string_small() {
let str = String::from("012345");
let num = BigInt::from(str);
assert_eq!(num.inner[0], 12345usize);
assert_eq!(num.inner[0], 12345_usize);
}
#[test]
fn test_from_str_radix_1() {
let s = "1".repeat(32);
let num = BigInt::from_str_radix(s, 1);
assert_eq!(num.inner[0], 32usize);
assert_eq!(num.inner[0], 32_usize);
}
#[test]
fn test_from_str_radix_1_with_zeroes() {
let ones = "1".repeat(32);
let zeroes = "0".repeat(24);
let s = ones + &zeroes;
let num = BigInt::from_str_radix(s, 1);
assert_eq!(num.inner[0], 32_usize);
}
#[test]
#[should_panic]
fn test_from_str_radix_invalid() {
let _ = BigInt::from_str_radix("foobar0", 50);
}
#[test]
#[should_panic]
fn test_from_str_radix_large() {
BigInt::from_str_radix("ZYXWVUTSRQPONMLKJIHGFEDCBA987654321", 36);
let _ = BigInt::from_str_radix("ZYXWVUTSRQPONMLKJIHGFEDCBA987654321", 36);
}
#[test]
@ -993,12 +1009,12 @@ mod tests {
let num = BigInt::from_str_radix("FEDCBA", 16);
assert!(num.inner[0] > 0, "Number is not greater than 0");
assert!(num.inner[0] < usize::MAX, "Result is larger than usize");
assert_eq!(num.inner[0], 0xFEDCBAusize);
assert_eq!(num.inner[0], 0xFEDCBA_usize);
}
#[test]
fn test_from_str_radix_lowercase() {
let num = BigInt::from_str_radix("fedcba", 16);
assert_eq!(num.inner[0], 0xFEDCBAusize);
assert_eq!(num.inner[0], 0xFEDCBA_usize);
}
}