From b0069bfaa516378672c35a8359f411638a4e49fb Mon Sep 17 00:00:00 2001 From: Felix Prillwitz Date: Thu, 25 Dec 2025 18:32:18 +0100 Subject: [PATCH 1/2] chore: fix shuffle vec test --- connect/src/shuffle_vec.rs | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/connect/src/shuffle_vec.rs b/connect/src/shuffle_vec.rs index 595a392ba..3c1ed9027 100644 --- a/connect/src/shuffle_vec.rs +++ b/connect/src/shuffle_vec.rs @@ -146,8 +146,7 @@ mod test { ); } - #[test] - fn test_shuffle_with_first() { + fn get_shuffle_vec_without_and_with_first() -> (ShuffleVec, ShuffleVec) { const MAX_RANGE: usize = 200; let (base_vec, seed) = base(0..MAX_RANGE); @@ -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 + // the randomly determined first values, we just create another set of two shuffled vec + println!("failed to retrieve two different vector") + }; + 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" ); } From 2d2702cfa90c1a85aeb17152efcefe9cfb0b3ca7 Mon Sep 17 00:00:00 2001 From: Felix Prillwitz Date: Thu, 25 Dec 2025 19:35:33 +0100 Subject: [PATCH 2/2] chore: prevent indefinite running, fix typo --- connect/src/shuffle_vec.rs | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/connect/src/shuffle_vec.rs b/connect/src/shuffle_vec.rs index 3c1ed9027..7a4b6f1bf 100644 --- a/connect/src/shuffle_vec.rs +++ b/connect/src/shuffle_vec.rs @@ -169,14 +169,22 @@ mod test { #[test] fn test_shuffle_with_first() { + const MAX_VEC_RECREATION: usize = 20; + + let mut prevent_running_indefinitely = 0; 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 + + // vec without and with first is equal, aka the vec first item is the same value as // the randomly determined first values, we just create another set of two shuffled vec - println!("failed to retrieve two different vector") + assert!( + prevent_running_indefinitely < MAX_VEC_RECREATION, + "failed to retrieve two different vector after {MAX_VEC_RECREATION}" + ); + prevent_running_indefinitely += 1; }; let mut switched_positions = Vec::with_capacity(2);