@@ -250,6 +250,29 @@ impl<Msg> Drop for World<Msg> {
250250 }
251251}
252252
253+ fn run_test < Msg : Debug + PartialEq + Clone , F : Fn ( ) -> NodeHandle < Msg > > (
254+ number_of_nodes : u8 ,
255+ spawn : F ,
256+ property : impl Fn ( History < Msg > ) -> Result < ( ) , String > ,
257+ ) -> impl Fn ( & [ Reverse < Entry < Msg > > ] ) -> ( History < Msg > , Result < ( ) , String > ) {
258+ move |entries| {
259+ let node_handles: Vec < _ > = ( 1 ..=number_of_nodes)
260+ . map ( |i| ( format ! ( "n{}" , i) , spawn ( ) ) )
261+ . collect ( ) ;
262+
263+ let mut world = World :: new ( entries. to_vec ( ) , node_handles) ;
264+
265+ match world. run_world ( ) {
266+ Ok ( history) => {
267+ let history = History ( history. to_vec ( ) ) ;
268+ let result = property ( history. clone ( ) ) ;
269+ ( history, result)
270+ }
271+ Err ( ( reason, history) ) => ( History ( history. to_vec ( ) ) , Err ( reason) ) ,
272+ }
273+ }
274+ }
275+
253276pub fn simulate < Msg , F > (
254277 config : SimulateConfig ,
255278 spawn : F ,
@@ -263,35 +286,13 @@ pub fn simulate<Msg, F>(
263286{
264287 let mut rng = StdRng :: seed_from_u64 ( config. seed ) ;
265288
266- fn test < Msg : Debug + PartialEq + Clone , F : Fn ( ) -> NodeHandle < Msg > > (
267- number_of_nodes : u8 ,
268- spawn : F ,
269- property : impl Fn ( History < Msg > ) -> Result < ( ) , String > ,
270- ) -> impl Fn ( & [ Reverse < Entry < Msg > > ] ) -> ( History < Msg > , Result < ( ) , String > ) {
271- move |entries| {
272- let node_handles: Vec < _ > = ( 1 ..=number_of_nodes)
273- . map ( |i| ( format ! ( "n{}" , i) , spawn ( ) ) )
274- . collect ( ) ;
275-
276- let mut world = World :: new ( entries. to_vec ( ) , node_handles) ;
277-
278- match world. run_world ( ) {
279- Ok ( history) => (
280- History ( history. to_vec ( ) ) ,
281- property ( History ( history. to_vec ( ) ) ) ,
282- ) ,
283- Err ( ( reason, history) ) => ( History ( history. to_vec ( ) ) , Err ( reason) ) ,
284- }
285- }
286- }
287-
288289 for test_number in 1 ..=config. number_of_tests {
289290 let entries: Vec < Reverse < Entry < Msg > > > = generator ( & mut rng) ;
290291
291- match test ( config. number_of_nodes , & spawn, & property) ( & entries) {
292+ match run_test ( config. number_of_nodes , & spawn, & property) ( & entries) {
292293 ( _history, Err ( reason) ) => {
293294 let ( shrunk_entries, ( shrunk_history, result) , number_of_shrinks) = shrink (
294- test ( config. number_of_nodes , & spawn, & property) ,
295+ run_test ( config. number_of_nodes , & spawn, & property) ,
295296 entries,
296297 |result| result. 1 == Err ( reason. clone ( ) ) ,
297298 ) ;
0 commit comments