use proptest::{
prelude::{Arbitrary, Strategy},
strategy::ValueTree,
};
pub mod test_builder;
#[cfg(feature = "fuzz")]
pub mod fuzz;
pub trait ToValue {
type Params: Default;
fn arbitrary_value(seed: u128) -> Self;
fn arbitrary_value_with(params: Self::Params, seed: u128) -> Self;
}
impl<T: Arbitrary> ToValue for T {
type Params = <T as Arbitrary>::Parameters;
fn arbitrary_value(seed: u128) -> Self {
Self::arbitrary_value_with(Self::Params::default(), seed)
}
fn arbitrary_value_with(params: Self::Params, seed: u128) -> Self {
let rng = proptest::test_runner::TestRng::from_seed(
proptest::test_runner::RngAlgorithm::ChaCha,
&[seed.to_le_bytes(), [0; 16]].concat(),
);
let config = proptest::test_runner::Config {
failure_persistence: None,
..Default::default()
};
let mut runner = proptest::test_runner::TestRunner::new_with_rng(config, rng);
T::arbitrary_with(params)
.new_tree(&mut runner)
.unwrap()
.current()
}
}