Skip to content
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 19 additions & 5 deletions connect/src/shuffle_vec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -146,8 +146,7 @@ mod test {
);
}

#[test]
fn test_shuffle_with_first() {
fn get_shuffle_vec_without_and_with_first() -> (ShuffleVec<usize>, ShuffleVec<usize>) {
const MAX_RANGE: usize = 200;

let (base_vec, seed) = base(0..MAX_RANGE);
Expand All @@ -165,13 +164,28 @@ mod test {
let mut shuffled_without_first = base_vec.clone();
shuffled_without_first.shuffle_with_seed(seed, |_| false);

(shuffled_without_first, shuffled_with_first)
}

#[test]
fn test_shuffle_with_first() {
let (shuffled_without_first, shuffled_with_first) = loop {
let (vec1, vec2) = get_shuffle_vec_without_and_with_first();
if vec1 != vec2 {
break (vec1, vec2);
}
// vec without and with first ist equal, aka the vec first item is the same value as
Comment thread
photovoltex marked this conversation as resolved.
Outdated
// the randomly determined first values, we just create another set of two shuffled vec
println!("failed to retrieve two different vector")
Comment thread
photovoltex marked this conversation as resolved.
Outdated
};
Comment thread
photovoltex marked this conversation as resolved.

let mut switched_positions = Vec::with_capacity(2);
for (i, without_first_value) in shuffled_without_first.iter().enumerate() {
if without_first_value != &shuffled_with_first[i] {
for (i, shuffled_without_first_value) in shuffled_without_first.iter().enumerate() {
if shuffled_without_first_value != &shuffled_with_first[i] {
switched_positions.push(i);
} else {
assert_eq!(
without_first_value, &shuffled_with_first[i],
shuffled_without_first_value, &shuffled_with_first[i],
"shuffling with the same seed has the same result"
);
}
Expand Down