make unit test

This commit is contained in:
Daniel Løvbrøtte Olsen 2019-03-28 12:23:43 +01:00
parent 0be764ef23
commit 7a14f2d603
1 changed files with 27 additions and 4 deletions

View File

@ -25,11 +25,9 @@ trait Peristance {
impl Peristance for BigUint { impl Peristance for BigUint {
fn per_mul(&self) -> u8 { fn per_mul(&self) -> u8 {
let mut n = self.to_radix_le(10) let mut n = self.clone();
.into_iter()
.product::<BigUint>();
let mut counter = 1; let mut counter = 0;
while n.to_str_radix(10).chars().count() > 1 { while n.to_str_radix(10).chars().count() > 1 {
n = n.to_radix_le(10) n = n.to_radix_le(10)
.into_iter() .into_iter()
@ -112,3 +110,28 @@ fn main() {
println!("Finding took {:#?}", start.elapsed()); println!("Finding took {:#?}", start.elapsed());
return; 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);
}
}