Add proper test for add function
Some checks failed
timw4mail/rusty-numbers/pipeline/head There was a failure building this commit
Some checks failed
timw4mail/rusty-numbers/pipeline/head There was a failure building this commit
This commit is contained in:
parent
d5d9730607
commit
a5e3e88e1e
@ -38,18 +38,18 @@ macro_rules! impl_from_smaller {
|
||||
#[cfg(target_pointer_width = "16")]
|
||||
impl_from_smaller!(u8, u16);
|
||||
|
||||
#[cfg(target_pointer_width = "32")]
|
||||
impl_from_smaller!(u8, u16, u32);
|
||||
|
||||
#[cfg(target_pointer_width = "64")]
|
||||
impl_from_smaller!(u8, u16, u32, u64);
|
||||
|
||||
#[cfg(target_pointer_width = "16")]
|
||||
static BITS:usize = 16;
|
||||
|
||||
#[cfg(target_pointer_width = "32")]
|
||||
impl_from_smaller!(u8, u16, u32);
|
||||
|
||||
#[cfg(target_pointer_width = "32")]
|
||||
static BITS:usize = 32;
|
||||
|
||||
#[cfg(target_pointer_width = "64")]
|
||||
impl_from_smaller!(u8, u16, u32, u64);
|
||||
|
||||
#[cfg(target_pointer_width = "64")]
|
||||
static BITS:usize = 64;
|
||||
|
||||
@ -78,7 +78,7 @@ fn add(u: BigInt, v: BigInt) -> BigInt {
|
||||
} else {
|
||||
out.inner.push(res);
|
||||
}
|
||||
carry = core::usize::MAX - res + 1;
|
||||
carry = core::usize::MAX - res;
|
||||
} else {
|
||||
if res < core::usize::MAX {
|
||||
out.inner.push(res + carry);
|
||||
@ -134,18 +134,7 @@ impl BigInt {
|
||||
todo!();
|
||||
}
|
||||
|
||||
pub fn from_str_radix() {
|
||||
todo!();
|
||||
}
|
||||
|
||||
/// Split an unsigned number into BigInt parts
|
||||
fn split<T: Unsigned>(&mut self, num: T) -> Vec<usize> {
|
||||
// Pretty easy if you don't actually need to split the value!
|
||||
if num < T::max_value() {
|
||||
todo!();
|
||||
// return vec![num as usize];
|
||||
}
|
||||
|
||||
pub fn from_str_radix<T: ToString>(s: T, radix: usize) {
|
||||
todo!();
|
||||
}
|
||||
}
|
||||
@ -160,13 +149,20 @@ mod tests {
|
||||
assert_eq!(int.inner[0], 45usize)
|
||||
}
|
||||
|
||||
/* #[test]
|
||||
#[test]
|
||||
fn test_add() {
|
||||
let a = BigInt::from(core::u64::MAX);
|
||||
let b = BigInt::from(core::u64::MAX);
|
||||
// MAX is 2^Bitsize - 1,
|
||||
// so the sum should be
|
||||
// [MAX -1, 1]
|
||||
// Compare base 10: 9 + 9 = 18
|
||||
let a = BigInt::from(core::usize::MAX);
|
||||
let b = BigInt::from(core::usize::MAX);
|
||||
|
||||
let sum = add(a, b);
|
||||
|
||||
assert!(false, "{:#?} should have inner equal to {:?}", sum, core::u64::MAX as u128 + core::u64::MAX as u128);
|
||||
} */
|
||||
assert_eq!(sum.inner[0], core::usize::MAX - 1, "least significant place should be MAX - 1");
|
||||
assert_eq!(sum.inner[1], 1usize, "most significant place should be 1");
|
||||
|
||||
// assert!(false, "{:#?} should have inner equal to {:?}", sum, core::u64::MAX as u128 + core::u64::MAX as u128);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user