diff --git a/src/main.rs b/src/main.rs index a2c775b..bad9f33 100644 --- a/src/main.rs +++ b/src/main.rs @@ -25,11 +25,9 @@ trait Peristance { impl Peristance for BigUint { fn per_mul(&self) -> u8 { - let mut n = self.to_radix_le(10) - .into_iter() - .product::(); + let mut n = self.clone(); - let mut counter = 1; + let mut counter = 0; while n.to_str_radix(10).chars().count() > 1 { n = n.to_radix_le(10) .into_iter() @@ -112,3 +110,28 @@ fn main() { println!("Finding took {:#?}", start.elapsed()); return; } + + + + +#[cfg(test)] +mod tests { + // Note this useful idiom: importing names from outer (for mod tests) scope. + use super::*; + + #[test] + fn test_persistance() { + assert_eq!(BigUint::from(0u8).per_mul(), 0); + assert_eq!(BigUint::from(10u8).per_mul(), 1); + assert_eq!(BigUint::from(25u8).per_mul(), 2); + assert_eq!(BigUint::from(39u8).per_mul(), 3); + assert_eq!(BigUint::from(77u8).per_mul(), 4); + assert_eq!(BigUint::from(679u16).per_mul(), 5); + assert_eq!(BigUint::from(6788u16).per_mul(), 6); + assert_eq!(BigUint::from(68889u32).per_mul(), 7); + assert_eq!(BigUint::from(2677889u32).per_mul(), 8); + assert_eq!(BigUint::from(26888999u32).per_mul(), 9); + assert_eq!(BigUint::from(3778888999u32).per_mul(), 10); + assert_eq!(BigUint::from(277777788888899u64).per_mul(), 11); + } +}