mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-29 12:07:46 +00:00
tests ~ (factor) refactor divisor()
to return quickcheck::TestResult
- return standard quickcheck results - drop `a == 0 && b == 0` from test domain via TestResult::discard() - avoid divide by zero panics - ref: #1589
This commit is contained in:
parent
740d8e9bc5
commit
363453f5e4
1 changed files with 4 additions and 5 deletions
|
@ -52,7 +52,7 @@ pub fn gcd(mut u: u64, mut v: u64) -> u64 {
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
use quickcheck::quickcheck;
|
use quickcheck::{quickcheck, TestResult};
|
||||||
|
|
||||||
quickcheck! {
|
quickcheck! {
|
||||||
fn euclidean(a: u64, b: u64) -> bool {
|
fn euclidean(a: u64, b: u64) -> bool {
|
||||||
|
@ -76,13 +76,12 @@ mod tests {
|
||||||
gcd(0, a) == a
|
gcd(0, a) == a
|
||||||
}
|
}
|
||||||
|
|
||||||
fn divisor(a: u64, b: u64) -> () {
|
fn divisor(a: u64, b: u64) -> TestResult {
|
||||||
// Test that gcd(a, b) divides a and b, unless a == b == 0
|
// Test that gcd(a, b) divides a and b, unless a == b == 0
|
||||||
if a == 0 && b == 0 { return; }
|
if a == 0 && b == 0 { return TestResult::discard(); } // restrict test domain to !(a == b == 0)
|
||||||
|
|
||||||
let g = gcd(a, b);
|
let g = gcd(a, b);
|
||||||
assert_eq!(a % g, 0);
|
TestResult::from_bool( g != 0 && a % g == 0 && b % g == 0 )
|
||||||
assert_eq!(b % g, 0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn commutative(a: u64, b: u64) -> bool {
|
fn commutative(a: u64, b: u64) -> bool {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue