From 774feb0a40bfe118c55285e536c0f41459f0e5da Mon Sep 17 00:00:00 2001 From: nicoo Date: Wed, 24 Jun 2020 17:50:38 +0200 Subject: [PATCH] factor::numeric: Generalise tests for Arithmetic trait --- src/uu/factor/src/numeric.rs | 41 ++++++++++++++++++++++++++++++------ 1 file changed, 34 insertions(+), 7 deletions(-) diff --git a/src/uu/factor/src/numeric.rs b/src/uu/factor/src/numeric.rs index 5934ab749..c6b40aa9b 100644 --- a/src/uu/factor/src/numeric.rs +++ b/src/uu/factor/src/numeric.rs @@ -328,11 +328,10 @@ mod tests { test_inverter::() } - #[test] - fn test_montgomery_add() { + fn test_add() { for n in 0..100 { let n = 2 * n + 1; - let m = Montgomery::new(n); + let m = A::new(n); for x in 0..n { let m_x = m.from_u64(x); for y in 0..=x { @@ -345,10 +344,19 @@ mod tests { } #[test] - fn test_montgomery_mult() { + fn test_add_m32() { + test_add::>() + } + + #[test] + fn test_add_m64() { + test_add::>() + } + + fn test_mult() { for n in 0..100 { let n = 2 * n + 1; - let m = Montgomery::new(n); + let m = A::new(n); for x in 0..n { let m_x = m.from_u64(x); for y in 0..=x { @@ -360,14 +368,33 @@ mod tests { } #[test] - fn test_montgomery_roundtrip() { + fn test_mult_m32() { + test_mult::>() + } + + #[test] + fn test_mult_m64() { + test_mult::>() + } + + fn test_roundtrip() { for n in 0..100 { let n = 2 * n + 1; - let m = Montgomery::new(n); + let m = A::new(n); for x in 0..n { let x_ = m.from_u64(x); assert_eq!(x, m.to_u64(x_)); } } } + + #[test] + fn test_roundtrip_m32() { + test_roundtrip::>() + } + + #[test] + fn test_roundtrip_m64() { + test_roundtrip::>() + } }