From ea20b22d1289eaecb6acaa1a09b453e5c262b634 Mon Sep 17 00:00:00 2001 From: nicoo Date: Wed, 20 Jan 2021 19:10:07 +0100 Subject: [PATCH] factor::numeric::gcd: Refactor `divisor` test Should be clearer; does not handle the `gcd(0, 0)` case, which is already covered by the `zero` test. --- src/uu/factor/src/numeric/gcd.rs | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/src/uu/factor/src/numeric/gcd.rs b/src/uu/factor/src/numeric/gcd.rs index 96a0366a2..36ad833a6 100644 --- a/src/uu/factor/src/numeric/gcd.rs +++ b/src/uu/factor/src/numeric/gcd.rs @@ -76,14 +76,13 @@ mod tests { gcd(0, a) == a } - fn divisor(a: u64, b: u64) -> bool { - // Test that gcd(a, b) divides a and b + fn divisor(a: u64, b: u64) -> () { + // Test that gcd(a, b) divides a and b, unless a == b == 0 + if a == 0 && b == 0 { return; } + let g = gcd(a, b); - if g != 0 { - a % g == 0 && b % g == 0 - } else { - a == 0 && b == 0 // for g == 0 - } + assert_eq!(a % g, 0); + assert_eq!(b % g, 0); } fn commutative(a: u64, b: u64) -> bool {