// Ensures that no fixed point are present in the generated vector.
Ensures that no fixed point are present in the generated vector.
Ensures that no fixed point are present in the generated vector .
fn no_fixed_point() {
        let mut rng = thread_rng();
        for _ in 0..10000 {
            let size = rng.gen_range(5,10);
            let derangement = random_derangement(size);
            // Test that all elements are different than their index.
            let not_found = derangement
                .iter()
                .enumerate()
                .all(|(i, &p)| i != p);
            assert!(not_found);
            // Ensures that each index is present in the permutation
            let same_sum = derangement
                .iter()
                .enumerate()
                .fold((0,0), |(ai, ap), (i, &p)| (ai+i, ap+p));
            assert!(same_sum.0 == same_sum.1);
        }
    }
fn no_fixed_point ( ) { let mut rng = thread_rng ( ) ; for _ in 0 .. 10000 { let size = rng . gen_range ( 5 , 10 ) ; let derangement = random_derangement ( size ) ; // Test that all elements are different than their index. let not_found = derangement . iter ( ) . enumerate ( ) . all ( | ( i , & p ) | i != p ) ; assert ! ( not_found ) ; // Ensures that each index is present in the permutation let same_sum = derangement . iter ( ) . enumerate ( ) . fold ( ( 0 , 0 ) , | ( ai , ap ) , ( i , & p ) | ( ai + i , ap + p ) ) ; assert ! ( same_sum 0 same_sum 1 ) ; } }
Ensures that no fixed point are present in the generated vector.
Ensures that no fixed point are present in the generated vector .