From 7a14f2d6034f87383a789879046f92813ea002dd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20L=C3=B8vbr=C3=B8tte=20Olsen?= Date: Thu, 28 Mar 2019 12:23:43 +0100 Subject: [PATCH] make unit test --- src/main.rs | 31 +++++++++++++++++++++++++++---- 1 file changed, 27 insertions(+), 4 deletions(-) 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); + } +}