Skip to content

Commit c2ec257

Browse files
committed
Add a vector test for random_odd_integer()
1 parent f4dab98 commit c2ec257

File tree

1 file changed

+22
-1
lines changed

1 file changed

+22
-1
lines changed

src/hazmat/sieve.rs

+22-1
Original file line numberDiff line numberDiff line change
@@ -400,7 +400,7 @@ mod tests {
400400
use alloc::vec::Vec;
401401
use core::num::NonZero;
402402

403-
use crypto_bigint::U64;
403+
use crypto_bigint::{U256, U64};
404404
use num_prime::nt_funcs::factorize64;
405405
use rand_chacha::ChaCha8Rng;
406406
use rand_core::{OsRng, SeedableRng, TryRngCore};
@@ -614,4 +614,25 @@ mod tests {
614614
.get();
615615
assert_eq!(x, U64::ONE);
616616
}
617+
618+
#[test]
619+
fn platform_independence() {
620+
let mut rng = ChaCha8Rng::from_seed([7u8; 32]);
621+
622+
let x = random_odd_integer::<U256, _>(&mut rng, NonZero::new(200).unwrap(), SetBits::TwoMsb)
623+
.unwrap()
624+
.get();
625+
assert_eq!(
626+
x,
627+
U256::from_be_hex("00000000000000DAD782090CD9F9744AE64381DA8B37F5D4E4D0CB593FBC1E39")
628+
);
629+
630+
let x = random_odd_integer::<U256, _>(&mut rng, NonZero::new(220).unwrap(), SetBits::TwoMsb)
631+
.unwrap()
632+
.get();
633+
assert_eq!(
634+
x,
635+
U256::from_be_hex("000000000F6547964157E35960CE28A6F256EF9A53F6671C19A2D683053F65B5")
636+
);
637+
}
617638
}

0 commit comments

Comments
 (0)