diff --git a/Code/itf/tests/consensus.rs b/Code/itf/tests/consensus.rs index 6777ef01e..9eac81275 100644 --- a/Code/itf/tests/consensus.rs +++ b/Code/itf/tests/consensus.rs @@ -1,13 +1,18 @@ +use glob::glob; + use malachite_itf::consensus::State; -use rstest::rstest; -use std::path::PathBuf; -#[rstest] -fn test_itf(#[files("tests/fixtures/consensus/*.json")] json_fixture: PathBuf) { - println!("Parsing {json_fixture:?}"); +#[test] +fn test_itf() { + for json_fixture in glob("tests/fixtures/consensus/*.json") + .expect("Failed to read glob pattern") + .flatten() + { + println!("Parsing {json_fixture:?}"); - let json = std::fs::read_to_string(&json_fixture).unwrap(); - let state = itf::trace_from_str::(&json).unwrap(); + let json = std::fs::read_to_string(&json_fixture).unwrap(); + let state = itf::trace_from_str::(&json).unwrap(); - dbg!(state); + dbg!(state); + } } diff --git a/Code/itf/tests/votekeeper.rs b/Code/itf/tests/votekeeper.rs index 88d2a2c5c..ee47d2e9b 100644 --- a/Code/itf/tests/votekeeper.rs +++ b/Code/itf/tests/votekeeper.rs @@ -1,24 +1,44 @@ -use std::path::PathBuf; - -use malachite_itf::votekeeper::State; - -use rstest::rstest; - #[path = "votekeeper/runner.rs"] pub mod runner; #[path = "votekeeper/utils.rs"] pub mod utils; -use runner::{vote_keeper_runner, VoteKeeperRunner}; +use glob::glob; +use rand::rngs::StdRng; +use rand::SeedableRng; + +use malachite_itf::votekeeper::State; +use malachite_test::{Address, PrivateKey}; + +use runner::VoteKeeperRunner; +use utils::ADDRESSES; + +const RANDOM_SEED: u64 = 0x42; + +#[test] +fn test_itf() { + for json_fixture in glob("tests/fixtures/votekeeper/*.itf.json") + .expect("Failed to read glob pattern") + .flatten() + { + println!("Parsing {json_fixture:?}"); + + let json = std::fs::read_to_string(&json_fixture).unwrap(); + let trace = itf::trace_from_str::(&json).unwrap(); + + let mut rng = StdRng::seed_from_u64(RANDOM_SEED); -#[rstest] -fn test_itf( - #[files("tests/fixtures/votekeeper/*.itf.json")] json_fixture: PathBuf, - vote_keeper_runner: VoteKeeperRunner, -) { - println!("Parsing {json_fixture:?}"); + // build mapping from model addresses to real addresses + let vote_keeper_runner = VoteKeeperRunner { + address_map: ADDRESSES + .iter() + .map(|&name| { + let pk = PrivateKey::generate(&mut rng).public_key(); + (name.into(), Address::from_public_key(&pk)) + }) + .collect(), + }; - let json = std::fs::read_to_string(&json_fixture).unwrap(); - let trace = itf::trace_from_str::(&json).unwrap(); - trace.run_on(vote_keeper_runner).unwrap(); + trace.run_on(vote_keeper_runner).unwrap(); + } } diff --git a/Code/itf/tests/votekeeper/runner.rs b/Code/itf/tests/votekeeper/runner.rs index 7588365ff..b8657e71b 100644 --- a/Code/itf/tests/votekeeper/runner.rs +++ b/Code/itf/tests/votekeeper/runner.rs @@ -1,23 +1,19 @@ use std::collections::HashMap; -use rand::rngs::StdRng; -use rand::SeedableRng; - use malachite_common::{Context, Round, Value}; use malachite_itf::votekeeper::State; -use malachite_test::{Address, Height, PrivateKey, TestContext, Vote}; +use malachite_test::{Address, Height, TestContext, Vote}; use malachite_vote::{ keeper::{Message, VoteKeeper}, ThresholdParams, }; use itf::Runner as ItfRunner; -use rstest::fixture; -use super::utils::{check_votes, value_from_model, ADDRESSES}; +use super::utils::{check_votes, value_from_model}; pub struct VoteKeeperRunner { - address_map: HashMap, + pub address_map: HashMap, } impl ItfRunner for VoteKeeperRunner { @@ -181,19 +177,3 @@ impl ItfRunner for VoteKeeperRunner { Ok(true) } } - -#[fixture] -pub fn vote_keeper_runner() -> VoteKeeperRunner { - let mut rng = StdRng::seed_from_u64(0x42); - - // build mapping from model addresses to real addresses - VoteKeeperRunner { - address_map: ADDRESSES - .iter() - .map(|&name| { - let pk = PrivateKey::generate(&mut rng).public_key(); - (name.into(), Address::from_public_key(&pk)) - }) - .collect(), - } -}