From eb0958ae5a9c2a214bdeda808f0a08bea430d0be Mon Sep 17 00:00:00 2001 From: Narthana Epa Date: Sat, 6 Jul 2024 14:33:19 +1000 Subject: [PATCH] Allow overriding seed --- src/passphrase.rs | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/src/passphrase.rs b/src/passphrase.rs index 247f1bf..28776b5 100644 --- a/src/passphrase.rs +++ b/src/passphrase.rs @@ -31,7 +31,7 @@ mod test { use rand_chacha::{rand_core::SeedableRng, ChaCha8Rng}; use rayon::iter::{IndexedParallelIterator, IntoParallelRefIterator, ParallelIterator}; use statrs::distribution::{ChiSquared, ContinuousCDF}; - use std::collections::HashMap; + use std::{collections::HashMap, env}; // This test file has W = 4 words, which can have 24 permutations const W: usize = 4; @@ -45,10 +45,15 @@ mod test { let batches = std::thread::available_parallelism().unwrap(); let words = words::list(Some("src/fixtures/test")).unwrap(); - let seed = std::time::SystemTime::now() - .duration_since(std::time::UNIX_EPOCH) - .unwrap() - .as_secs(); + let seed = env::var("TETS_SEED") + .map_err(|_| eyre::eyre!("TEST_SEED environment variable not set")) + .and_then(|s| s.parse().map_err(|_| eyre::eyre!("invalid SEED"))) + .unwrap_or_else(|_| { + std::time::SystemTime::now() + .duration_since(std::time::UNIX_EPOCH) + .unwrap() + .as_secs() + }); eprintln!("Available parallelism: {batches}"); eprintln!("Number of samples: {N}");