1use serde_json::{json, Value};
2
3use antithesis_sdk::prelude::*;
4
5#[allow(dead_code)]
6fn random_demo() {
7 println!("fuzz_get_random() => {}", random::get_random());
9
10 let choices: Vec<&str> = vec!["abc", "def", "xyz", "qrs"];
12 let nchoices = 10;
13 print!("{nchoices} Choices: ");
14 for n in 0..nchoices {
15 let z = random::random_choice(choices.as_slice());
16 if n > 0 {
17 print!(" ,");
18 }
19 match z {
20 Some(s) => print!("'{s}'"),
21 None => print!("()"),
22 };
23 }
24 println!();
25}
26
27#[allow(dead_code)]
28fn lifecycle_demo() {
29 let bird_value: Value = json!({
31 "name": "Tweety Bird",
32 "age": 4,
33 "phones": [
34 "+1 9734970340"
35 ]
36 });
37 let cat_value: Value = json!({
38 "name": "Meow Cat",
39 "age": 11,
40 "phones": [
41 "+1 2126581356",
42 "+1 2126581384"
43 ]
44 });
45
46 let tiger: Value = json!(2457);
47 lifecycle::setup_complete(&tiger);
48 lifecycle::setup_complete(&bird_value);
49 lifecycle::setup_complete(&cat_value);
50
51 let info_value: Value = json!({
53 "month": "January",
54 "day": 32
55 });
56 lifecycle::send_event("user_info", &info_value);
57}
58
59fn assert_demo() {
60 let details = json!({"things": 13});
62 assert_always!(true, "Things 777 look good", &details);
63
64 let details = json!({"more things": "red and blue"});
66 assert_always_or_unreachable!(true, "A few colors", &details);
67
68 let details = json!({"notes": [1,2,3,4,5]});
70 assert_sometimes!(false, "Notes have small values", &details);
71
72 for i in 0..4 {
74 let details =
75 json!({"got here": {"name": "somewhere", "scores": [i*10,(i+1)*10,(i+2)*10]}});
76 assert_reachable!("Someplace we need to be", &details);
77 }
78
79 let details = json!({"impossible!": {"name": "trouble", "weights": [100,200,300]}});
81 assert_unreachable!("Impossible to get here", &details);
82
83 assert_always_greater_than!(3, 100, "not right");
84 assert_sometimes_greater_than_or_equal_to!(3, 100, "not right");
85
86 assert_sometimes_all!({a: true, b: false}, "not all right");
87}
88
89pub fn main() {
90 antithesis_init();
91 antithesis_init();
92 antithesis_init();
93
94 random_demo();
95
96 lifecycle_demo();
97
98 assert_demo();
99}