Skip to content

Commit

Permalink
Add test for infinite loop
Browse files Browse the repository at this point in the history
  • Loading branch information
benjamin-lieser committed Jul 5, 2023
1 parent c5af1f8 commit a4739d8
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions rand_distr/src/binomial.rs
Original file line number Diff line number Diff line change
Expand Up @@ -366,4 +366,15 @@ mod test {
fn binomial_distributions_can_be_compared() {
assert_eq!(Binomial::new(1, 1.0), Binomial::new(1, 1.0));
}

#[test]
fn binomial_avoid_infinite_loop() {
let dist = Binomial::new(16000000, 3.1444753148558566e-10).unwrap();
let mut sum: u64 = 0;
let mut rng = crate::test::rng(742);
for _ in 0..100_000 {
sum = sum.wrapping_add(dist.sample(&mut rng));
}
assert_ne!(sum, 0);
}
}

0 comments on commit a4739d8

Please sign in to comment.