Add tests for advancing PCG generators

A simple test to check the values after 20 steps.
This commit is contained in:
Mark Wong
2021-04-10 17:35:00 -07:00
parent 91d7699a69
commit 9017732011
3 changed files with 36 additions and 0 deletions
+12
View File
@@ -1,6 +1,18 @@
use rand_core::{RngCore, SeedableRng};
use rand_pcg::{Lcg128Xsl64, Pcg64};
#[test]
fn test_lcg128xsl64_advancing() {
let seed = Default::default();
let mut rng1 = Lcg128Xsl64::from_seed(seed);
let mut rng2 = Lcg128Xsl64::from_seed(seed);
for _ in 0..20 {
rng1.next_u64();
}
rng2.advance(20);
assert_eq!(rng1.next_u64(), rng2.next_u64());
}
#[test]
fn test_lcg128xsl64_construction() {
// Test that various construction techniques produce a working RNG.
+12
View File
@@ -1,6 +1,18 @@
use rand_core::{RngCore, SeedableRng};
use rand_pcg::{Lcg64Xsh32, Pcg32};
#[test]
fn test_lcg64xsh32_advancing() {
let seed = Default::default();
let mut rng1 = Lcg64Xsh32::from_seed(seed);
let mut rng2 = Lcg64Xsh32::from_seed(seed);
for _ in 0..20 {
rng1.next_u64();
}
rng2.advance(20);
assert_eq!(rng1.next_u64(), rng2.next_u64());
}
#[test]
fn test_lcg64xsh32_construction() {
// Test that various construction techniques produce a working RNG.
+12
View File
@@ -1,6 +1,18 @@
use rand_core::{RngCore, SeedableRng};
use rand_pcg::{Mcg128Xsl64, Pcg64Mcg};
#[test]
fn test_mcg128xsl64_advancing() {
let seed = Default::default();
let mut rng1 = Mcg128Xsl64::from_seed(seed);
let mut rng2 = Mcg128Xsl64::from_seed(seed);
for _ in 0..20 {
rng1.next_u64();
}
rng2.advance(20);
assert_eq!(rng1.next_u64(), rng2.next_u64());
}
#[test]
fn test_mcg128xsl64_construction() {
// Test that various construction techniques produce a working RNG.