summaryrefslogtreecommitdiff
path: root/gen_random_test/src/lib.rs
diff options
context:
space:
mode:
authorpommicket <pommicket@gmail.com>2022-12-14 12:45:48 -0500
committerpommicket <pommicket@gmail.com>2022-12-14 12:45:48 -0500
commit3265cb676c5c87fd624f59aaf3ca89d947df8cda (patch)
tree0bc94cbdddb9cecfc6205f834428e6efafcdb69a /gen_random_test/src/lib.rs
parent3f839f2ec08ffbb75bee391202e7e0d7432d97e0 (diff)
GenRandom
Diffstat (limited to 'gen_random_test/src/lib.rs')
-rw-r--r--gen_random_test/src/lib.rs63
1 files changed, 63 insertions, 0 deletions
diff --git a/gen_random_test/src/lib.rs b/gen_random_test/src/lib.rs
new file mode 100644
index 0000000..faca129
--- /dev/null
+++ b/gen_random_test/src/lib.rs
@@ -0,0 +1,63 @@
+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::*;
+
+ #[test]
+ fn basic() {
+ let mut rng = rand::thread_rng();
+
+ let tests1: Vec<_> = (0..10).map(|_| {
+ Test1::gen_random(&mut rng)
+ }).collect();
+ 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();
+ println!("{tests2:?}");
+ }
+
+ #[test]
+ fn linked_list() {
+ let ll = LinkedList::gen_thread_random();
+ println!("{ll:?}");
+ }
+}