Add some more tests to bigint module
All checks were successful
timw4mail/rusty-numbers/pipeline/head This commit looks good
All checks were successful
timw4mail/rusty-numbers/pipeline/head This commit looks good
This commit is contained in:
parent
541859bccf
commit
1f15ff93f5
@ -887,7 +887,7 @@ mod tests {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_not() {
|
fn test_not() {
|
||||||
let a = BigInt::from(0u8);
|
let a = BigInt::from(0_u8);
|
||||||
let b = !a;
|
let b = !a;
|
||||||
|
|
||||||
assert_eq!(b.inner[0], core::usize::MAX);
|
assert_eq!(b.inner[0], core::usize::MAX);
|
||||||
@ -895,7 +895,7 @@ mod tests {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_partial_eq() {
|
fn test_partial_eq() {
|
||||||
let a = 12345u16;
|
let a = 12345_u16;
|
||||||
let b = BigInt::from(a);
|
let b = BigInt::from(a);
|
||||||
|
|
||||||
assert!(a.eq(&b));
|
assert!(a.eq(&b));
|
||||||
@ -904,9 +904,9 @@ mod tests {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_partial_ord() {
|
fn test_partial_ord() {
|
||||||
let a = 12345u32;
|
let a = 12345_u32;
|
||||||
let b = BigInt::from(a);
|
let b = BigInt::from(a);
|
||||||
let c = 3u8;
|
let c = 3_u8;
|
||||||
|
|
||||||
assert_eq!(a.partial_cmp(&b), Some(Ordering::Equal));
|
assert_eq!(a.partial_cmp(&b), Some(Ordering::Equal));
|
||||||
assert_eq!(c.partial_cmp(&b), Some(Ordering::Less));
|
assert_eq!(c.partial_cmp(&b), Some(Ordering::Less));
|
||||||
@ -924,7 +924,7 @@ mod tests {
|
|||||||
assert_eq!(-BigInt::from(2), BigInt::from(-2));
|
assert_eq!(-BigInt::from(2), BigInt::from(-2));
|
||||||
|
|
||||||
// Larger than usize
|
// Larger than usize
|
||||||
assert_eq!(BigInt::from(45u128), BigInt::from(45usize));
|
assert_eq!(BigInt::from(45_u128), BigInt::from(45_usize));
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
@ -933,8 +933,8 @@ mod tests {
|
|||||||
let res = BigInt::from(big_num);
|
let res = BigInt::from(big_num);
|
||||||
|
|
||||||
assert_eq!(res.sign, Sign::Positive, "{:#?}", res);
|
assert_eq!(res.sign, Sign::Positive, "{:#?}", res);
|
||||||
assert_eq!(res.inner[0], 8usize, "{:#?}", res);
|
assert_eq!(res.inner[0], 8_usize, "{:#?}", res);
|
||||||
assert_eq!(res.inner[1], 9usize, "{:#?}", res);
|
assert_eq!(res.inner[1], 9_usize, "{:#?}", res);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
@ -943,8 +943,8 @@ mod tests {
|
|||||||
let res = BigInt::from(-big_num);
|
let res = BigInt::from(-big_num);
|
||||||
|
|
||||||
assert_eq!(res.sign, Sign::Negative, "{:#?}", res);
|
assert_eq!(res.sign, Sign::Negative, "{:#?}", res);
|
||||||
assert_eq!(res.inner[0], 3usize, "{:#?}", res);
|
assert_eq!(res.inner[0], 3_usize, "{:#?}", res);
|
||||||
assert_eq!(res.inner[1], 2usize, "{:#?}", res);
|
assert_eq!(res.inner[1], 2_usize, "{:#?}", res);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
@ -958,7 +958,7 @@ mod tests {
|
|||||||
fn test_from_str_small() {
|
fn test_from_str_small() {
|
||||||
let str = "012345";
|
let str = "012345";
|
||||||
let num = BigInt::from(str);
|
let num = BigInt::from(str);
|
||||||
assert_eq!(num.inner[0], 12345usize);
|
assert_eq!(num.inner[0], 12345_usize);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
@ -972,20 +972,36 @@ mod tests {
|
|||||||
fn test_from_string_small() {
|
fn test_from_string_small() {
|
||||||
let str = String::from("012345");
|
let str = String::from("012345");
|
||||||
let num = BigInt::from(str);
|
let num = BigInt::from(str);
|
||||||
assert_eq!(num.inner[0], 12345usize);
|
assert_eq!(num.inner[0], 12345_usize);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_from_str_radix_1() {
|
fn test_from_str_radix_1() {
|
||||||
let s = "1".repeat(32);
|
let s = "1".repeat(32);
|
||||||
let num = BigInt::from_str_radix(s, 1);
|
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]
|
#[test]
|
||||||
#[should_panic]
|
#[should_panic]
|
||||||
fn test_from_str_radix_large() {
|
fn test_from_str_radix_large() {
|
||||||
BigInt::from_str_radix("ZYXWVUTSRQPONMLKJIHGFEDCBA987654321", 36);
|
let _ = BigInt::from_str_radix("ZYXWVUTSRQPONMLKJIHGFEDCBA987654321", 36);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
@ -993,12 +1009,12 @@ mod tests {
|
|||||||
let num = BigInt::from_str_radix("FEDCBA", 16);
|
let num = BigInt::from_str_radix("FEDCBA", 16);
|
||||||
assert!(num.inner[0] > 0, "Number is not greater than 0");
|
assert!(num.inner[0] > 0, "Number is not greater than 0");
|
||||||
assert!(num.inner[0] < usize::MAX, "Result is larger than usize");
|
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]
|
#[test]
|
||||||
fn test_from_str_radix_lowercase() {
|
fn test_from_str_radix_lowercase() {
|
||||||
let num = BigInt::from_str_radix("fedcba", 16);
|
let num = BigInt::from_str_radix("fedcba", 16);
|
||||||
assert_eq!(num.inner[0], 0xFEDCBAusize);
|
assert_eq!(num.inner[0], 0xFEDCBA_usize);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user