mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-30 12:37:49 +00:00
factor::numeric::tests: Use a macro to instantiate every test
This commit is contained in:
parent
cbcc760f83
commit
7a1b86c9c2
3 changed files with 52 additions and 46 deletions
26
Cargo.lock
generated
26
Cargo.lock
generated
|
@ -649,6 +649,23 @@ dependencies = [
|
|||
"pkg-config 0.3.17 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "paste"
|
||||
version = "0.1.18"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"paste-impl 0.1.18 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"proc-macro-hack 0.5.16 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "paste-impl"
|
||||
version = "0.1.18"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"proc-macro-hack 0.5.16 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "pkg-config"
|
||||
version = "0.3.17"
|
||||
|
@ -668,6 +685,11 @@ name = "ppv-lite86"
|
|||
version = "0.2.8"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
|
||||
[[package]]
|
||||
name = "proc-macro-hack"
|
||||
version = "0.5.16"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
|
||||
[[package]]
|
||||
name = "proc-macro2"
|
||||
version = "1.0.18"
|
||||
|
@ -1336,6 +1358,7 @@ name = "uu_factor"
|
|||
version = "0.0.1"
|
||||
dependencies = [
|
||||
"num-traits 0.2.12 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"paste 0.1.18 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"quickcheck 0.9.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"rand 0.5.6 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"uucore 0.0.4 (git+https://github.com/uutils/uucore.git?branch=canary)",
|
||||
|
@ -2254,9 +2277,12 @@ dependencies = [
|
|||
"checksum numtoa 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "b8f8bdf33df195859076e54ab11ee78a1b208382d3a26ec40d142ffc1ecc49ef"
|
||||
"checksum onig 4.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "8518fcb2b1b8c2f45f0ad499df4fda6087fc3475ca69a185c173b8315d2fb383"
|
||||
"checksum onig_sys 69.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "388410bf5fa341f10e58e6db3975f4bea1ac30247dd79d37a9e5ced3cb4cc3b0"
|
||||
"checksum paste 0.1.18 (registry+https://github.com/rust-lang/crates.io-index)" = "45ca20c77d80be666aef2b45486da86238fabe33e38306bd3118fe4af33fa880"
|
||||
"checksum paste-impl 0.1.18 (registry+https://github.com/rust-lang/crates.io-index)" = "d95a7db200b97ef370c8e6de0088252f7e0dfff7d047a28528e47456c0fc98b6"
|
||||
"checksum pkg-config 0.3.17 (registry+https://github.com/rust-lang/crates.io-index)" = "05da548ad6865900e60eaba7f589cc0783590a92e940c26953ff81ddbab2d677"
|
||||
"checksum platform-info 0.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "f2fd076acdc7a98374de6e300bf3af675997225bef21aecac2219553f04dd7e8"
|
||||
"checksum ppv-lite86 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)" = "237a5ed80e274dbc66f86bd59c1e25edc039660be53194b5fe0a482e0f2612ea"
|
||||
"checksum proc-macro-hack 0.5.16 (registry+https://github.com/rust-lang/crates.io-index)" = "7e0456befd48169b9f13ef0f0ad46d492cf9d2dbb918bcf38e01eed4ce3ec5e4"
|
||||
"checksum proc-macro2 1.0.18 (registry+https://github.com/rust-lang/crates.io-index)" = "beae6331a816b1f65d04c45b078fd8e6c93e8071771f41b8163255bbd8d7c8fa"
|
||||
"checksum quick-error 1.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "a1d01941d82fa2ab50be1e79e6714289dd7cde78eba4c074bc5a4374f650dfe0"
|
||||
"checksum quickcheck 0.9.2 (registry+https://github.com/rust-lang/crates.io-index)" = "a44883e74aa97ad63db83c4bf8ca490f02b2fc02f92575e720c8551e843c945f"
|
||||
|
|
|
@ -24,6 +24,7 @@ uucore = { version="0.0.4", package="uucore", git="https://github.com/uutils/uuc
|
|||
uucore_procs = { version="0.0.4", package="uucore_procs", git="https://github.com/uutils/uucore.git", branch="canary" }
|
||||
|
||||
[dev-dependencies]
|
||||
paste = "0.1.18"
|
||||
quickcheck = "0.9.2"
|
||||
|
||||
[[bin]]
|
||||
|
|
|
@ -308,6 +308,21 @@ pub(crate) fn modular_inverse<T: Int>(a: T) -> T {
|
|||
mod tests {
|
||||
use super::*;
|
||||
|
||||
macro_rules! parametrized_check {
|
||||
( $f:ident ) => {
|
||||
paste::item! {
|
||||
#[test]
|
||||
fn [< $f _ u32 >]() {
|
||||
$f::<u32>()
|
||||
}
|
||||
#[test]
|
||||
fn [< $f _ u64 >]() {
|
||||
$f::<u64>()
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
fn test_inverter<T: Int>() {
|
||||
// All odd integers from 1 to 20 000
|
||||
let one = T::from(1).unwrap();
|
||||
|
@ -318,21 +333,12 @@ mod tests {
|
|||
|
||||
assert!(test_values.all(|x| x.wrapping_mul(&modular_inverse(x)) == one));
|
||||
}
|
||||
parametrized_check!(test_inverter);
|
||||
|
||||
#[test]
|
||||
fn test_inverter_u32() {
|
||||
test_inverter::<u32>()
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_inverter_u64() {
|
||||
test_inverter::<u64>()
|
||||
}
|
||||
|
||||
fn test_add<A: Arithmetic>() {
|
||||
fn test_add<A: DoubleInt>() {
|
||||
for n in 0..100 {
|
||||
let n = 2 * n + 1;
|
||||
let m = A::new(n);
|
||||
let m = Montgomery::<A>::new(n);
|
||||
for x in 0..n {
|
||||
let m_x = m.from_u64(x);
|
||||
for y in 0..=x {
|
||||
|
@ -343,21 +349,12 @@ mod tests {
|
|||
}
|
||||
}
|
||||
}
|
||||
parametrized_check!(test_add);
|
||||
|
||||
#[test]
|
||||
fn test_add_m32() {
|
||||
test_add::<Montgomery<u32>>()
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_add_m64() {
|
||||
test_add::<Montgomery<u64>>()
|
||||
}
|
||||
|
||||
fn test_mult<A: Arithmetic>() {
|
||||
fn test_mult<A: DoubleInt>() {
|
||||
for n in 0..100 {
|
||||
let n = 2 * n + 1;
|
||||
let m = A::new(n);
|
||||
let m = Montgomery::<A>::new(n);
|
||||
for x in 0..n {
|
||||
let m_x = m.from_u64(x);
|
||||
for y in 0..=x {
|
||||
|
@ -367,35 +364,17 @@ mod tests {
|
|||
}
|
||||
}
|
||||
}
|
||||
parametrized_check!(test_mult);
|
||||
|
||||
#[test]
|
||||
fn test_mult_m32() {
|
||||
test_mult::<Montgomery<u32>>()
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_mult_m64() {
|
||||
test_mult::<Montgomery<u64>>()
|
||||
}
|
||||
|
||||
fn test_roundtrip<A: Arithmetic>() {
|
||||
fn test_roundtrip<A: DoubleInt>() {
|
||||
for n in 0..100 {
|
||||
let n = 2 * n + 1;
|
||||
let m = A::new(n);
|
||||
let m = Montgomery::<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::<Montgomery<u32>>()
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_roundtrip_m64() {
|
||||
test_roundtrip::<Montgomery<u64>>()
|
||||
}
|
||||
parametrized_check!(test_roundtrip);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue