factor: Make random Factors instance generatable for tests
@@ -239,9 +239,13 @@ mod tests {
}
#[cfg(test)]
-impl quickcheck::Arbitrary for Factors {
- fn arbitrary<G: quickcheck::Gen>(gen: &mut G) -> Self {
- use rand::Rng;
+use rand::{
+ distributions::{Distribution, Standard},
+ Rng,
+};
+#[cfg(test)]
+impl Distribution<Factors> for Standard {
+ fn sample<R: Rng + ?Sized>(&self, rng: &mut R) -> Factors {
let mut f = Factors::one();
let mut g = 1u64;
let mut n = u64::MAX;
@@ -252,7 +256,7 @@ impl quickcheck::Arbitrary for Factors {
// See Generating Random Factored Numbers, Easily, J. Cryptology (2003)
'attempt: loop {
while n > 1 {
- n = gen.gen_range(1, n);
+ n = rng.gen_range(1, n);
if miller_rabin::is_prime(n) {
if let Some(h) = g.checked_mul(n) {
f.push(n);
@@ -269,6 +273,13 @@ impl quickcheck::Arbitrary for Factors {
}
}
+#[cfg(test)]
+impl quickcheck::Arbitrary for Factors {
+ fn arbitrary<G: quickcheck::Gen>(g: &mut G) -> Self {
+ g.gen()
+ }
+}
+
#[cfg(test)]
impl std::ops::BitXor<Exponent> for Factors {
type Output = Self;
