fn generate_rnd_conf_change() -> ConfState {
        let conv = |sl: &Vec<u64>| -> Vec<u64> {
            // We want IDs but the incoming slice is zero-indexed, so add one to
            // each.
            let mut out = [0].repeat(sl.len());
            for i in 0..sl.len() {
                out[i] = sl[i] + 1;
            }
            out
        };

        let mut r = rand::thread_rng();
        // NB: never generate the empty ConfState, that one should be unit tested.
        let n_voters = r.gen_range(0, 5) + 1;
        let n_learners = r.gen_range(0, 5);

        // The number of voters that are in the outgoing config but not in the
        // incoming one. (We'll additionally retain a random number of the
        // incoming voters below).
        let n_removed_voters = r.gen_range(0, 3);

        // Voters, learners, and removed voters must not overlap. A "removed voter"
        // is one that we have in the outgoing config but not the incoming one.
        let mut ids =
            (1..=2 * (n_voters + n_learners + n_removed_voters) as u64).collect::<Vec<_>>();
        ids.shuffle(&mut r);
        // println!("ids {:?}, {}", ids, 2 * (n_voters + n_learners + n_removed_voters));
        let mut cs = ConfState::new();
        cs.voters = ids.drain(..n_voters).collect();

        if n_learners > 0 {
            cs.learners = ids.drain(..n_learners).collect::<Vec<_>>();
        }

        // Roll the dice on how many of the incoming voters we decide were also
        // previously voters.
        //
        // NB: this code avoids creating non-nil empty slices (here and below).
        let n_outgoing_retained_voters = r.gen_range(0, n_voters + 1);
        if n_outgoing_retained_voters > 0 || n_removed_voters > 0 {
            cs.voters_outgoing
                .extend_from_slice(&cs.voters[..n_outgoing_retained_voters]);
            cs.voters_outgoing
                .extend_from_slice(&ids[..n_removed_voters]);
        }

        // Only outgoing voters that are not also incoming voters can be in
        // learners_next (they represent demotions).
        if n_removed_voters > 0 {
            let n_learners = r.gen_range(0, n_removed_voters + 1);
            if n_learners > 0 {
                cs.learners_next = ids[..n_learners].to_vec();
            }
        }

        cs.set_auto_leave(cs.voters_outgoing.len() > 0 && r.gen_range(0, 2) == 1);
        cs
    }
// Generate create a random (valid) ConfState for use with quickcheck.
Generate create a random (valid) ConfState for use with quickcheck.
Generate create a random ( valid ) ConfState for use with quickcheck .
fn generate_rnd_conf_change() -> ConfState {
        let conv = |sl: &Vec<u64>| -> Vec<u64> {
            // We want IDs but the incoming slice is zero-indexed, so add one to
            // each.
            let mut out = [0].repeat(sl.len());
            for i in 0..sl.len() {
                out[i] = sl[i] + 1;
            }
            out
        };
        let mut r = rand::thread_rng();
        // NB: never generate the empty ConfState, that one should be unit tested.
        let n_voters = r.gen_range(0, 5) + 1;
        let n_learners = r.gen_range(0, 5);
        // The number of voters that are in the outgoing config but not in the
        // incoming one. (We'll additionally retain a random number of the
        // incoming voters below).
        let n_removed_voters = r.gen_range(0, 3);
        // Voters, learners, and removed voters must not overlap. A "removed voter"
        // is one that we have in the outgoing config but not the incoming one.
        let mut ids =
            (1..=2 * (n_voters + n_learners + n_removed_voters) as u64).collect::<Vec<_>>();
        ids.shuffle(&mut r);
        // println!("ids {:?}, {}", ids, 2 * (n_voters + n_learners + n_removed_voters));
        let mut cs = ConfState::new();
        cs.voters = ids.drain(..n_voters).collect();
        if n_learners > 0 {
            cs.learners = ids.drain(..n_learners).collect::<Vec<_>>();
        }
        // Roll the dice on how many of the incoming voters we decide were also
        // previously voters.
        //
        // NB: this code avoids creating non-nil empty slices (here and below).
        let n_outgoing_retained_voters = r.gen_range(0, n_voters + 1);
        if n_outgoing_retained_voters > 0 || n_removed_voters > 0 {
            cs.voters_outgoing
                .extend_from_slice(&cs.voters[..n_outgoing_retained_voters]);
            cs.voters_outgoing
                .extend_from_slice(&ids[..n_removed_voters]);
        }
        // Only outgoing voters that are not also incoming voters can be in
        // learners_next (they represent demotions).
        if n_removed_voters > 0 {
            let n_learners = r.gen_range(0, n_removed_voters + 1);
            if n_learners > 0 {
                cs.learners_next = ids[..n_learners].to_vec();
            }
        }
        cs.set_auto_leave(cs.voters_outgoing.len() > 0 && r.gen_range(0, 2) == 1);
        cs
    }
fn generate_rnd_conf_change ( ) -> ConfState { let conv = | sl : & Vec < u64 > | -> Vec < u64 > { // We want IDs but the incoming slice is zero-indexed, so add one to // each. let mut out = [ 0 ] . repeat ( sl . len ( ) ) ; for i in 0 .. sl . len ( ) { out [ i ] = sl [ i ] + 1 ; } out } ; let mut r = rand :: thread_rng ( ) ; // NB: never generate the empty ConfState, that one should be unit tested. let n_voters = r . gen_range ( 0 , 5 ) + 1 ; let n_learners = r . gen_range ( 0 , 5 ) ; // The number of voters that are in the outgoing config but not in the // incoming one. (We'll additionally retain a random number of the // incoming voters below). let n_removed_voters = r . gen_range ( 0 , 3 ) ; // Voters, learners, and removed voters must not overlap. A "removed voter" // is one that we have in the outgoing config but not the incoming one. let mut ids = ( 1 ..= 2 * ( n_voters + n_learners + n_removed_voters ) as u64 ) . collect :: < Vec < _ > > ( ) ; ids . shuffle ( & mut r ) ; // println!("ids {:?}, {}", ids, 2 * (n_voters + n_learners + n_removed_voters)); let mut cs = ConfState :: new ( ) ; cs . voters = ids . drain ( .. n_voters ) . collect ( ) ; if n_learners > 0 { cs . learners = ids . drain ( .. n_learners ) . collect :: < Vec < _ > > ( ) ; } // Roll the dice on how many of the incoming voters we decide were also // previously voters. // // NB: this code avoids creating non-nil empty slices (here and below). let n_outgoing_retained_voters = r . gen_range ( 0 , n_voters + 1 ) ; if n_outgoing_retained_voters > 0 || n_removed_voters > 0 { cs . voters_outgoing . extend_from_slice ( & cs . voters [ .. n_outgoing_retained_voters ] ) ; cs . voters_outgoing . extend_from_slice ( & ids [ .. n_removed_voters ] ) ; } // Only outgoing voters that are not also incoming voters can be in // learners_next (they represent demotions). if n_removed_voters > 0 { let n_learners = r . gen_range ( 0 , n_removed_voters + 1 ) ; if n_learners > 0 { cs . learners_next = ids [ .. n_learners ] . to_vec ( ) ; } } cs . set_auto_leave ( cs . voters_outgoing . len ( ) > 0 && r . gen_range ( 0 , 2 ) == 1 ) ; cs }
Generate create a random (valid) ConfState for use with quickcheck.
Generate create a random ( valid ) ConfState for use with quickcheck .