mirror of
https://github.com/uutils/coreutils
synced 2024-11-17 18:28:18 +00:00
factor::factor: Add integration tests
This commit is contained in:
parent
bada7530fb
commit
e91155519a
1 changed files with 26 additions and 0 deletions
|
@ -47,6 +47,13 @@ impl Factors {
|
||||||
fn push(&mut self, prime: u64) {
|
fn push(&mut self, prime: u64) {
|
||||||
self.add(prime, 1)
|
self.add(prime, 1)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
fn product(&self) -> u64 {
|
||||||
|
self.f
|
||||||
|
.iter()
|
||||||
|
.fold(1, |acc, (p, exp)| acc * p.pow(*exp as u32))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ops::MulAssign<Factors> for Factors {
|
impl ops::MulAssign<Factors> for Factors {
|
||||||
|
@ -132,3 +139,22 @@ pub fn uumain(args: Vec<String>) -> i32 {
|
||||||
}
|
}
|
||||||
0
|
0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod tests {
|
||||||
|
use super::factor;
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn factor_recombines_small() {
|
||||||
|
assert!((1..10_000)
|
||||||
|
.map(|i| 2 * i + 1)
|
||||||
|
.all(|i| factor(i).product() == i));
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn factor_recombines_overflowing() {
|
||||||
|
assert!((0..250)
|
||||||
|
.map(|i| 2 * i + 2u64.pow(32) + 1)
|
||||||
|
.all(|i| factor(i).product() == i));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue