diff options
author | pommicket <pommicket@gmail.com> | 2022-12-14 16:16:57 -0500 |
---|---|---|
committer | pommicket <pommicket@gmail.com> | 2022-12-14 16:16:57 -0500 |
commit | eff66f8056b01a732df9523cb3a3d06b2d69c750 (patch) | |
tree | be4f2bb7ea2dc765c0c7ded04be92993cab1ba4c /gen_random_test/src/lib.rs | |
parent | 3f77c9f224c935aa56793bd548944e991cd4b0cd (diff) |
nicer GenRandom
Diffstat (limited to 'gen_random_test/src/lib.rs')
-rw-r--r-- | gen_random_test/src/lib.rs | 77 |
1 files changed, 0 insertions, 77 deletions
diff --git a/gen_random_test/src/lib.rs b/gen_random_test/src/lib.rs deleted file mode 100644 index 0d2b1cc..0000000 --- a/gen_random_test/src/lib.rs +++ /dev/null @@ -1,77 +0,0 @@ -#[cfg(test)] -mod tests { - extern crate gen_random; - extern crate gen_random_proc_macro; - extern crate rand; - use gen_random::{gen_thread_random_vec, GenRandom}; - 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 = 10] - Empty, - #[prob = 90] - Cons(f32, Box<LinkedList>), - } - - #[derive(GenRandom, Debug)] - struct ScaleBias { - #[bias = 1.0] - #[scale = 10.0] - a: f32, - #[bias = 2.0] - #[scale = 0.0] - b: f32, - } - - #[test] - fn basic() { - let tests1: Vec<Test1> = gen_thread_random_vec(10); - println!("{tests1:?}"); - } - - #[test] - fn many_types_of_variants() { - let tests2: Vec<Test2> = gen_thread_random_vec(10); - println!("{tests2:?}"); - } - - #[test] - fn linked_list() { - let ll = LinkedList::gen_thread_random(); - println!("{ll:?}"); - } - - #[test] - fn scale_bias() { - let sb: Vec<ScaleBias> = gen_thread_random_vec(10); - println!("{sb:?}"); - for x in sb.iter() { - if x.a < 1.0 || x.a > 11.0 { - panic!("a field should be between 1 and 11; got {}", x.a); - } - if x.b != 2.0 { - panic!("b field should be exactly 2; got {}", x.b); - } - } - } -} |