Skip to content

Commit

Permalink
test(tests): ✅ resolve type inference issue in test_rand_bool by sp…
Browse files Browse the repository at this point in the history
…ecifying integer type
  • Loading branch information
sebastienrousseau committed Aug 26, 2024
1 parent 30fa199 commit 7f1e9e4
Showing 1 changed file with 21 additions and 4 deletions.
25 changes: 21 additions & 4 deletions tests/test_macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -379,10 +379,27 @@ mod tests {
fn test_rand_bool() {
let mut rng = Random::new();
let probability = 0.5; // Example probability
let result = rand_bool!(rng, probability);
// Since probability is 0.5, result should be either true or false
// This assertion is actually more meaningful when checked under different probabilities
assert!(!result);
let mut true_count: i32 = 0;
let mut false_count: i32 = 0;
let iterations = 1000;

for _ in 0..iterations {
let result = rand_bool!(rng, probability);
if result {
true_count += 1;
} else {
false_count += 1;
}
}

// With a probability of 0.5, we expect the number of `true` and `false` results to be roughly equal
// Allow some tolerance for randomness
let tolerance = iterations / 10;
assert!(
(true_count - false_count).abs() <= tolerance,
"The distribution between true and false should be approximately equal, but got true_count: {}, false_count: {}",
true_count, false_count
);
}

#[test]
Expand Down

0 comments on commit 7f1e9e4

Please sign in to comment.