@@ -42,6 +42,7 @@ often enough to spot the issue immediately.
4242` select ` is how you define structured choices:
4343
4444``` rust
45+ # fn prop (src : & mut chaos_theory :: Source ) {
4546src . select (" action" , & [" insert" , " remove" , " get" ], | src , action , _ix | {
4647 match action {
4748 " insert" => { /* ... */ }
@@ -50,6 +51,7 @@ src.select("action", &["insert", "remove", "get"], |src, action, _ix| {
5051 _ => unreachable! (),
5152 }
5253});
54+ # }
5355```
5456
5557You should not encode a variant choice as ` any::<u8>() ` or a random number. Use
@@ -62,10 +64,12 @@ You should not encode a variant choice as `any::<u8>()` or a random number. Use
6264``` rust
6365use chaos_theory :: Effect ;
6466
67+ # fn prop (src : & mut chaos_theory :: Source ) {
6568src . repeat (" step" , | src | {
6669 // perform one step
6770 Effect :: Success
6871});
72+ # }
6973```
7074
7175` Effect ` matters:
@@ -81,10 +85,12 @@ Honest `Effect` values make exploration and minimization much more efficient.
8185Don't do this:
8286
8387``` rust
88+ # fn prop (src : & mut chaos_theory :: Source ) {
8489let n : usize = src . any (" n" );
8590for _ in 0 .. n {
8691 /* use src here */
8792}
93+ # }
8894```
8995
9096Use ` repeat ` instead. ` repeat ` is structured and minimizes well, while manual
@@ -93,8 +99,10 @@ random loops are opaque and minimize poorly.
9399Another version of the same issue is:
94100
95101``` rust
102+ # fn prop (src : & mut chaos_theory :: Source ) {
96103let do_it : bool = src . any (" do_it" );
97104if do_it { /* use src here */ }
105+ # }
98106```
99107
100108Prefer ` maybe ` or ` select ` so the execution shape is tracked structurally.
@@ -113,14 +121,17 @@ The most common pattern is:
113121Example shape:
114122
115123``` rust
124+ # fn prop (src : & mut chaos_theory :: Source ) {
116125src . repeat (" step" , | src | {
117126 src . select (" action" , & [" insert" , " remove" , " get" ], | src , action , _ | {
118127 // apply action to SUT
119128 // apply action to model
120129 // assert invariants
121130 // return Effect for the chosen action
131+ # todo! ()
122132 })
123133});
134+ # }
124135```
125136
126137Nested ` repeat ` and ` select ` are normal and encouraged for complex stateful systems.
@@ -155,7 +166,9 @@ are not required for everyday property tests.
155166You will spend most of your time doing this:
156167
157168``` rust
169+ # fn prop (src : & mut chaos_theory :: Source ) {
158170let v : Vec <String > = src . any (" v" );
171+ # }
159172```
160173
161174### Built-Ins (` make::* ` )
@@ -195,10 +208,12 @@ Useful combinators:
195208Use seeds when you have real examples that should guide exploration:
196209
197210``` rust
198- use chaos_theory :: make;
199-
211+ # use chaos_theory :: {make, Source , Generator as _};
212+ # #[cfg(feature = " regex" )]
213+ # fn prop (src : & mut Source ) {
200214let cities = [" Tokyo" . to_owned (), " Moscow" . to_owned (), " Shanghai" . to_owned ()];
201215let city = make :: string_matching (" [A-Za-z '-]+" , true ). seeded (& cities , true );
216+ # }
202217```
203218
204219Built-in generators already have seeds pre-configured internally,
@@ -227,6 +242,7 @@ struct Point {
227242 y : i32 ,
228243}
229244
245+ #[derive(Debug )]
230246struct PointGen ;
231247
232248impl Generator for PointGen {
@@ -254,6 +270,7 @@ enum Op {
254270 Reset ,
255271}
256272
273+ #[derive(Debug )]
257274struct OpGen ;
258275
259276impl Generator for OpGen {
@@ -293,6 +310,7 @@ Use `repeat` to build the collection:
293310``` rust
294311use chaos_theory :: {Arbitrary , Effect , Generator , SourceRaw };
295312
313+ #[derive(Debug )]
296314struct BytesGen ;
297315
298316impl Generator for BytesGen {
0 commit comments