num-bigint-dig/tests/torture.rs
Josh Stone 8964eb9887 Chop the tests up
The test modules were getting huge, and some of its functions were
actually a huge amount of code due to macros, causing tests to take a
long time just to compile.  They are now separated into a few different
tests, and the scalar macros especially are now expanded more sparingly
in just a few `check()` functions.

Test compile times for me went from about 25 seconds to 1.5s in debug
mode, and from 300 seconds (!) to about 8s in release mode.
2018-02-26 22:13:25 -08:00

46 lines
969 B
Rust

#![cfg(feature = "rand")]
extern crate num_bigint;
extern crate num_traits;
extern crate rand;
use num_bigint::RandBigInt;
use num_traits::Zero;
use rand::{SeedableRng, StdRng, Rng};
fn test_mul_divide_torture_count(count: usize) {
let bits_max = 1 << 12;
let seed: &[_] = &[1, 2, 3, 4];
let mut rng: StdRng = SeedableRng::from_seed(seed);
for _ in 0..count {
// Test with numbers of random sizes:
let xbits = rng.gen_range(0, bits_max);
let ybits = rng.gen_range(0, bits_max);
let x = rng.gen_biguint(xbits);
let y = rng.gen_biguint(ybits);
if x.is_zero() || y.is_zero() {
continue;
}
let prod = &x * &y;
assert_eq!(&prod / &x, y);
assert_eq!(&prod / &y, x);
}
}
#[test]
fn test_mul_divide_torture() {
test_mul_divide_torture_count(1000);
}
#[test]
#[ignore]
fn test_mul_divide_torture_long() {
test_mul_divide_torture_count(1000000);
}