mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-29 03:57:44 +00:00
factor::table::chunked: Add test (equivalent to the single-number version)
This commit is contained in:
parent
998b3c11d3
commit
a0a103b15e
1 changed files with 27 additions and 0 deletions
|
@ -72,3 +72,30 @@ pub fn factor_chunk(n_s: &mut [u64; CHUNK_SIZE], f_s: &mut [Factors; CHUNK_SIZE]
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use crate::Factors;
|
||||
use quickcheck::quickcheck;
|
||||
use rand::{rngs::SmallRng, Rng, SeedableRng};
|
||||
|
||||
quickcheck! {
|
||||
fn chunk_vs_iter(seed: u64) -> () {
|
||||
let mut rng = SmallRng::seed_from_u64(seed);
|
||||
let mut n_c: [u64; CHUNK_SIZE] = rng.gen();
|
||||
let mut f_c: [Factors; CHUNK_SIZE] = rng.gen();
|
||||
|
||||
let mut n_i = n_c.clone();
|
||||
let mut f_i = f_c.clone();
|
||||
for (n, f) in n_i.iter_mut().zip(f_i.iter_mut()) {
|
||||
factor(n, f);
|
||||
}
|
||||
|
||||
factor_chunk(&mut n_c, &mut f_c);
|
||||
|
||||
assert_eq!(n_i, n_c);
|
||||
assert_eq!(f_i, f_c);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue