Skip to content

Commit

Permalink
factor: ignore quickcheck tests using unhandled large vals
Browse files Browse the repository at this point in the history
  • Loading branch information
g-k committed Jan 25, 2022
1 parent e24ecea commit e6fdf07
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 9 deletions.
6 changes: 5 additions & 1 deletion src/uu/factor/src/miller_rabin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,11 @@ mod tests {

quickcheck! {
fn composites(i: u64, j: u64) -> bool {
i < 2 || j < 2 || !is_prime(i*j)
// TODO: #1559 factor n > 2^64 - 1
match i.checked_mul(j) {
Some(n) => i < 2 || j < 2 || !is_prime(n),
_ => true,
}
}
}
}
29 changes: 25 additions & 4 deletions src/uu/factor/src/numeric/gcd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
// * For the full copyright and license information, please view the LICENSE file
// * that was distributed with this source code.

// spell-checker:ignore (vars) kgcdab gcdac gcdbc

use std::cmp::min;
use std::mem::swap;

Expand Down Expand Up @@ -93,16 +95,35 @@ mod tests {
}

fn scalar_multiplication(a: u64, b: u64, k: u64) -> bool {
gcd(k * a, k * b) == k * gcd(a, b)
// TODO: #1559 factor n > 2^64 - 1
match (k.checked_mul(a), k.checked_mul(b), k.checked_mul(gcd(a, b))) {
(Some(ka), Some(kb), Some(kgcdab)) => gcd(ka, kb) == kgcdab,
_ => true
}
}

fn multiplicative(a: u64, b: u64, c: u64) -> bool {
// gcd(ab, c) = gcd(a, c) gcd(b, c) when a and b coprime
gcd(a, b) != 1 || gcd(a * b, c) == gcd(a, c) * gcd(b, c)
// TODO: #1559 factor n > 2^64 - 1
match (a.checked_mul(b), gcd(a, c).checked_mul(gcd(b, c))) {
(Some(ab), Some(gcdac_gcdbc)) => {
// gcd(ab, c) = gcd(a, c) gcd(b, c) when a and b coprime
gcd(a, b) != 1 || gcd(ab, c) == gcdac_gcdbc
},
_ => true,
}
}

fn linearity(a: u64, b: u64, k: u64) -> bool {
gcd(a + k * b, b) == gcd(a, b)
// TODO: #1559 factor n > 2^64 - 1
match k.checked_mul(b) {
Some(kb) => {
match a.checked_add(kb) {
Some(a_plus_kb) => gcd(a_plus_kb, b) == gcd(a, b),
_ => true,
}
}
_ => true,
}
}
}
}
12 changes: 8 additions & 4 deletions src/uu/factor/src/numeric/modular_inverse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,13 +63,17 @@ mod tests {

quickcheck! {
fn random_values_u32(n: u32) -> bool {
let n = 2 * n + 1;
modular_inverse(n).wrapping_mul(n) == 1
match 2_u32.checked_mul(n) {
Some(n) => modular_inverse(n + 1).wrapping_mul(n + 1) == 1,
_ => true,
}
}

fn random_values_u64(n: u64) -> bool {
let n = 2 * n + 1;
modular_inverse(n).wrapping_mul(n) == 1
match 2_u64.checked_mul(n) {
Some(n) => modular_inverse(n + 1).wrapping_mul(n + 1) == 1,
_ => true,
}
}
}
}

0 comments on commit e6fdf07

Please sign in to comment.