diff options
author | pommicket <pommicket@gmail.com> | 2022-12-14 13:08:08 -0500 |
---|---|---|
committer | pommicket <pommicket@gmail.com> | 2022-12-14 13:08:08 -0500 |
commit | 5a20cffba66caa71b495736f75031f69d09ba40b (patch) | |
tree | 92834986e8f8c7d1ab8947da52e649c90caac556 /gen_random_test/src/lib.rs | |
parent | 3265cb676c5c87fd624f59aaf3ca89d947df8cda (diff) |
more genrandom
Diffstat (limited to 'gen_random_test/src/lib.rs')
-rw-r--r-- | gen_random_test/src/lib.rs | 77 |
1 files changed, 34 insertions, 43 deletions
diff --git a/gen_random_test/src/lib.rs b/gen_random_test/src/lib.rs index faca129..00f5026 100644 --- a/gen_random_test/src/lib.rs +++ b/gen_random_test/src/lib.rs @@ -1,57 +1,48 @@ -extern crate rand; -extern crate gen_random_proc_macro; -extern crate gen_random; -use gen_random::GenRandom; -use gen_random_proc_macro::GenRandom; - -#[derive(GenRandom, Debug)] -enum Test1 { - #[prob = 0.2] - A(f32), - #[prob = 0.8] - B(f32) -} - -#[derive(GenRandom, Debug)] -#[allow(dead_code)] -enum Test2 { - #[prob = 0.1] - Variant1, - #[prob = 0.7] - Variant2 { x : f32, y: f64, z: Test1 }, - #[prob = 0.2] - Variant3(f32, Box<Test2>) -} - -#[derive(GenRandom, Debug)] -enum LinkedList { - #[prob = 0.1] - Empty, - #[prob = 0.9] - Cons(f32, Box<LinkedList>) -} - #[cfg(test)] mod tests { - use super::*; + extern crate rand; + extern crate gen_random_proc_macro; + extern crate gen_random; + use gen_random::{GenRandom, gen_thread_random_vec}; + use gen_random_proc_macro::GenRandom; + + #[derive(GenRandom, Debug)] + enum Test1 { + #[prob = 0.2] + A(f32), + #[prob = 0.8] + B(Option<f32>) + } + + #[derive(GenRandom, Debug)] + #[allow(dead_code)] + enum Test2 { + #[prob = 0.1] + Variant1, + #[prob = 0.7] + Variant2 { x : f32, y: f64, z: Test1 }, + #[prob = 0.2] + Variant3(f32, Box<Test2>) + } + + #[derive(GenRandom, Debug)] + enum LinkedList { + #[prob = 0.1] + Empty, + #[prob = 0.9] + Cons(f32, Box<LinkedList>) + } #[test] fn basic() { - let mut rng = rand::thread_rng(); - - let tests1: Vec<_> = (0..10).map(|_| { - Test1::gen_random(&mut rng) - }).collect(); + let tests1: Vec<Test1> = gen_thread_random_vec(10); println!("{tests1:?}"); } #[test] fn many_types_of_variants() { - let mut rng = rand::thread_rng(); - let tests2: Vec<_> = (0..10).map(|_| { - Test2::gen_random(&mut rng) - }).collect(); + let tests2: Vec<Test2> = gen_thread_random_vec(10); println!("{tests2:?}"); } |